From 8691210b76b2096a35e176f9589f1fbdc73d93df Mon Sep 17 00:00:00 2001 From: emmett1 Date: Tue, 4 May 2021 00:42:28 +0800 Subject: [PATCH] updated --- pkgadd | 12 ++++++-- scratch | 85 +++++++++++++++++++++++++++++++-------------------------- 2 files changed, 57 insertions(+), 40 deletions(-) diff --git a/pkgadd b/pkgadd index 1c9246f..51b0c37 100755 --- a/pkgadd +++ b/pkgadd @@ -133,6 +133,7 @@ parse_opts $(extract_opts "$@") SCRATCHPKG_DIR="var/lib/scratchpkg" PKGDB_DIR="$SCRATCHPKG_DIR/db" +PKGDBPERMS_DIR="$PKGDB_DIR.perms" LOCK_FILE="$SCRATCHPKG_DIR/spkg.lock" ROOT_DIR="${ROOT_DIR%/}" # remove trailing slash @@ -216,7 +217,7 @@ TMP_PKGINSTALL="$ROOT_DIR/$SCRATCHPKG_DIR/.tmp_pkginstall" TMP_CONFLICT="$ROOT_DIR/$SCRATCHPKG_DIR/.tmp_conflict" # check integrity of package and save list file/dirs to install in the meantime -tar -tf $PKGNAME > $TMP_PKGADD 2>/dev/null || { +tar -tvf $PKGNAME > $TMP_PKGADD 2>/dev/null || { msgerr "Package '$1' is corrupted!" ret 1 } @@ -230,7 +231,7 @@ echo "$opr: $name-$version-$release..." # check for file conflict if [ ! "$IGNORE_CONFLICT" ]; then - grep -v '/$' "$TMP_PKGADD" | while read -r line; do + grep -v '/$' "$TMP_PKGADD" | awk '{print $6}' | while read -r line; do if [ "$line" = "${line%.*}.spkgnew" ]; then line=${line%.*} fi @@ -284,6 +285,13 @@ fi # register package into database echo "$version $release" > "$ROOT_DIR/$PKGDB_DIR/$name" cat "$TMP_PKGINSTALL" >> "$ROOT_DIR/$PKGDB_DIR/$name" +mkdir -p "$ROOT_DIR/$PKGDBPERMS_DIR" +grep '/$' $TMP_PKGADD | while read -r perms own junk1 junk2 junk3 dir; do + if [ "$perms" != drwxr-xr-x ] || [ "$own" != root/root ]; then + echo "$perms $own $dir" >> "$ROOT_DIR/$PKGDBPERMS_DIR/$name" + [ -s "$ROOT_DIR/$PKGDBPERMS_DIR/$name" ] || rm "$ROOT_DIR/$PKGDBPERMS_DIR/$name" + fi +done # running ldconfig if [ -x "$ROOT_DIR"/sbin/ldconfig ]; then diff --git a/scratch b/scratch index 8234c80..14377ba 100755 --- a/scratch +++ b/scratch @@ -227,6 +227,48 @@ scratch_sync() { portsync } +cvperms() { + # converts symbolic to numeric permissions + # required an input (symbolic, eg: drwxr-xr-x) + s=0; n=0; count=0 + for i in $(echo "$1" | sed -e 's/\(.\)/\1\n/g'); do + count=$((count+1)) + case $i in + d) ;; + r) n=$((n+4));; + w) n=$((n+2));; + x) n=$((n+1));; + s) [ $count = 4 ] && s=$((s+4)) || s=$((s+2)); n=$((n+1));; + t) s=$((s+1));n=$((n+1));; + S) s=$((s+2));; + T) s=$((s+1));; + esac + [ "$count" = 4 ] && { + user=$n; n=0 + } + [ "$count" = 7 ] && { + group=$n; n=0 + } + [ "$count" = 10 ] && { + other=$n; n=0 + } + done + echo "$s$user$group$other" +} + +fixperms() { + needroot "Fix permissions" + for i in $PKGDBPERMS_DIR/*; do + [ -s $i ] || continue + while read -r perms own dir; do + chmod $(cvperms $perms) /$dir + echo $own | while IFS=/ read -r o g; do + chown $o:$g /$dir + done + done < $i + done +} + scratch_trigger() { needroot "Run trigger" if [ -z "$*" ]; then @@ -239,27 +281,7 @@ scratch_trigger() { post_triggers } -post_triggers() { - if [ "$trig_12" = 1 ]; then - echo "trigger: Running mkdirs..." - for mkd in $PKGDB_DIR/*/.pkgmkdirs; do - [ -s $mkd ] || continue - grep -Ev '^(#|$)' $mkd | while read -r dir mode uid gid junk; do - if [ -e "$dir" ]; then - if [ "$uid" != '-' ]; then - getent passwd $uid >/dev/null && chown "$uid" "$dir" - fi - if [ "$gid" != '-' ]; then - getent group $gid >/dev/null && chgrp "$gid" "$dir" - fi - if [ "$mode" != '-' ]; then - chmod "$mode" "$dir" - fi - fi - done - done - fi - +post_triggers() { if [ "$trig_11" = 1 ] && [ $(command -v fc-cache) ]; then echo "trigger: Updating fontconfig cache..." fc-cache -s @@ -327,6 +349,9 @@ post_triggers() { echo "trigger: Updating the MIME type database..." update-mime-database /usr/share/mime fi + + echo "trigger: Fix files ownership and permissions..." + fixperms } pre_triggers() { @@ -439,16 +464,6 @@ pre_triggers() { fi done fi - - # makedirs - if [ "$trig_12" != "1" ]; then - for pkg in $@; do - if [ -s "$PKGDB_DIR/$pkg/.pkgmkdirs" ]; then - trig_12=1 - break - fi - done - fi } scratch_build() { @@ -899,7 +914,6 @@ scratch_outdate() { fi iversion=$(get_iver $pkg) irelease=$(get_irelease $pkg) - [ -f "$PKGDB_DIR/$pkg/.lock" ] && ITSLOCK="[masked]" if [ -f "$MASK_FILE" ] && [ $(grep -Ev '^(#|$| )' $MASK_FILE | grep $pkg) ]; then ITSLOCK="[masked]" fi @@ -1270,12 +1284,6 @@ scratch_missingdep() { done } -scratch_locked() { - for pkg in $(allinstalled); do - [ -f "$PKGDB_DIR/$pkg/.lock" ] && echo "$pkg" - done -} - scratch_orphan() { tmpallpkg="/tmp/.pkgquery_allpkg.$$" tmpalldep="/tmp/.pkgquery_alldep.$$" @@ -1430,6 +1438,7 @@ done BUILD_SCRIPT="spkgbuild" PKGDB_DIR="$(pkgadd --print-dbdir)" +PKGDBPERMS_DIR=${PKGDB_DIR}.perms REPO_FILE="${REPO_FILE:-/etc/scratchpkg.repo}" ALIAS_FILE="${ALIAS_FILE:-/etc/scratchpkg.alias}" MASK_FILE="${MASK_FILE:-/etc/scratchpkg.mask}"