-
Notifications
You must be signed in to change notification settings - Fork 0
/
remote.sh
executable file
·65 lines (55 loc) · 2.22 KB
/
remote.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bash
# includes
DIR="$(dirname $(readlink -f $0))"
. $DIR/bin/common.sh
# Kill existing taskWait if requested
if [ "$1" = "--kill-taskwaiter" ]; then
kill $(cat $TOR_CLI_HOME/taskwait.pid)
rm "$TOR_CLI_HOME/taskwait.pid"
exit 0
fi
# Check if packages are installed
# TODO: MOVE TO THE INSTALLER
if !([ -f $GDRIVE ] && dpkg-query -W pigz deluged deluge-console gnupg &>/dev/null); then
echo -e "${BROWN}Missing packages detected! They will now be installed. Script might request elevation${NC}"
$DIR/bin/install_prereqs.sh remote || exit 1
fi
# Change user if requested
if [ "$1" = "--change-user" ]; then
change_user $2
fi
# Check drive for folders
check_drive
# Create and put public key for server to drive
echo -e "${BROWN}Checking server key...${NC}"
if ! gpg --list-secret-keys "Alfred Pennyworth" &>/dev/null; then
echo -e "${BROWN}Server key doesn't exist. Creating...${NC}"
name="Alfred Pennyworth"
email="[email protected]"
pass="theButtler#1"
eval "cat > .buttler <<EOF
$(<$DIR/gpg_gen_template.txt)
EOF"
gpg --batch --gen-key .buttler
shred -ufn 5 .buttler
update_drive=true
fi
# Export buttler's public key if not exported yet
gpg --export [email protected] > $KEY_DIR/alfred.pennyworth.pub
# Upload buttler's key if not uploaded yet
BUTTLER_KEY=$(safe_list -q "\"'$KEYS_FOLDER' in parents and name = 'alfred.pennyworth.pub'\"" --no-header --name-width 0 | cut -d" " -f1 -)
if [ "$BUTTLER_KEY" = "" ]; then
echo -e "${BROWN}Uploading server's public key to drive...${NC}"
BUTTLER_KEY=$(safe_upload "$KEY_DIR/alfred.pennyworth.pub" $KEYS_FOLDER)
elif [ "$update_drive" = true ]; then # TODO: SEND REVOCATION OF KEY TO DRIVE
echo -e "${BROWN}Updating server's public key in drive...${NC}"
safe_update $BUTTLER_KEY $KEY_DIR/alfred.pennyworth.pub &> /dev/null
fi
# Wait task file from drive
if [ -f "$TOR_CLI_HOME/taskwait.pid" ]; then
echo "Already waiting for tasks on the background!. Execute $0 --kill-taskwaiter if you want to kill background process."
else
nohup $BIN_DIR/taskWait.sh > "$TOR_CLI_HOME/taskwait.out" 2>&1 &
echo $! > "$TOR_CLI_HOME/taskwait.pid"
fi
echo -e "${GREEN}Configuration done. Waiting for tasks...${NC}"