diff --git a/Makefile b/Makefile index 98147ace..93b3b076 100644 --- a/Makefile +++ b/Makefile @@ -4,8 +4,6 @@ DESTDIR ?= "/" DAEMON_BINARY := swhkd SERVER_BINARY := swhks BUILDFLAGS := --release -POLKIT_DIR := /usr/share/polkit-1/actions -POLKIT_POLICY_FILE := com.github.swhkd.pkexec.policy TARGET_DIR := /usr/bin MAN1_DIR := /usr/share/man/man1 MAN5_DIR := /usr/share/man/man5 @@ -15,9 +13,6 @@ all: build build: @cargo build $(BUILDFLAGS) - @./scripts/build-polkit-policy.sh \ - --policy-path=$(POLKIT_POLICY_FILE) \ - --swhkd-path=$(TARGET_DIR)/$(DAEMON_BINARY) install: @find ./docs -type f -iname "*.1.gz" \ @@ -25,9 +20,10 @@ install: @find ./docs -type f -iname "*.5.gz" \ -exec install -Dm 644 {} -t $(DESTDIR)/$(MAN5_DIR) \; @install -Dm 755 ./target/release/$(DAEMON_BINARY) -t $(DESTDIR)/$(TARGET_DIR) + @sudo chown root:root $(DESTDIR)/$(TARGET_DIR)/$(DAEMON_BINARY) + @sudo chmod u+s $(DESTDIR)/$(TARGET_DIR)/$(DAEMON_BINARY) @install -Dm 755 ./target/release/$(SERVER_BINARY) -t $(DESTDIR)/$(TARGET_DIR) - @install -Dm 644 -o root ./$(POLKIT_POLICY_FILE) -t $(DESTDIR)/$(POLKIT_DIR) -# Ideally, we would have a default config file instead of an empty one + # Ideally, we would have a default config file instead of an empty one @if [ ! -f $(DESTDIR)/etc/$(DAEMON_BINARY)/$(DAEMON_BINARY)rc ]; then \ touch ./$(DAEMON_BINARY)rc; \ install -Dm 644 ./$(DAEMON_BINARY)rc -t $(DESTDIR)/etc/$(DAEMON_BINARY); \ @@ -38,7 +34,6 @@ uninstall: @$(RM) -f /usr/share/man/**/swhks.* @$(RM) $(TARGET_DIR)/$(SERVER_BINARY) @$(RM) $(TARGET_DIR)/$(DAEMON_BINARY) - @$(RM) $(POLKIT_DIR)/$(POLKIT_POLICY_FILE) check: @cargo fmt @@ -57,7 +52,6 @@ clean: @cargo clean @$(RM) -f ./docs/*.gz @$(RM) -f $(DAEMON_BINARY)rc - @$(RM) -f $(POLKIT_POLICY_FILE) setup: @rustup install stable diff --git a/scripts/build-polkit-policy.sh b/scripts/build-polkit-policy.sh deleted file mode 100755 index 628ba903..00000000 --- a/scripts/build-polkit-policy.sh +++ /dev/null @@ -1,89 +0,0 @@ -#!/bin/sh - -############### -# Defaults -############### - -readonly DEFAULT_SWHKD_PATH="/usr/bin/swhkd" -readonly DEFAULT_POLICY_PATH="com.github.swhkd.pkexec.policy" -readonly DEFAULT_MESSAGE="Authentication is required to run Simple Wayland Hotkey Daemon" -readonly DEFAULT_ACTION_ID="com.github.swhkd.pkexec" - -############### -# Init -############### - -print_help() { - printf "Usage: build-polkit-policy [OPTIONS]\n\n" - printf "Generates a polkit policy file for swhkd.\n\n" - printf "Optional Arguments:\n" - printf " --policy-path= Path to save the policy file to.\n" - printf " If set to '-', this tool will output to stdout instead.\n" - printf " Defaults to '%s'.\n" "${DEFAULT_POLICY_PATH}" - printf " --swhkd-path= Path to the swhkd binary when installed.\n" - printf " Defaults to '%s'.\n" "${DEFAULT_SWHKD_PATH}" - printf " --action-id= Polkit action id to use.\n" - printf " Defaults to '%s'.\n" "${DEFAULT_ACTION_ID}" - printf " --message= Custom authentication message.\n" - printf " Defaults to '%s'\n" "${DEFAULT_MESSAGE}" - printf " -h|--help Show this help.\n" -} - -while [ -n "$1" ]; do - case "$1" in - --policy-path=*) - POLICY_PATH=${1#*=} - shift - ;; - --swhkd-path=*) - SWHKD_PATH=${1#*=} - shift - ;; - --action-id=*) - ACTION_ID=${1#*=} - shift - ;; - --message=*) - MESSAGE=${1#*=} - shift - ;; - -h|--help) - print_help - exit 0 - ;; - *) - printf "Unknown option '%s'. Aborting.\n" "$1" - exit 1 - ;; - esac -done - -print_policy() { -cat << EOF - - - - - ${MESSAGE} - - no - no - yes - - ${SWHKD_PATH} - - -EOF -} - -# No local variables in POSIX sh, so just set these globally -POLICY_PATH="${POLICY_PATH:-${DEFAULT_POLICY_PATH}}" -SWHKD_PATH="${SWHKD_PATH:-${DEFAULT_SWHKD_PATH}}" -ACTION_ID="${ACTION_ID:-${DEFAULT_ACTION_ID}}" -MESSAGE="${MESSAGE:-${DEFAULT_MESSAGE}}" - -if [ "${POLICY_PATH}" = "-" ]; then - print_policy -else - print_policy > "${POLICY_PATH}" -fi