summaryrefslogtreecommitdiff
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
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.
-rwxr-xr-xezjail-admin57
-rw-r--r--man8/ezjail-admin.814
2 files changed, 70 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 $@
diff --git a/man8/ezjail-admin.8 b/man8/ezjail-admin.8
index 65c44bf..71ec14b 100644
--- a/man8/ezjail-admin.8
+++ b/man8/ezjail-admin.8
@@ -61,6 +61,9 @@
61.Op Fl s Ar sourcetree | sourceosversion 61.Op Fl s Ar sourcetree | sourceosversion
62.Op Fl p 62.Op Fl p
63.Fl b | Fl i | Fl P | Fl u | Fl U 63.Fl b | Fl i | Fl P | Fl u | Fl U
64.Nm
65.Cm baseclean
66.Op Fl y
64.Sh DESCRIPTION 67.Sh DESCRIPTION
65The 68The
66.Nm 69.Nm
@@ -629,6 +632,17 @@ sub command to install the basejail from binary packages.
629.Pp 632.Pp
630If the basejail is managed in its own ZFS filesystem, a snapshot of that 633If the basejail is managed in its own ZFS filesystem, a snapshot of that
631filesystem is taken first. 634filesystem is taken first.
635.Ss Nm Cm baseclean
636Cleans ezjail's basejail from any unneeded files that might still be present
637after an upgrade via
638.Cm ezjail-admin install
639.Fl K
640.Pp
641Defaults in a dry run which
642will not delete anything, but shows all files that would be deleted.
643.Pp
644.Fl y
645Really delete that files.
632.Sh FILES 646.Sh FILES
633.Pa EZJAIL_PREFIX/bin/ezjail-admin 647.Pa EZJAIL_PREFIX/bin/ezjail-admin
634.br 648.br