#!/bin/sh # variables shell_arguments=$1 giteadownloader_default="https://dl.gitea.io/gitea/1.16/gitea-1.16-linux-amd64" myIP="$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)" pwd="$(pwd)" dbuser="giteauser" dbpassword=$(date +%s | sha256sum | base64 | head -c 32) dbtable="giteadb" if [[ "$shell_arguments" == "--github-ci-test" ]]; then run_ci_tests=1 else run_ci_tests=0 fi echo "" echo "" echo " Gitea installer & updater" echo "-------------------------------------------------------------------------" echo "" sleep 3s if [[ run_ci_tests == 1 ]]; then giteadownloader="${giteadownloader_default}" else echo "Define your downloadpath. Otherwise I use: ${giteadownloader_default}" read -p "-> " giteadownloader if [[ -z ${giteadownloader} ]]; then giteadownloader="${giteadownloader_default}" fi echo "You choose: ${giteadownloader}" fi echo "" echo "" echo "//-->> Update" apt-get update -q >> /dev/null 2>&1 apt-get upgrade -q -y >> /dev/null 2>&1 echo "//-->> Install packages" apt-get install git mariadb-server mariadb-client nano -q -y >> /dev/null 2>&1 echo "//-->> Create user: git" adduser --system --shell /bin/bash --gecos 'Git Version Control' --group --disabled-password --home /home/git git >> /dev/null 2>&1 cd /home/git/ echo "//-->> Download Gitea" wget -q $giteadownloader -O gitea >> /dev/null 2>&1 chmod +x gitea echo "//-->> Create important folder" mkdir -p /var/lib/gitea/custom mkdir -p /var/lib/gitea/data mkdir -p /var/lib/gitea/data/lfs mkdir -p /var/lib/gitea/log chown -R git:git /var/lib/gitea chmod -R 750 /var/lib/gitea/ mkdir /etc/gitea chown root:git /etc/gitea chmod 770 /etc/gitea # insert gitea user echo "//-->> Prepare database" mysql -e "CREATE USER '$dbuser'@'localhost' IDENTIFIED BY '$dbpassword';" mysql -e "CREATE DATABASE $dbtable;" mysql -e "GRANT ALL PRIVILEGES ON $dbtable . * TO '$dbuser'@'localhost';" mysql -e "FLUSH PRIVILEGES;" # set system variables echo "//-->> Set system variables" export GITEA_WORK_DIR=/var/lib/gitea/ >> /dev/null 2>&1 echo "//-->> Copy Gite to: /usr/local/bin/gitea (replace binary to upgrade.)" mv gitea /usr/local/bin/gitea # set gitea service echo "//-->> Create gitea-service" cp "$pwd/config/gitea-service.txt" "/etc/systemd/system/gitea.service" systemctl enable gitea >> /dev/null 2>&1 service gitea start >> /dev/null 2>&1 if [[ run_ci_tests == 0 ]]; then while true; do read -p "Do you want to secure your mysql-installation? [Y/n]" yn case $yn in [Yy]* ) mysql_secure_installation; break;; [Jj]* ) mysql_secure_installation; break;; [Nn]* ) break;; * ) echo "ERROR! Please answer with [Y/n]";; esac done fi # gitea-auto-update echo "//-->> Create gitea-updater cronjob" apt-get install python3 python3-pip -q -y >> /dev/null 2>&1 pip3 install gitea-auto-update >> /dev/null 2>&1 mkdir /home/git/update echo "[Gitea] site=http://127.0.0.1:3000/api/v1/version apiUrl=https://api.github.com/repos/go-gitea/gitea/releases/latest system=linux-amd64 file=/usr/local/bin/gitea tmpDir=/tmp/ buildFromSource= sourceDir= logFile=/var/log/update.log" > /home/git/update/settings.ini crontab -l > giteaupdater echo "0 4 * * 1 /usr/local/bin/gitea-auto-update --settings=/home/git/update/settings.ini >/dev/null 2>&1" >> giteaupdater crontab giteaupdater rm giteaupdater # after install commands chmod 750 /etc/gitea chmod 660 /etc/gitea/app.ini echo "" echo "" # output install echo "##########################################################################" echo "Gitea was installed successfully!" echo "Now, open your browser and visit: http://$myIP:3000" echo "" echo "--- Database ---" echo "username: $dbuser" echo "password: $dbpassword" echo "database: $dbtable" echo "" echo "--- Gitea Settings ---" echo "Gitea Repositorie dir: /home/git/gitea-repositories" echo "" echo "##########################################################################" echo "Have fun :)"