summaryrefslogtreecommitdiff
path: root/ezjail-admin
diff options
context:
space:
mode:
authorPhilipp Wuensche <cryx-freebsd@h3q.com>2019-08-15 16:07:03 +0200
committerPhilipp Wuensche <cryx-freebsd@h3q.com>2019-08-15 16:07:03 +0200
commitbcf5edaa201b735419f45f817b8c89ff5ce20b69 (patch)
tree2bdb20a9699c4ea7200383cadd183a912a3a2ee8 /ezjail-admin
parentbc503ac02358b514b605f92110a913e36055a50b (diff)
introduce the baseclean subcommand. It uses the new install log to compare to the files present in the basejail and deletes them. By default it does a dry run and deletes nothing, adding the -y parameter will delete files really.
Diffstat (limited to 'ezjail-admin')
-rwxr-xr-xezjail-admin57
1 files changed, 56 insertions, 1 deletions
diff --git a/ezjail-admin b/ezjail-admin
index a6514c1..beffaed 100755
--- a/ezjail-admin
+++ b/ezjail-admin
@@ -41,7 +41,7 @@ ezjail_basesystem="base"
41case `uname -p` in amd64) ezjail_dirlist="${ezjail_dirlist} usr/lib32"; ezjail_basesystem="${ezjail_basesystem} lib32";; esac 41case `uname -p` in amd64) ezjail_dirlist="${ezjail_dirlist} usr/lib32"; ezjail_basesystem="${ezjail_basesystem} lib32";; esac
42 42
43# Synopsis messages 43# Synopsis messages
44ezjail_usage_ezjailadmin="${ezjail_admin} v3.4.2\nUsage: ${ezjail_admin} [archive|config|console|create|delete|freeze|install|list|restore|snapshot|troubleshoot|update] {params}" 44ezjail_usage_ezjailadmin="${ezjail_admin} v3.4.2\nUsage: ${ezjail_admin} [archive|config|console|create|delete|freeze|install|list|restore|snapshot|troubleshoot|update|baseclean] {params}"
45ezjail_usage_install="Usage: ${ezjail_admin} install [-mMpPsSK] [-h host] [-r release]" 45ezjail_usage_install="Usage: ${ezjail_admin} install [-mMpPsSK] [-h host] [-r release]"
46ezjail_usage_create="Usage: ${ezjail_admin} create [-xbi] [-f flavour] [-r jailroot] [-s size] [-c bde|eli|zfs] [-C args] [-a archive] [-z parentzfs] jailname jailip" 46ezjail_usage_create="Usage: ${ezjail_admin} create [-xbi] [-f flavour] [-r jailroot] [-s size] [-c bde|eli|zfs] [-C args] [-a archive] [-z parentzfs] jailname jailip"
47ezjail_usage_delete="Usage: ${ezjail_admin} delete [-wf] jailname" 47ezjail_usage_delete="Usage: ${ezjail_admin} delete [-wf] jailname"
@@ -53,6 +53,7 @@ ezjail_usage_restore="Usage: ${ezjail_admin} restore [-f] [-d archivedir] (archi
53ezjail_usage_freeze="Usage: ${ezjail_admin} freeze jailname newflavour" 53ezjail_usage_freeze="Usage: ${ezjail_admin} freeze jailname newflavour"
54ezjail_usage_troubleshoot="Usage: ${ezjail_admin} troubleshoot [jailname...]" 54ezjail_usage_troubleshoot="Usage: ${ezjail_admin} troubleshoot [jailname...]"
55ezjail_usage_list="Usage: ${ezjail_admin} list" 55ezjail_usage_list="Usage: ${ezjail_admin} list"
56ezjail_usage_baseclean="Usage: ${ezjail_admin} baseclean [-y]"
56 57
57################################ 58################################
58# End of variable initialization 59# End of variable initialization
@@ -1218,6 +1219,60 @@ install)
1218 [ "${ezjail_installports}" ] && ezjail_updateports 1219 [ "${ezjail_installports}" ] && ezjail_updateports
1219 1220
1220 ;; 1221 ;;
1222######################## ezjail-admin BASECLEAN ########################
1223baseclean)
1224 unset ezjail_yeswecan
1225
1226 shift; while getopts y arg; do case ${arg} in
1227 y) ezjail_yeswecan="YES";;
1228 ?) exerr ${ezjail_usage_baseclean};;
1229 esac; done; shift $(( $OPTIND - 1 ))
1230
1231 [ "${ezjail_yeswecan}" != "YES" ] && echo "baseclean dry run, nothing will be deleted. Use -y option to delete files."
1232
1233 [ "${ezjail_use_zfs}" = "YES" ] && ensure_jailzfs
1234 ezjail_makeabsolute ezjail_jailtemp
1235 rm -rf "${ezjail_jailtemp}"
1236
1237 # Create and try to access temp dir
1238 mkdir -p "${ezjail_jailtemp}" || exerr "Error: Could not create temporary base jail directory ${ezjail_jailtemp}."
1239
1240 # create any directories in install log
1241 for line in `cat ${ezjail_jailbase}/.ezjail.installlog | sort`; do
1242 [ ! -d "${ezjail_jailtemp}/${line%/*}" ] && mkdir -p "${ezjail_jailtemp}/${line%/*}"
1243 done
1244
1245 # we ignore any usr/ports and the ezjail install log itself
1246 mkdir -p "${ezjail_jailtemp}/usr/ports"
1247 touch "${ezjail_jailtemp}/.ezjail.installlog"
1248
1249 # touch any files listed in install log
1250 for line in `cat ${ezjail_jailbase}/.ezjail.installlog | sort`; do
1251 [ ! -e "${ezjail_jailtemp}/${line}" ] && touch "${ezjail_jailtemp}/${line}"
1252 done
1253
1254 # User has enabled uglyperlhack in ezjail.conf, make sure symlink doesn't get deleted
1255 [ "${ezjail_uglyperlhack}" = "YES" ] && touch "${ezjail_jailtemp}/usr/bin/perl"
1256
1257 # find all files in base jail that are not listed in the install log and delete them
1258 for _file in `find ${ezjail_jailbase} -type l -or -type f ! -regex ".*usr/ports.*" | sed s:^${ezjail_jailbase}/:: `; do
1259 if [ ! -f "${ezjail_jailtemp}/${_file}" ]; then
1260 [ "${ezjail_yeswecan}" != "YES" ] && echo "File: ${ezjail_jailbase}/${_file} will be deleted"
1261 [ "${ezjail_yeswecan}" = "YES" ] && rm "${ezjail_jailbase}/${_file}" && echo "File: ${ezjail_jailbase}/${_file} deleted"
1262 fi
1263 done
1264
1265 # find all directories in base jail that are not listed in the install log and delete them when empty
1266 for _dir in `find ${ezjail_jailbase} -type d ! -regex ".*usr/ports.*" | sort -r | sed -E s:^${ezjail_jailbase}:: `; do
1267 if [ ! -e "${ezjail_jailtemp}/${_dir}" ]; then
1268 [ "${ezjail_yeswecan}" != "YES" ] && echo "Dir: ${ezjail_jailbase}/${_dir} will be deleted"
1269 [ "${ezjail_yeswecan}" = "YES" ] && rmdir ${ezjail_jailbase}/${_dir} && echo "Dir: ${ezjail_jailbase}/${_dir} deleted"
1270 fi
1271 done
1272
1273 # remove our temporary directory
1274 rm -rf "${ezjail_jailtemp}"
1275 ;;
1221######################## ezjail-admin SHORTCUT ######################## 1276######################## ezjail-admin SHORTCUT ########################
1222*start|*stop|*startcrypto|*stopcrypto) 1277*start|*stop|*startcrypto|*stopcrypto)
1223 start_stop_jail_by_script $@ 1278 start_stop_jail_by_script $@