-
Notifications
You must be signed in to change notification settings - Fork 12
/
install
executable file
·154 lines (150 loc) · 4.76 KB
/
install
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env bash
DOCKER_IMAGE=lukaszlach/satis-server
DOCKER_TAG=${SATIS_SERVER_VERSION:-latest}
[ "$DOCKER_TAG" == "master" ] && DOCKER_TAG=latest
DOCKER_CONTAINER_NAME=satis_server
if ! command -v "docker" > /dev/null 2>&1; then
echo "Error: Docker not found, visit https://docs.docker.com/engine/installation/ or run: 'curl -sS https://get.docker.com/ | bash'"
exit 1
fi
if ! command -v "docker-compose" > /dev/null 2>&1; then
echo -e "Error: docker-compose command not found, visit https://docs.docker.com/compose/install/"
exit 1
fi
set -ex
if [ -f /usr/local/bin/satis-server-stop ]; then
/usr/local/bin/satis-server-stop || true
fi
docker stop "$DOCKER_CONTAINER_NAME" || true
docker rm -f "$DOCKER_CONTAINER_NAME" || true
docker pull "$DOCKER_IMAGE:$DOCKER_TAG"
# configure satis-server
SATIS_SERVER_PORT=8080
BUILD_DIR=/etc/satis
ETC_DIR=/etc/satis-server
VAR_DIR=/var/satis-server
set +x
printf '\033[1;37m'
if nc -w 1 127.0.0.1 "$SATIS_SERVER_PORT" < /dev/null; then
echo "Warning: Port $SATIS_SERVER_PORT is currently opened, make sure it's closed before running satis-server"
fi
if [ ! -f "$BUILD_DIR/satis.json" ]; then
echo "Warning: $BUILD_DIR/satis.json not found, it will be created automatically on first run."
echo " You can always overwrite this file manually and rebuild Satis repository."
fi
if [ ! -f "$ETC_DIR/https/cert.pem" ]; then
echo "Notice: Place cert.pem and key.pem certificates under $ETC_DIR/https directory"
echo " to serve satis-server and Satis API over HTTPs."
fi
printf '\033[0m'
set -ex
rm -rf "$VAR_DIR"
mkdir -p "$ETC_DIR" "$VAR_DIR" "$BUILD_DIR"
set +ex
# docker-compose.yml file
cat > "$ETC_DIR/docker-compose.yml" << EOF
# Satis Server ($DOCKER_IMAGE:$DOCKER_TAG)
# WARNING: Do NOT edit this file, modify your settings in $ETC_DIR/satis-server.conf
version: "2.1"
services:
satis-server:
image: $DOCKER_IMAGE:$DOCKER_TAG
container_name: $DOCKER_CONTAINER_NAME
restart: unless-stopped
ports:
- \${PORT:-8080}:80
#ssl - \${SSL_PORT:-443}:443
volumes:
- $BUILD_DIR/:/etc/satis
- $ETC_DIR/:/etc/satis-server
- $VAR_DIR/:/var/satis-server
environment:
#ssl - "SSL_PORT=\${SSL_PORT}"
- "SATIS_REBUILD_AT=\${REBUILD_AT}"
- "PUSH_SECRET=\${PUSH_SECRET}"
- "API_ALLOW=\${API_ALLOW}"
- "NOTIFY_DEBUG=\${NOTIFY_DEBUG:-0}"
- "NOTIFY_HIPCHAT=\${NOTIFY_HIPCHAT:-0}"
- "HIPCHAT_API=\${HIPCHAT_API}"
- "HIPCHAT_ROOM=\${HIPCHAT_ROOM}"
- "HIPCHAT_TOKEN=\${HIPCHAT_TOKEN}"
- "NOTIFY_SLACK=\${NOTIFY_SLACK:-0}"
- "SLACK_URL=\${SLACK_URL}"
- "SLACK_ROOM=\${SLACK_ROOM}"
EOF
# configuration file
if [ ! -f "$ETC_DIR/satis-server.conf" ]; then
cat > "$ETC_DIR/satis-server.conf" << EOF
## Core settings
PORT=$SATIS_SERVER_PORT
SSL_PORT=443
# crontab rule for automatic full rebuild
REBUILD_AT=1 0 * * *
# set pre-shared key required to call /api/push
PUSH_SECRET=
# set subnet mask allowed to access /api endpoints, by default
# all IPs are allowed; example: 192.168.1.0/24
API_ALLOW=
## Build notifications settings
# set to 1 to include extra information in notifications
NOTIFY_DEBUG=0
## HipChat configuration
# set to 1 to enable HipChat notifications
NOTIFY_HIPCHAT=0
# base URL of your HipChat API, including trailing slash
HIPCHAT_API=https://api.hipchat.com/
# room ID
HIPCHAT_ROOM=
# room notification token
HIPCHAT_TOKEN=
## Slack configuration
# set to 1 to enable Slack notifications
NOTIFY_SLACK=0
# Incoming WebHook URL
SLACK_URL=
# room name
SLACK_ROOM=
EOF
rm -f "$ETC_DIR/.env"
ln -s "$ETC_DIR/satis-server.conf" "$ETC_DIR/.env"
fi
# start/stop scripts
cat > "/usr/local/bin/satis-server-start" << EOF
#!/usr/bin/env sh
set -e
(
if [ -f /etc/satis-server/https/cert.pem ] && [ -f /etc/satis-server/https/key.pem ]; then
TMP_DIR=\$(mktemp -d)
cp -rf $ETC_DIR/* "\$TMP_DIR"
cd "\$TMP_DIR"
sed 's/^#ssl//' $ETC_DIR/docker-compose.yml > docker-compose.yml
else
cd $ETC_DIR
fi
docker-compose -f ./docker-compose.yml up -d
)
echo "satis-server started"
exit 0
EOF
cat > "/usr/local/bin/satis-server-stop" << EOF
#!/usr/bin/env sh
(
docker stop `docker ps | grep $DOCKER_CONTAINER_NAME | cut -d' ' -f1`
docker rm -f $DOCKER_CONTAINER_NAME
) 2>/dev/null
echo "satis-server stopped"
exit 0
EOF
# help
cat > "/usr/local/bin/satis-server-help" << EOF
#!/usr/bin/env sh
docker run --rm -it $DOCKER_IMAGE:$DOCKER_TAG help
EOF
set -ex
chmod +x /usr/local/bin/satis-server-*
/usr/local/bin/satis-server-start
set +x
printf "\033[1;37m\n"
echo "satis-server installed and running, run 'satis-server-help' to view the documentation"
printf "\n\033[0m"
exit 0