From 50d0366e4794a358d15cea82b8b5d52fcac7b707 Mon Sep 17 00:00:00 2001 From: Arinerron Date: Sat, 30 Mar 2019 16:21:12 -0700 Subject: [PATCH] Run onionr as user instead of system always --- install/install_arch.sh | 12 ++++++------ install/onionr | 19 +++++++++++++------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/install/install_arch.sh b/install/install_arch.sh index 046ea4fe..c2263916 100755 --- a/install/install_arch.sh +++ b/install/install_arch.sh @@ -5,7 +5,7 @@ OUTPUT_DIR='/usr/share/onionr' DATA_DIR='/etc/onionr' LOG_DIR='/var/log/onionr' -BRANCH='master' +BRANCH='easy-releases' # setup error handlers @@ -43,12 +43,10 @@ echo -e "\033[0;32mInstalling pip dependencies...\033[0m" pip3 install --no-input -r "$OUTPUT_DIR/requirements.txt" --require-hashes > /dev/null -# create nologin onionr user if not exists - -id -u onionr &>/dev/null || useradd -r -s /sbin/nologin onionr +# set permissions on Onionr directory chmod 755 "$OUTPUT_DIR" -chown -R onionr:onionr "$OUTPUT_DIR" +chown -R root:root "$OUTPUT_DIR" # create directories @@ -56,7 +54,7 @@ mkdir -p "$OUTPUT_DIR/onionr/data" "$LOG_DIR" mv "$OUTPUT_DIR/onionr/data" "$DATA_DIR" chmod -R 750 "$DATA_DIR" "$LOG_DIR" -chown -R onionr:onionr "$DATA_DIR" "$LOG_DIR" +chown -R root:root "$DATA_DIR" "$LOG_DIR" # create executable @@ -67,6 +65,8 @@ chown root:root "$EXECUTABLE" # create systemd service +echo -e "\033[0;32mCreating systemd unit...\033[0m" + SERVICE='/etc/systemd/system/onionr.service' cp "$OUTPUT_DIR/install/onionr.service" "$SERVICE" diff --git a/install/onionr b/install/onionr index 73430851..eb141f0b 100755 --- a/install/onionr +++ b/install/onionr @@ -5,11 +5,18 @@ set -e [ "root" != "$USER" ] && exec sudo $0 "$@" export OUTPUT_DIR=${OUTPUT_DIR:=/usr/share/onionr} -export ONIONR_HOME=${ONIONR_HOME:=/etc/onionr} -export LOG_DIR=${LOG_DIR:=/var/log/onionr} + +if [ -n "$HOME" ]; then + export XDG_DATA_HOME=${XDG_DATA_HOME:=$HOME/.local/share/onionr} + + export ONIONR_HOME=${ONIONR_HOME:=$XDG_DATA_HOME} + export LOG_DIR=${LOG_DIR:=$XDG_DATA_HOME/logs} +else + export ONIONR_HOME=${ONIONR_HOME:=/etc/onionr} + export LOG_DIR=${LOG_DIR:=/var/log/onionr} +fi + +mkdir -p "$ONIONR_HOME" "$LOG_DIR" cd "$OUTPUT_DIR/onionr" - -command="python3.7 onionr.py '$@'" -echo $command -exec su onionr -s /bin/sh -c "$command" +exec python3.7 onionr.py "$@"