-
Notifications
You must be signed in to change notification settings - Fork 1
/
gitea.sh
executable file
·54 lines (49 loc) · 2.15 KB
/
gitea.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
#!/bin/sh
set -xefu
ADD_PPA="${ADD_PPA:-0}"
# From https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c
GITEA_VERSION="${GITEA_VERSION:-$(wget -qO- "https://api.github.com/repos/go-gitea/gitea/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")' | awk -F '^v' '{print $NF}')}"
dest="${dest:-$1}"
# First build rootfs tree
# Probably there is nothing Ubuntu-specific,
# so it can be used with any systemd-based GNU/Linux distro
# (except adduser and apt commands)
. ./rootfs-ubuntu.sh
systemd-nspawn -q -D "$dest" \
apt update
systemd-nspawn -q -D "$dest" \
apt install -y openssh-server git
# Then setup this rootfs tree
wget https://github.com/go-gitea/gitea/releases/download/v${GITEA_VERSION}/gitea-${GITEA_VERSION}-linux-${ARCH} -O "${dest}/usr/local/bin/gitea"
chmod 755 "${dest}/usr/local/bin/gitea"
wget https://github.com/go-gitea/gitea/raw/master/contrib/systemd/gitea.service -O "${dest}/etc/systemd/system/gitea.service"
mkdir -p "${dest}/etc/gitea/"
wget https://github.com/go-gitea/gitea/raw/master/custom/conf/app.ini.sample -O "${dest}/etc/gitea/app.ini"
sed -i -e 's,DB_TYPE = mysql,DB_TYPE = sqlite3,g' "${dest}/etc/gitea/app.ini"
# Increase session interval from 1 day to 7 days
sed -i -e 's,TIME = 86400,TIME = 604800,g' "${dest}/etc/gitea/app.ini"
sed -i -e 's,PATH = data/gitea.db,PATH = /var/lib/gitea/gitea.db,g' "${dest}/etc/gitea/app.ini"
sed -i -e 's,HTTP_PORT = 3000,HTTP_PORT = 3250,g' "${dest}/etc/gitea/app.ini"
sed -i -e 's,^#Port 22,Port 3251,g' "$dest/etc/ssh/sshd_config"
# https://golb.hplar.ch/2018/06/self-hosted-git-server.html
systemd-nspawn -q -D "$dest" \
adduser --system \
--shell /bin/bash \
--gecos 'Gitea user' \
--group --disabled-password \
--home /home/git \
git
mkdir -p "${dest}/var/lib/gitea/"
systemd-nspawn -q -D "$dest" \
chown -R git:git /var/lib/gitea/
systemd-nspawn -q -D "$dest" \
chmod 700 -R /var/lib/gitea/
systemd-nspawn -q -D "$dest" \
chown git:root /etc/gitea/app.ini
# generate ssh host keys
systemd-nspawn -q -D "$dest" \
dpkg-reconfigure openssh-server
systemd-nspawn -q -D "$dest" \
systemctl enable gitea.service ssh.service
echo ""
echo "Gitea container (rootfs) has been created in $dest"