-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver
executable file
·82 lines (69 loc) · 1.57 KB
/
server
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
# run like
# [key=/path/to/ssh-key] server [staging|production] [args...]
# where args can be...
# - setup path/to/ssh-key
# - deploy [service]
# - revert service
# - everything
set -o errexit
set -o nounset
set -o pipefail
# Environment
if [ $# -ge 0 ]; then
environment="$1"
shift
else
read -p "Environment (production|staging): " environment
fi
if [ $environment = "production" ]; then
host="my.6gu.nz"
elif [ $environment = "staging" ]; then
host="staging.6gu.nz"
else
read -p "Assuming $environment is an ip address."
host="$environment"
fi
# SSH keys
if [ -e "${key-""}" ]; then
key_args=(-i $key)
else
declare -a key_args
fi
# Command
if [ $# -ge 0 ]; then
cmd="$1"
shift
args=( "$@" )
else
read -p "Command: " cmd
if [ ! "$cmd" = "setup" ]; then
read -a "Arguments (may be empty): " args
fi
fi
# Bash
if [ "$cmd" = "bash" ]; then
ssh ${key_args[*]} root@${host}
exit 0
fi
# "Regular" commands
if [ ! "$cmd" = "setup" ]; then
set -o xtrace
ssh ${key_args[*]} root@${host} \
"bash 6gu/machines/run.sh" "$cmd" ${args[*]}
exit 0
fi
# Server setup
read -p "Path to gitea creds: " path_to_creds
path_to_creds=${path_to_creds/#\~/$HOME}
if [ ! -f "$path_to_creds" ]; then
echo "Gitea creds not found."
exit 1
fi
read -p "Enter docker registry username: " docker_username
read -p "Enter docker registry password: " docker_password
set -o xtrace
scp ${key_args[*]} "$path_to_creds" root@${host}:/root/.ssh/git-key
ssh ${key_args[*]} root@${host} \
"bash -s '$docker_username' '$docker_password'" \
< machines/setup.sh