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

chore: add support for updating sudoers file #2212

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
30 changes: 30 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,20 @@
# ARG2: Directory in which to store the yabai man-page; must be an absolutepath.
# Fallback: /usr/local/man/man1
#
# ARG3: Whether to update the sudoers file; must be "true" or "false".
# Fallback: "false"
#
# ARG4: Path to the sudoers file; must be an absolute path.
# Fallback: /private/etc/sudoers.d/yabai
#
# Author: Åsmund Vikane
# Date: 2024-02-13
#

BIN_DIR="$1"
MAN_DIR="$2"
UPDATE_SUDOERS="$3"
SUDOERS_FILE="$4"

if [ -z "$BIN_DIR" ]; then
BIN_DIR="/usr/local/bin"
Expand Down Expand Up @@ -55,6 +63,10 @@ if [ ! -w "$MAN_DIR" ]; then
exit 1
fi

if [ -z "$SUDOERS_FILE" ]; then
SUDOERS_FILE="/private/etc/sudoers.d/yabai"
fi

AUTHOR="koekeishiya"
NAME="yabai"
VERSION="7.1.0"
Expand All @@ -74,6 +86,24 @@ if [ "$FILE_HASH" = "$EXPECTED_HASH" ]; then
rm ${MAN_DIR}/${NAME}.1
cp -v ./archive/bin/${NAME} ${BIN_DIR}/${NAME}
cp -v ./archive/doc/${NAME}.1 ${MAN_DIR}/${NAME}.1

if [ "$UPDATE_SUDOERS" = "true" ]; then
TMP_SUDOERS_FILE="./tmp_sudoers"
SUDOERS_ROW="$(whoami) ALL=(root) NOPASSWD: sha256:$(shasum -a 256 ${BIN_DIR}/yabai | cut -d " " -f 1) ${BIN_DIR}/yabai --load-sa"

echo "$SUDOERS_ROW" > $TMP_SUDOERS_FILE

if visudo -c -f $TMP_SUDOERS_FILE; then
echo "Sudoers file syntax is OK. Updating sudoers file.."
# Please note that this will prompt for the user's password unless they have passwordless sudo set up.
sudo cp $TMP_SUDOERS_FILE $SUDOERS_FILE
else
echo "Sudoers file syntax is not OK. Not updating sudoers file."
fi

rm $TMP_SUDOERS_FILE
fi

echo "Finished copying files.."
echo ""
echo "If you want yabai to be managed by launchd (start automatically upon login):"
Expand Down