-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgogs.sh
More file actions
executable file
·70 lines (59 loc) · 1.76 KB
/
gogs.sh
File metadata and controls
executable file
·70 lines (59 loc) · 1.76 KB
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
#!/bin/bash
#
# gogs Start up the OpenSSH server and Gogs server
#
KEYGEN="/usr/bin/ssh-keygen"
SSHD="/usr/sbin/sshd"
OPTIONS="-D" # -E /var/log/sshd/output.log
CONF="/etc/ssh/sshd_config"
if ! test -d /data/app; then
mkdir -p /var/run/sshd
mkdir -p /data/app/custom /data/app/data /data/app/conf /data/app/log /data/git /data/ssh/config /data/ssh/log
fi
if ! test -d /var/log/sshd; then
# prepare sshd environment
mkdir -p /var/run /var/empty/sshd /var/log/sshd
chmod 755 /var/empty
fi
test -d /data/app/templates || cp -ar ./templates /data/app/
if id -u git >/dev/null 2>&1; then
echo "found git user, skip init process"
else
echo "git user does not exist, booting the container"
adduser -h /data/git -s /bin/sh -D -u 1000 git git
passwd -u git
ln -sf /data/app/custom ./custom
ln -sf /data/app/data ./data
ln -sf /data/app/log ./log
ln -sf /data/app/templates ./templates
ln -sf /data/ssh/config /etc/ssh
ln -sf /data/ssh/log /var/log/sshd
mkdir /data/git/.ssh
touch /data/git/.ssh/authorized_keys
chmod 0700 /data/git/.ssh
chmod -R 0600 /data/git/.ssh/*
chown -R git:git /data/git/.ssh
chown -R git:git /data /tmp .
fi
if [ ! -s $CONF ]; then
echo "/etc/ssh/sshd_config not found, Use default sshd_config"
cp /etc/default/sshd_config $CONF
fi
if [ ! -s /etc/ssh/moduli ]; then
echo "/etc/ssh/moduli not found, Use default moduli"
cp -f /etc/default/moduli /etc/ssh/moduli
fi
# generate server key if not exists
$KEYGEN -A
echo "starting sshd..."
$SSHD $OPTIONS &
sshd_pid="$!"
echo "sshd is running"
sleep 1
echo "starting gogs..."
su git -c "./gogs web" &
echo "gogs is running"
gogs_pid="$!"
trap "echo \"gogs and sshd is stopped\"; kill $sshd_pid $gogs_pid; exit 0" exit INT TERM
wait
exit 1