diff --git a/install/install_arch.sh b/install/install_arch.sh new file mode 100644 index 00000000..5cc80d40 --- /dev/null +++ b/install/install_arch.sh @@ -0,0 +1,77 @@ +#!/bin/bash + +EXECUTABLE='/usr/bin/onionr' +OUTPUT_DIR='/usr/share/onionr' +DATA_DIR='/etc/onionr' +LOG_DIR='/var/log/onionr' + +BRANCH='master' + +set -e + +# require root permissions + +if ! [ $(id -u) = 0 ]; then + echo 'This script must be run as root.' >&2 + exit 1337 +fi + +# install basic dependencies + +pacman --needed --noconfirm -S git curl python python-pip tor + +# get the repository + +rm -rf "$OUTPUT_DIR" "$DATA_DIR" "$LOG_DIR" + +git clone https://gitlab.com/beardog/onionr "$OUTPUT_DIR" + +cd "$OUTPUT_DIR" +git checkout "$BRANCH" + +# install python dependencies + +pip3 install --no-input -r "$OUTPUT_DIR/requirements.txt" --require-hashes + +# create nologin onionr user if not exists + +id -u onionr &>/dev/null || useradd -r -s /sbin/nologin onionr + +chmod 755 "$OUTPUT_DIR" +chown -R onionr:onionr "$OUTPUT_DIR" + +# create directories + +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" + +# create executable + +cp "$OUTPUT_DIR/install/onionr" "$EXECUTABLE" + +chmod 755 "$EXECUTABLE" +chown root:root "$EXECUTABLE" + +# create systemd service + +SERVICE='/etc/systemd/system/onionr.service' + +cp "$OUTPUT_DIR/install/onionr.service" "$SERVICE" + +chmod 644 "$SERVICE" +chown root:root "$SERVICE" + +systemctl enable onionr +systemctl daemon-reload +systemctl start onionr + +# pretty header thing + +"$EXECUTABLE" --header 'Onionr successfully installed.' + +# and we're good! + +exit 0 diff --git a/install/onionr b/install/onionr new file mode 100755 index 00000000..81c071fa --- /dev/null +++ b/install/onionr @@ -0,0 +1,12 @@ +#!/bin/sh + +set -e + +[ "root" != "$USER" ] && exec sudo $0 "$@" + +export OUTPUT_DIR=${OUTPUT_DIR:=/usr/share/onionr} +export DATA_DIR=${DATA_DIR:=/etc/onionr} +export LOG_DIR=${LOG_DIR:=/var/log/onionr} + +cd "$OUTPUT_DIR" +exec su onionr -s /bin/sh -c "./onionr.sh ""$@""" diff --git a/install/onionr.service b/install/onionr.service new file mode 100644 index 00000000..0f2a42b6 --- /dev/null +++ b/install/onionr.service @@ -0,0 +1,15 @@ +[Unit] +Description=Onionr Daemon +Requires=network.target tor.service +After=network.target tor.service + +[Service] +Environment="DATA_DIR=/usr/share/onionr" +Environment="LOG_DIR=/var/log/onionr/" +ExecStart=/usr/bin/onionr --start +ExecStop=/usr/bin/onionr --stop +Type=simple +Restart=always + +[Install] +WantedBy=tor.service