Archive for category Scripts

Migrating Cpanel to Virtualmin

Posted by on Monday, 11 May, 2009

For those who do not know what either are, CPanel and Virtualmin are very similar to Plesk. They are a way of managing all your virtual hosting needs if you have a server. You log into a web interface, add a domain and it automagicly reconfigures your server to accept email DNS and websites for it. You can then add email addresses easily and let users manage their own stuff. They make life very easy for those less knowledgeable about Linux and servers in general. Virtualmin is often migrated to as you can download the GPL version entirely free, and it works great. Alternatively you can pay and get a slightly better more featured version.

A nice tip from Jamie of Virtualmin for migration here.

As for migration, once you have the backups from cPanel you can more easily mass-migrate them into Virtualmin from the command line.
You could use a script like :

for file /cpanel/*.gz; do
virtualmin migrate-domain –type cpanel –source $file –pass foo
done

This will migrate all backups in the /cpanel , and give them the password ‘foo’ in Virtualmin. Sadly there is no way to extract the original password from a cPanel backup 🙁


Website migration from debian.co.nz

Posted by on Tuesday, 7 April, 2009

I’ve been wanting to move the old debian.co.nz onto a more generic name since its more than just debian. Its about Linux.

Ive also made the move for the first time into using somebody elses software for the site rather than my own home rolled stuff, as i really just dont have the time anymore.

Greets go out to those who helped with migrating posts (you can see who they are by who posted em!).

As for more news. The debian and ubnutu repository is going, and the server is now moved offshore. Orcon refused to respond when asked for more bandwidth and 128k international wasnt enough to maintain it. Also gone is the FTP with ISO images, for the same reason.

I have no hard feelings however, I now host on a rimuhosting VPS which has excellent resources, and saves me the hassle of having to deal with hardware and upgrades (PS, I work as a sysadmin at Rimu – and its the most awesome place to work.)

My goal now is to turn the website into more of a community hub for NZ Linux people both new and old, and geeks in general. I welcome you all to post news, gadgets, your own projects, or even how you managed to install Linux on the toaster.

When you post, just post as a Draft, ill review and approve. If I notice anyone who seems particularly into it, i will happily make you an admin who can approve or help manage the website.


Sorting MP3s

Posted by on Tuesday, 7 April, 2009

#!/bin/bash
#
# My mp3s are always heniously unsorted and blowed if im gonna sit there spending hours sorting them
# Call me lazy or something but this definatly helps (even though i spent a couple days writing this and working out bugs)
#
# WARNING – THIS PROGRAM RELIES ON ID3 TAGS!
#
# There are a couple programs to get the ID3 tags sorted out available
# easytag, juk, rhythembox etc (those are all gui ones)
#
# Make sure mp3info is installed ( http://ibiblio.org/mp3info/ )
# just ./runthis and hey presto (make sure you edit where your mp3s are of course first)
#debug
#set -x

#The Dir where all your mp3s are
DIR=”/other/mp3s”

#The final destination dir for the mp3s – No trailing / needed
DESTINATION=”/other/mp3s”

#This is the thing that seperates fields (some people prefer _ some prefer a space however SPACES BREAK THINGS! use ‘1’ if you want spaces)
SPACER=”_”

#try not too edit to much below this

if [ -e moving.log ];then
rm -rf moving.log
fi

if [ ${SPACER} = “1” ];then
SPACER=”[:space:]”
fi

if [ $1 ];then

find ${DIR} -type f -name \*.[mM][Pp]3 | while read i
do

FINALDEST=”${DESTINATION}”
ARTIST=`mp3info -p %a “$i” | tr [:punct:][:blank:] ${SPACER} `
ALBUM=`mp3info -p %l “$i” | tr [:punct:][:blank:] ${SPACER} `
GENRE=`mp3info -p %g “$i” | tr [:punct:][:blank:] ${SPACER}`
SONGNAME=`mp3info -p %t “$i” | tr [:punct:][:blank:] ${SPACER}`
TRACKNUM=`mp3info -p %n “$i”`
FILENAME=`mp3info -p %f “$i” | tr [:punct:][:blank:][mM][Pp]3 ${SPACER} `

# sort the artists
function artistpath {
if [ ! “${ARTIST}” ];then
FINALDEST=”${FINALDEST}/Unknown/”
else
FINALDEST=”${FINALDEST}/${ARTIST}/”
fi
}
function albumpath {
#sort the albums
if [ ! “${ALBUM}” ];then
FINALDEST=”${FINALDEST}/Unknown/”
else
FINALDEST=”${FINALDEST}/${ALBUM}/”
fi
}
if [ $1 == “1” ];then
artistpath
albumpath
elif [ $1 == “2” ];then
albumpath
artistpath
elif [ $1 == “3” ];then
artistpath
elif [ $1 == “4” ];then
albumpath
fi

FINALDEST=`echo ${FINALDEST} | sed s/${SPACER}${SPACER}*/${SPACER}/g`
echo mkdir -p “${FINALDEST}”
echo mkdir -p “${FINALDEST}”>>moving.log
mkdir -p “${FINALDEST}”

unset NEWNAME

if [ “$2″ ];then

NEWNAME=`echo $2 | sed s/TRACKNUM/$TRACKNUM/g | sed s/ALBUM/$ALBUM/g | sed s/ARTIST/$ARTIST/g | sed s/SONGNAME/$SONGNAME/g`
else
NEWNAME=”${TRACKNUM}-${ALBUM}-${ARTIST}-${SONGNAME}”
fi

if [ “${TRACKNUM}” == “” ] && [ “${ALBUM}” == “” ] && [ “${ARTIST}” == “” ] && [ “${SONGNME}” == “” ];then
echo “Songname is non existant (no id3 tag?) – resorting to ${FILENAME} $i”
echo “Songname is non existant (no id3 tag?) – resorting to ${FILENAME} $i”>>moving.log
NEWNAME=”${FILENAME}”
fi
NEWNAME=`echo ${NEWNAME} | sed s/–*/-/g | sed s/^-// | sed s/^${SPACER}// `
FINALDEST=”${FINALDEST}${NEWNAME}.mp3″
FIXDEST=`echo ${FINALDEST} | sed s/${SPACER}${SPACER}*/${SPACER}/g `
echo moving $i to ${FIXDEST}
echo moving $i to ${FIXDEST} >>moving.log
mv -u “$i” “${FIXDEST}”
FINALDEST=”${DESTINATION}”
unset FIXDEST
done

