chmod +x switcheroo
[vsys-scripts.git] / exec / switcheroo
1 #!/bin/sh
2
3 RDIR="/vservers/$1/rootfs"
4
5 if [ ! -d $RDIR ];
6 then
7   # User does not have his own distro, check if he has a default custom distro set
8   VREF_FILE="/etc/planetlab/vsys-attributes/$1/vsys_vref"
9   if [ -e $VREF_FILE ];
10   then
11       VREF=`cat $VREF_FILE`
12       VREF_DIR="/vservers/.vref/$VREF"
13       if [ -d $VREF_DIR ];
14       then
15           echo "Copying in reference image $VREF..."
16           mkdir -p $RDIR
17           cp -aRp $VREF_DIR/* $RDIR
18       else
19           echo "Reference directory $VREF not found."
20           exit
21       fi
22   else
23       echo "Please set up a custom distribution in /rootfs or set a vsys_vref tag for your slice"
24       exit
25   fi
26 fi
27
28 echo "Restarting your slice. Please reconnect and login in a few minutes."
29 vserver $1 stop
30 mv /vservers/$1 /vservers/_$1
31 mv /vservers/_$1/rootfs /vservers/$1
32 vserver $1 start