3 then echo "Please run as root"
7 then echo "Need arg $1 to specify which chroot to delete"
12 chroot_path
=/opt
/chroot
/$chrootdir
13 chroot_config_path
=/etc
/schroot
/$chrootdir
15 schroot_main_config
=/etc
/schroot
/schroot.conf
16 backup_schroot_config
="/tmp/schroot.conf.orig"
19 echo "----------------------------------------------"
20 echo "WARNING! If the script finds directories:"
22 echo "$chroot_config_path"
23 echo "It will DELETE them!"
25 echo "The [$chrootdir] chroot profile from:"
26 echo "$schroot_main_config"
27 echo "will also be removed."
29 echo "The script will wait for $sleep_time second/s before starting"
30 echo "Press Ctrl-C now to cancel."
31 echo "----------------------------------------------"
34 if [ -e $chroot_path ]; then
35 echo "Deleting $chroot_path"
38 echo "$chroot_path not found, skipping."
41 if [ -e $chroot_config_path ]; then
42 echo "Deleting $chroot_config_path configuration directory"
43 rm -rf $chroot_config_path
45 echo "$chroot_config_path not found, skipping."
48 # Find where the entry for given scroot profile is in the file.
49 # Return line number corresponding to the start.
50 lin_num_start
=$
(grep -n "\[$chrootdir\]" $schroot_main_config | cut
-d : -f 1)
52 if [ -z $lin_num_start ]; then
53 echo "The [$chrootdir] chroot profile in $schroot_main_config does not exist"
54 echo "Skipping $schroot_main_config"
56 echo "The [$chrootdir] chroot profile found in $schroot_main_config"
57 # Can't think of a good way to make this clean
58 # Assumption: the profile always ends with "profile=$chrootdir",
59 # which will indicate the last line to delete of the old chroot
60 lin_num_end
=$
(grep -n "profile=$chrootdir" $schroot_main_config | cut
-d : -f 1)
61 lines
="$lin_num_start,$lin_num_end"
62 echo "Line range to delete from $schroot_main_config: $lines"
64 echo "Creating backup copy of $schroot_main_config in $backup_schroot_config"
65 cp $schroot_main_config $backup_schroot_config
66 echo "Script will re-write $schroot_main_config by"
67 echo "removing the old $chrootdir profile"
68 sed -e "$lines"'d' $backup_schroot_config > $schroot_main_config