gitea- https://git.supernets.org/ |
git clone git://git.acid.vegas/gitea.git |
Log | Files | Refs | Archive |
deploy-gitea (6008B)
1 #!/bin/bash 2 # Gitea Container Deployment - Developed by acidvegas (https://git.acid.vegas) 3 4 set -xev 5 6 # TODO: Automate this process on a timer to do daily backups & remote backups 7 backup_gitea() { 8 GITEA_DB="giteadb" 9 GITEA_DB_USER="gitea" 10 11 NOW=$(date +%Y%m%d) 12 13 incus exec gitea-container -- systemctl stop gitea 14 incus exec gitea-container -- sudo -u git sh -c 'gitea dump -c /etc/gitea/app.ini --file - > /home/git/gitea-${NOW}.zip' 15 incus exec gitea-container -- sudo -u git sh -c 'pg_dump -U $GITEA_DB_USER $GITEA_DB > /home/git/gitea-${NOW}.sql' 16 incus file pull gitea-container/home/git/gitea-${NOW}.zip gitea-${NOW}.zip 17 incus file pull gitea-container/home/git/gitea-${NOW}.sql gitea-${NOW}.sql 18 incus exec gitea-container -- rm /home/git/gitea-${NOW}.zip /home/git/gitea-${NOW}.sql 19 incus exec gitea-container -- systemctl start gitea 20 } 21 22 23 setup_gitea() { 24 [ ! -f gitea.zip ] && echo "Missing gitea.zip" && exit 1 25 [ ! -f gitea.sql ] && echo "Missing gitea.sql" && exit 1 26 27 GITEA_DB="giteadb" 28 GITEA_DB_USER="gitea" 29 PORT_GITEA_SSH=30022 30 31 CONTAINER_IP=$(incus list | grep gitea-container | awk '{print $6}') 32 VERSION=$(curl -s https://api.github.com/repos/go-gitea/gitea/releases/latest | jq -r .tag_name | cut -c2-) 33 34 incus config set gitea-container boot.autostart true 35 incus config device add gitea-container gitea-ssh-port proxy listen=tcp:0.0.0.0:$PORT_GITEA_SSH connect=tcp:$CONTAINER_IP:${PORT_GITEA_SSH} 36 37 incus exec prosody-container -- userdel -r agent 38 39 incus exec gitea-container -- apt-get install git postgresql postgresql-client unzip wget -y 40 incus exec gitea-container -- adduser --system --shell /bin/bash --group --disabled-password --home /home/git git 41 incus exec gitea-container -- wget -O /usr/local/bin/gitea https://github.com/go-gitea/gitea/releases/download/v${VERSION}/gitea-${VERSION}-linux-amd64 42 incus exec gitea-container -- chmod +x /usr/local/bin/gitea 43 incus exec gitea-container -- mkdir -p /etc/gitea /var/lib/gitea/custom/assets /var/lib/gitea/data /var/lib/gitea/log 44 incus exec gitea-container -- chown root:git /etc/gitea 45 incus exec gitea-container -- chmod 750 /etc/gitea 46 incus exec gitea-container -- chmod 640 /etc/gitea/app.ini 47 incus exec gitea-container -- chown -R git:git /var/lib/gitea 48 incus exec gitea-container -- chmod -R 750 /var/lib/gitea 49 incus exec gitea-container -- wget -O /usr/share/bash-completion/completions/gitea https://raw.githubusercontent.com/go-gitea/gitea/main/contrib/autocompletion/bash_autocomplete 50 incus exec gitea-container -- wget -O /etc/systemd/system/gitea.service https://raw.githubusercontent.com/go-gitea/gitea/release/v1.22/contrib/systemd/gitea.service 51 52 incus file push gitea.sql gitea-container/root/gitea.sql 53 incus exec gitea-container -- systemctl enable postgresql 54 incus exec gitea-container -- systemctl start postgresql 55 PASSWORD=$(grep PASSWD /etc/gitea/app.ini | awk '{print $3}') 56 su -c "psql -c \"CREATE ROLE $GITEA_DB_USER WITH LOGIN PASSWORD '${PASSWORD}';\" -c \"CREATE DATABASE $GITEA_DB WITH OWNER $GITEA_DB_USER TEMPLATE template0 ENCODING UTF8 LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8';\"" - postgres 57 printf "\nlocal $GITEA_DB $GITEA_DB_USER scram-sha-256" >> /etc/postgresql/*/main/pg_hba.conf # Verify this will write to all lol... 58 psql -h localhost -U $GIT_DB_USER $GIT_DB < /root/gitea.sql 59 incus exec gitea-container -- rm /root/gitea.sql 60 incus exec gitea-container -- systemctl restart postgresql 61 62 incus file push gitea.zip gitea-container/root/gitea.zip 63 incus exec gitea-container -- mkdir -p /root/restore 64 incus exec gitea-container -- unzip /root/gitea.zip -d /root/restore 65 incus exec gitea-container -- rm /root/gitea.zip 66 mv /root/restore/app.ini /etc/gitea/app.ini 67 mv /root/restore/custom/* /var/lib/gitea/custom/ 68 mv /root/restore/data/* /var/lib/gitea/data/ 69 mv /root/restore/repos/* /var/lib/gitea/data/gitea-repositories/ 70 chown -R git:git /etc/gitea/app.ini /var/lib/gitea 71 incus exec gitea-container -- systemctl enable gitea 72 incus exec gitea-container -- systemctl start gitea 73 } 74 75 # TODO: Unfinished 76 setup_runner() { 77 GITEA_URL="https://git.supernets.org" 78 CONTAINER_IP=$(incus list | grep gitea-runner-container | awk '{print $6}') 79 VERSION=$(curl -s https://gitea.com/api/v1/repos/gitea/act_runner/releases/latest | grep -o '"tag_name":"[^"]*' | cut -d'"' -f4) 80 81 incus config set gitea-container boot.autostart true 82 83 incus exec gitea-container -- wget -O /usr/local/bin/gitea-runner https://gitea.com/gitea/act_runner/releases/download/v${VERSION}/act_runner-${VERSION}-linux-amd64 84 incus exec gitea-container -- chmod +x /usr/local/bin/gitea-runner 85 incus exec gitea-container -- mkdir /etc/gitea-runner 86 incus exec gitea-container -- /usr/local/bin/gitea-runner generate-config > /etc/gitea-runner/config.yaml 87 incus exec gitea-container -- /usr/local/bin/gitea-runner register --no-interactive --instance $GITEA_URL --token <registration_token> --name <runner_name> --labels <runner_labels> 88 89 { 90 echo "[Unit]" 91 echo "Description=Gitea Actions runner" 92 echo "Documentation=https://gitea.com/gitea/act_runner" 93 echo "After=docker.service" 94 95 echo "[Service]" 96 echo "ExecStart=/usr/local/bin/act_runner daemon --config /etc/act_runner/config.yaml" 97 echo "ExecReload=/bin/kill -s HUP \$MAINPID" 98 echo "WorkingDirectory=/var/lib/act_runner" 99 echo "TimeoutSec=0" 100 echo "RestartSec=10" 101 echo "Restart=always" 102 echo "User=act_runner" 103 104 echo "[Install]" 105 echo "WantedBy=multi-user.target" 106 } > gitea-runner.service.tmp 107 108 incus file push gitea-runner.service.tmp gitea-container/etc/systemd/system/gitea-runner.service 109 rm gitea-runner.service.tmp 110 111 incus exec gitea-container -- systemctl enable gitea-runner 112 incus exec gitea-container -- systemctl start gitea-runner 113 }