Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use doas instead of sudo if it's installed (fixed) #364

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions common/profile-sync-daemon.in
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
PSDCONFDIR="$XDG_CONFIG_HOME/psd"
PSDCONF="$PSDCONFDIR/psd.conf"
SHAREDIR="/usr/share/psd"
SUDO="sudo"
DOASDIR="/usr/bin/doas"

if [[ ! -d "$SHAREDIR" ]]; then
echo -e " ${RED}ERROR:${NRM}${BLD} Missing ${BLU}$SHAREDIR${NRM}${BLD} - reinstall the package to use profile-sync-daemon.${NRM}"
Expand Down Expand Up @@ -257,7 +259,16 @@ config_check() {
# user must have sudo rights to call /usr/bin/mount
# and /usr/bin/umount to use overlay mode

if ! sudo -kn psd-overlay-helper &>/dev/null; then
# use doas in place of sudo if present
if [[ -d "$DOASDIR" ]]; then
SUDO="doas"
tmp_sudo = "doas"
else
tmp_sudo = "sudo -kn"
fi

# verify user has sudo rights
if ! $tmp_sudo psd-overlay-helper &>/dev/null; then
FAILCODE=1
fi

Expand Down Expand Up @@ -527,7 +538,7 @@ do_sync_for() {
# initial sync
REPORT="sync"
if [[ $OLFS -eq 1 ]]; then
if ! sudo psd-overlay-helper -v "$OLFSVER" -l "$BACKUP" -u "$UPPER" -w "$WORK" -d "$TMP" mountup; then
if ! $SUDO psd-overlay-helper -v "$OLFSVER" -l "$BACKUP" -u "$UPPER" -w "$WORK" -d "$TMP" mountup; then
echo -e "Error in trying to mount $TMP - this should not happen!"
exit 1
fi
Expand Down Expand Up @@ -627,7 +638,7 @@ do_unsync() {
[[ -d "$BACKUP" ]] && mv --no-target-directory "$BACKUP" "$DIR"
if [[ $OLFS -eq 1 ]] && mountpoint -q "$TMP"; then
rsync -aX --delete-after --inplace --no-whole-file --exclude .flagged "$BACK_OVFS/" "$DIR/"
sudo psd-overlay-helper -d "$TMP" -w "$WORK" mountdown && rm -rf "$TMP" "$UPPER"
$SUDO psd-overlay-helper -d "$TMP" -w "$WORK" mountdown && rm -rf "$TMP" "$UPPER"
fi
[[ -d "$TMP" ]] && rm -rf "$TMP"
echo -e "${BLD}$browser unsync successful${NRM}"
Expand Down
4 changes: 2 additions & 2 deletions common/psd-overlay-helper
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ case "$1" in
mountup)
# write access to upper/workdir is required or do not overlay lowerdirs
user=$(stat -c %U "$TMP")
if ! sudo -u "$user" test -w "$BACKUP"; then
if ! runuser -u "$user" -- test -w "$BACKUP"; then
echo "User $user has no write permissions for $BACKUP. Aborting..." >&2
exit 1
fi

user=$(stat -c %U "$UPPER")
if ! sudo -u "$user" test -w "$BACKUP"; then
if ! runuser -u "$user" -- test -w "$BACKUP"; then
echo "User $user has no write permissions for $BACKUP. Aborting..." >&2
exit 1
fi
Expand Down