Created
July 28, 2016 22:15
-
-
Save libcrack/c80ee167cd5f1f4d5af50c1f818f6124 to your computer and use it in GitHub Desktop.
FreeNAS: rename jail helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# [email protected] | |
# vie jul 29 00:09:06 CEST 2016 | |
if [ $# != 2 ]; then | |
printf "Usage: $0 oldjailname newjailname\n" | |
exit 1 | |
fi | |
if [ ! -d $jailroot/$oldjailname ]; then | |
printf "\e[31mERROR:\e[0m Cannot access $jailroot/$oldjailname\n" | |
exit 2 | |
fi | |
if [ ! -f $freenasdb ]; then | |
printf "\e[31mERROR:\e[0m Cannot access sqlitedb $freenasdb\n" | |
exit 3 | |
fi | |
oldjailname="$1" | |
newjailname="$2" | |
poolname=freenas | |
jailroot=/mnt/$poolname/jails | |
freenasdb=/data/freenas-v1.db | |
zfs rename $poolname/jails/$oldjailname $poolname/jails/$newjailname && \ | |
mv /mnt/$poolname/jails/.$oldjailname.meta /mnt/$poolname/jails/.$newjailname.meta && \ | |
sed -i '' -e "s/$oldjailname/$newjailname/g" $jailroot/.$newjailname.meta/host && \ | |
sed -i '' -e "s/$oldjailname/$newjailname/g" $jailroot/$newjailname/etc/hosts && \ | |
sed -i '' -e "s/$oldjailname/$newjailname/g" $jailroot/$newjailname/etc/rc.conf && \ | |
echo "update plugins_plugins set plugin_jail='$newjailname' where plugin_jail='$oldjailname';" \ | |
| sqlite3 $freenasdb \ | |
&& printf "\e[32m$newjailname\e[0m\n" \ | |
|| printf "\e[31mERROR: $oldjailname\e[0m\n" | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment