diff options
author | merakor <cem@ckyln.com> | 2020-10-05 07:30:59 +0000 |
---|---|---|
committer | merakor <cem@ckyln.com> | 2020-10-05 07:30:59 +0000 |
commit | 3a3944019a79fd171be19bfe8a56c3dca2fcfd76 (patch) | |
tree | 49556d0de58aad9141d3aac1dc59937296129907 /contrib/cpt-reset | |
parent | 41cfe97b8d1716dd2ae8c9b275e790da83eaca82 (diff) | |
download | cpt-3a3944019a79fd171be19bfe8a56c3dca2fcfd76.tar.gz |
cpt-reset: rewrite to make use of the /etc/cpt-base file.
FossilOrigin-Name: 8e53e32d1f2cfa115743a912260d6d8e60b547b29a99ae3684306400ff367f43
Diffstat (limited to 'contrib/cpt-reset')
-rwxr-xr-x | contrib/cpt-reset | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/contrib/cpt-reset b/contrib/cpt-reset index 1226fe6..4dfe52d 100755 --- a/contrib/cpt-reset +++ b/contrib/cpt-reset @@ -1,24 +1,39 @@ -#!/bin/sh -ef +#!/bin/sh -e # Remove all packages except for the base # # Disable word-splittng warnings as they're safe here. # shellcheck disable=SC2046 -set -- +[ "$1" ] && { + printf 'usage: %s\n\nRemove all packages not defined in the base.\n' \ + "${0##*/}" + exit 0 +} -while read -r pkg _; do - case $pkg in - baselayout|binutils|bison|busybox|bzip2|curl|flex|gcc|rsync|\ - gzip|cpt|libressl|linux-headers|m4|make|musl|pkgconf|xz|zlib) ;; +sys_db="$CPT_ROOT/var/db/cpt/installed" + +# Get base packages and their dependencies. +[ -f "$CPT_ROOT/etc/cpt-base" ] && while read -r basepkg _; do + case "$basepkg" in \#*) continue; esac + base=" $basepkg $base" + [ -f "$sys_db/$basepkg/depends" ] || continue + while read -r dep make; do + [ "$make" ] && continue + base=" $dep $base" + done < "$sys_db/$basepkg/depends" +done < "$CPT_ROOT/etc/cpt-base" + +set -- +cd "$sys_db" - *) set -- "$@" "$pkg" ;; - esac -done <<EOF -$(cpt-list) -EOF +for pkg in *; do + case "$base" in *" $pkg "*) continue; esac + set -- "$pkg" "$@" +done [ "$1" ] && { printf 'WARNING: This will remove \033[1m%s\033[m package(s).\n' "$#" + printf 'Base packages can be redefined in %s\n' "$CPT_ROOT/etc/cpt-base" printf 'Continue? [Enter/Ctrl+C]\n' read -r _ && CPT_FORCE=1 cpt-remove "$@" } |