1
0
mirror of https://codeberg.org/kiss-community/kiss synced 2024-12-24 16:10:05 -07:00

kiss: clean up + do less in instalalation by using test -a/-o

This commit is contained in:
Dylan Araps 2020-09-25 18:07:41 +03:00
parent 5d00c43720
commit 506db9b469
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E

53
kiss
View File

@ -939,27 +939,29 @@ pkg_install_files() {
[ST]*): "$((b+=1))" ;; [ST]*): "$((b+=1))" ;;
esac esac
[ "$((${c%?} % 3))" = 0 ] && oct=$oct$o o=0 case $((${c%?} % 3)) in
0) oct=$oct$o o=0
esac
done done
# Copy files and create directories (preserving permissions). # Copy files and create directories (preserving permissions).
case $line in case $line in
/etc/?*[!/]) /etc/?*[!/])
[ -d "$KISS_ROOT/$line" ] || test "$1" "$KISS_ROOT/$line" || test -d "$KISS_ROOT/$line" -o "$1" "$KISS_ROOT/$line" ||
pkg_etc_file "$2" "${line#/}" pkg_etc_file "$2" "${line#/}"
;; ;;
*/) */)
[ -d "$KISS_ROOT/$line" ] || test -d "$KISS_ROOT/$line" ||
mkdir -m "$oct" "$KISS_ROOT/$line" mkdir -m "$oct" "$KISS_ROOT/$line"
;; ;;
*) *)
[ -d "$KISS_ROOT/$line" ] || test "$1" "$KISS_ROOT/$line" || { test -d "$KISS_ROOT/$line" -o "$1" "$KISS_ROOT/$line" || {
cp -fP "$2/$line" "$KISS_ROOT/$line" cp -fP "$2/$line" "$KISS_ROOT/$line"
# This prepends $b which represents sticky bit, setuid, # This prepends $b which represents sticky bit,
# setfgid, etc. # setuid, setfgid, etc.
[ -h "$KISS_ROOT/$line" ] || [ -h "$KISS_ROOT/$line" ] ||
chmod "$b$oct" "$KISS_ROOT/$line" chmod "$b$oct" "$KISS_ROOT/$line"
} }
@ -974,28 +976,30 @@ pkg_remove_files() {
# installation and package removal. Combining the removals in these two # installation and package removal. Combining the removals in these two
# functions allows us to stop duplicating code. # functions allows us to stop duplicating code.
while read -r file; do while read -r file; do
case $file in /etc/?*[!/]) case $file in
sum_sys=$(sh256 "$KISS_ROOT/$file") /etc/?*[!/])
sum_old=$(grep -F "$sum_sys" "$tmp_dir/.etcsums") sum_sys=$(sh256 "$KISS_ROOT/$file") ||:
sum_old=$(grep -F "$sum_sys" "$tmp_dir/.etcsums") ||:
[ "$sum_sys" = "$sum_old" ] || { [ "$sum_sys" = "$sum_old" ] || {
printf 'Skipping %s (modified)\n' "$file" printf 'Skipping %s (modified)\n' "$file"
continue continue
} }
esac 2>/dev/null ||: ;;
esac 2>/dev/null
file=$KISS_ROOT/$file file=$KISS_ROOT/$file
# Remove files. # Remove files.
if [ -f "$file" ] && [ ! -h "$file" ]; then if test -f "$file" -a ! -h "$file"; then
rm -f "$file" rm -f "$file"
# Remove file symlinks. # Remove file symlinks.
elif [ -h "$file" ] && [ ! -d "$file" ]; then elif test -h "$file" -a ! -d "$file"; then
rm -f "$file" rm -f "$file"
# Remove directories if empty. # Remove directories if empty.
elif [ -d "$file" ] && [ ! -h "$file" ]; then elif test -d "$file" -a ! -h "$file"; then
rmdir "$file" 2>/dev/null ||: rmdir "$file" 2>/dev/null ||:
fi fi
done ||: done ||:
@ -1032,8 +1036,7 @@ pkg_etc_file() {
;; ;;
esac esac
cp -fPp "$1/$2" "$KISS_ROOT/${2}${new}" cp -fP "$1/$2" "$KISS_ROOT/${2}${new}"
chown root:root "$KISS_ROOT/${2}${new}" 2>/dev/null
} }
pkg_remove() { pkg_remove() {
@ -1335,13 +1338,13 @@ args() {
[ -z "$1" ] || [ -w "$KISS_ROOT/" ] || [ "$uid" = 0 ] || { [ -z "$1" ] || [ -w "$KISS_ROOT/" ] || [ "$uid" = 0 ] || {
as_root HOME="$HOME" \ as_root HOME="$HOME" \
XDG_CACHE_HOME="$XDG_CACHE_HOME" \ XDG_CACHE_HOME="$XDG_CACHE_HOME" \
KISS_PATH="$KISS_PATH" \
KISS_FORCE="$KISS_FORCE" \
KISS_ROOT="$KISS_ROOT" \
KISS_CHOICE="$KISS_CHOICE" \ KISS_CHOICE="$KISS_CHOICE" \
KISS_COLOR="$KISS_COLOR" \ KISS_COLOR="$KISS_COLOR" \
KISS_TMPDIR="$KISS_TMPDIR" \ KISS_FORCE="$KISS_FORCE" \
KISS_PATH="$KISS_PATH" \
KISS_PID="$KISS_PID" \ KISS_PID="$KISS_PID" \
KISS_ROOT="$KISS_ROOT" \
KISS_TMPDIR="$KISS_TMPDIR" \
"$0" "$action" "$@" "$0" "$action" "$@"
return return
@ -1365,8 +1368,8 @@ args() {
# Go over each alternative and format the file # Go over each alternative and format the file
# name for listing. (pkg_name>usr>bin>ls) # name for listing. (pkg_name>usr>bin>ls)
for _pkg in "$sys_db/../choices"/*; do for pkg in "$sys_db/../choices"/*; do
printf '%s\n' "${_pkg##*/}" printf '%s\n' "${pkg##*/}"
done | done |
sed 's|>| /|; s|>|/|g; /\*/d' sed 's|>| /|; s|>|/|g; /\*/d'