kiss: Run as root where needed

This commit is contained in:
Dylan Araps 2020-01-27 10:54:39 +02:00
parent 7eb80497f6
commit 7ab295a76b
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E
1 changed files with 12 additions and 12 deletions

24
kiss
View File

@ -61,10 +61,10 @@ root_cache() {
# Validate the password now with a simple 'true' command
# as we don't yet need to elevate permissions.
root_run true
dosu true
}
root_run() {
dosu() {
# Run a command as root using the cached password. The 'su'
# command allows you to input a password via stdin. To hide
# the prompt, the command's output is sent to '/dev/tty'
@ -719,9 +719,9 @@ pkg_remove() {
[ "${file##/etc/*}" ] || continue
if [ -d "$KISS_ROOT/$file" ]; then
rmdir "$KISS_ROOT/$file" 2>/dev/null || continue
dosu rmdir "$KISS_ROOT/$file" 2>/dev/null || continue
else
rm -f "$KISS_ROOT/$file"
dosu rm -f "$KISS_ROOT/$file"
fi
done < "$sys_db/$1/manifest"
@ -797,7 +797,7 @@ pkg_install() {
# This is repeated multiple times. Better to make it a function.
pkg_rsync() {
rsync --chown=root:root --chmod=Du-s,Dg-s,Do-s \
dosu rsync --chown=root:root --chmod=Du-s,Dg-s,Do-s \
-WhHKa --no-compress "$1" --exclude /etc \
"$tar_dir/$pkg_name/" "$KISS_ROOT/"
}
@ -808,7 +808,7 @@ pkg_install() {
# If '/etc/' exists in the package, install it but don't overwrite.
[ -d "$tar_dir/$pkg_name/etc" ] &&
rsync --chown=root:root -WhHKa --no-compress --ignore-existing \
dosu rsync --chown=root:root -WhHKa --no-compress --ignore-existing \
"$tar_dir/$pkg_name/etc" "$KISS_ROOT/"
# Remove any leftover files if this is an upgrade.
@ -826,18 +826,18 @@ pkg_install() {
# Remove files.
if [ -f "$file" ] && [ ! -L "$file" ]; then
rm -f "$file"
dosu rm -f "$file"
# Remove file symlinks.
elif [ -L "$file" ] && [ ! -d "$file" ]; then
unlink "$file" ||:
dosu unlink "$file" ||:
# Skip directory symlinks.
elif [ -L "$file" ] && [ -d "$file" ]; then :
# Remove directories if empty.
elif [ -d "$file" ]; then
rmdir "$file" 2>/dev/null ||:
dosu rmdir "$file" 2>/dev/null ||:
fi
done ||:
}
@ -853,7 +853,7 @@ pkg_install() {
if [ -x "$sys_db/$pkg_name/post-install" ]; then
log "$pkg_name" "Running post-install script"
"$sys_db/$pkg_name/post-install" ||:
dosu "$sys_db/$pkg_name/post-install" ||:
fi
log "$pkg_name" "Installed successfully"
@ -907,8 +907,8 @@ pkg_updates() {
git fetch
git merge
else
root_run git fetch
root_run git merge
dosu git fetch
dosu git merge
fi
}
done