2019-03-28 18:01:23 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
EXECUTABLE='/usr/bin/onionr'
|
|
|
|
OUTPUT_DIR='/usr/share/onionr'
|
|
|
|
DATA_DIR='/etc/onionr'
|
|
|
|
LOG_DIR='/var/log/onionr'
|
|
|
|
|
|
|
|
BRANCH='master'
|
|
|
|
|
2019-03-28 18:08:36 +00:00
|
|
|
# setup error handlers
|
|
|
|
|
2019-03-28 18:01:23 +00:00
|
|
|
set -e
|
|
|
|
|
2019-03-28 18:08:36 +00:00
|
|
|
trap "echo -e '\033[31mOnionr installation failed.\033[0m' >&2; exit 1337" ERR INT TERM
|
|
|
|
|
2019-03-28 18:01:23 +00:00
|
|
|
# require root permissions
|
|
|
|
|
|
|
|
if ! [ $(id -u) = 0 ]; then
|
|
|
|
echo 'This script must be run as root.' >&2
|
|
|
|
exit 1337
|
|
|
|
fi
|
|
|
|
|
|
|
|
# install basic dependencies
|
|
|
|
|
2019-03-29 06:18:25 +00:00
|
|
|
echo -e "\033[0;32mInstalling pacman dependencies...\033[0m"
|
2019-03-29 05:36:41 +00:00
|
|
|
|
2019-03-29 06:18:25 +00:00
|
|
|
! ((pacman --needed --noconfirm -S git curl python python-pip tor > /dev/null) 2>&1 | grep -v warning 1>&2) | grep .
|
2019-03-28 18:01:23 +00:00
|
|
|
|
|
|
|
# get the repository
|
|
|
|
|
2019-03-29 05:36:41 +00:00
|
|
|
echo -e "\033[0;32mCloning Onionr repository...\033[0m"
|
|
|
|
|
2019-03-28 18:01:23 +00:00
|
|
|
rm -rf "$OUTPUT_DIR" "$DATA_DIR" "$LOG_DIR"
|
|
|
|
|
2019-03-29 05:36:41 +00:00
|
|
|
git clone --quiet https://gitlab.com/beardog/onionr "$OUTPUT_DIR" > /dev/null
|
2019-03-28 18:01:23 +00:00
|
|
|
|
|
|
|
cd "$OUTPUT_DIR"
|
2019-03-29 05:36:41 +00:00
|
|
|
git checkout -q "$BRANCH" > /dev/null
|
2019-03-28 18:01:23 +00:00
|
|
|
|
|
|
|
# install python dependencies
|
|
|
|
|
2019-03-29 05:36:41 +00:00
|
|
|
echo -e "\033[0;32mInstalling pip dependencies...\033[0m"
|
|
|
|
|
|
|
|
pip3 install --no-input -r "$OUTPUT_DIR/requirements.txt" --require-hashes > /dev/null
|
2019-03-28 18:01:23 +00:00
|
|
|
|
|
|
|
# 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 daemon-reload
|
2019-03-28 18:10:11 +00:00
|
|
|
systemctl enable onionr
|
2019-03-28 18:01:23 +00:00
|
|
|
systemctl start onionr
|
|
|
|
|
|
|
|
# pretty header thing
|
|
|
|
|
|
|
|
"$EXECUTABLE" --header 'Onionr successfully installed.'
|
|
|
|
|
|
|
|
# and we're good!
|
|
|
|
|
2019-03-28 18:08:36 +00:00
|
|
|
trap - ERR
|
|
|
|
|
2019-03-28 18:01:23 +00:00
|
|
|
exit 0
|