# cleaning up empty dirs
#add this
#for i in `find ./ -type d ` ; do if [ “`find $i -type f`” ];then echo checking $i ; else echo $i is empty;rm -r “$i” ; fi ; done

for EMPTYDIR in ${DESTINATION}/*
do
if [ -d “${EMPTYDIR}” ];then
if [ “`find ${EMPTYDIR} -type f`” ];then
echo Checking ${EMPTYDIR} for cleanup
else
echo ${EMPTYDIR} is empty and being removed
echo ${EMPTYDIR} is empty and being removed >>moving.log
rm -r “${EMPTYDIR}”
#find “${EMPTYDIR}”
fi
else
echo ${EMPTYDIR} is a file

fi
done

# main else

else
echo “Useage: $0 {1|2|3|4} [PATTERN] ”
echo “1 sort by artist then album”
echo “2 sort by album then artist ”
echo “3 sort by artist only”
echo “4 sort by album only”
echo
echo “[PATTERN] – defaults to TRACKNUM-ARTIST-ALBUM-SONGNAME”
echo “ARTIST – Artist”
echo “ALBUM – Album Name”
echo “TRACKNUM – TrackNumber”
echo “SONGNAME – Songname”
fi

# Yes i realize some of the code is horiffic but it did the job at the time ;]
# Liz