From a70018062e6369921a593faf78e8bbd0cf8fd608 Mon Sep 17 00:00:00 2001 From: emmett1 Date: Fri, 12 Aug 2022 00:49:59 +0800 Subject: [PATCH 1/2] added scratch world option --- scratch | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/scratch b/scratch index 28603e4..efe42c0 100755 --- a/scratch +++ b/scratch @@ -552,6 +552,7 @@ scratch_install() { break } done_pkg="$done_pkg $ii" + world_add $ii cd - >/dev/null fi done @@ -599,6 +600,9 @@ scratch_install() { count=$(( count - 1 )) break } + if [ $(echo $IPKG | tr ' ' '\n' | grep -x $int) ]; then + world_add $int + fi run_postinstallsh done_pkg="$done_pkg $int" cd - >/dev/null @@ -654,10 +658,12 @@ scratch_remove() { count=$(( count + 1 )) pre_triggers $pkg settermtitle "[ $count/$pkgcount ] Removing $pkg..." + echo "remove: $pkg-$(get_iver $pkg)-$(get_irelease $pkg)..." pkgdel $pkg $OPTS || { error=1 break } + world_del $pkg done settermtitle "Triggering remove hook..." post_triggers @@ -1361,6 +1367,46 @@ scratch_files() { fi } +world_add() { + grep -qx $1 "$WORLD_FILE" && return + scratch_isinstalled $1 || { + echo "'$1' not installed" + return 1 + } + echo "$1" >> "$WORLD_FILE" + echo "world: '$1' added to world" + sort "$WORLD_FILE" -o "$WORLD_FILE" # sort world + sed '/^$/d' -i "$WORLD_FILE" # delete empty lines +} + +world_del() { + grep -qx $1 "$WORLD_FILE" || return + sed "/^$1$/d" -i "$WORLD_FILE" + echo "world: '$1' deleted from world" + sed '/^$/d' -i "$WORLD_FILE" # delete empty lines +} + +scratch_world() { + if [ "$1" ]; then + needroot + touch "$WORLD_FILE" + while [ "$1" ]; do + if [ ! $(grep -x $1 "$WORLD_FILE") ] ; then + world_add $1 + else + world_del $1 + fi + shift + done + else + [ -s "$WORLD_FILE" ] && { + cat "$WORLD_FILE" + } || { + echo "world is empty" + } + fi +} + scratch_help() { cat << EOF Usage: @@ -1417,6 +1463,7 @@ Options: missingdep print missing dependencies orphan print orphan installed ports foreign print foreign ports + world [ports] print/add/remove world list printconfig print scratchpkg configs help print this help msg @@ -1481,6 +1528,7 @@ REPO_FILE="${REPO_FILE:-/etc/scratchpkg.repo}" ALIAS_FILE="${ALIAS_FILE:-/etc/scratchpkg.alias}" MASK_FILE="${MASK_FILE:-/etc/scratchpkg.mask}" CONFIG_FILE="${CONFIG_FILE:-/etc/scratchpkg.conf}" +WORLD_FILE="$(dirname $PKGDB_DIR)/world" # default value from pkgbuild SOURCE_DIR="/var/cache/scratchpkg/sources" From 1161d001b8c36fa929bb1c0c02dfcd49701fd708 Mon Sep 17 00:00:00 2001 From: emmett1 Date: Sat, 13 Aug 2022 21:57:48 +0800 Subject: [PATCH 2/2] fix scratch_orphan to use world --- scratch | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/scratch b/scratch index efe42c0..533ebb1 100755 --- a/scratch +++ b/scratch @@ -1292,15 +1292,15 @@ scratch_missingdep() { } scratch_orphan() { - tmpallpkg="/tmp/.pkgquery_allpkg.$$" - tmpalldep="/tmp/.pkgquery_alldep.$$" - for pkg in $(allinstalled); do - echo $pkg >> $tmpallpkg - dep="$dep $(get_depends $pkg)" + tmpdeplistworld="/tmp/.deplistworld.$$" + tmpallinstalled="/tmp/.allinstalled.$$" + for i in $(cat $WORLD_FILE); do + deplist $i done - echo $dep | tr ' ' '\n' | sort | uniq > "$tmpalldep" - grep -xvF -f "$tmpalldep" "$tmpallpkg" - rm "$tmpalldep" "$tmpallpkg" + echo $DEP | tr ' ' '\n' > $tmpdeplistworld + allinstalled > $tmpallinstalled + grep -xvF -f $tmpdeplistworld $tmpallinstalled + rm $tmpallinstalled $tmpdeplistworld } scratch_path() {