#!/bin/bash # ## Installation of self hosted git service Gitea toolName="gitea" giteaLatestUrl="https://api.github.com/repos/go-gitea/gitea/releases/latest" giteaVersion=$(curl --silent "$giteaLatestUrl" | grep -Po '"tag_name": "v\K.*?(?=")') giteaDownload="https://dl.gitea.io/gitea/${giteaVersion}/gitea-${giteaVersion}-linux-arm-6" giteaDir="/usr/local/bin" giteaLoc="${giteaDir}/gitea" giteaService="https://raw.githubusercontent.com/go-gitea/gitea/master/contrib/systemd/gitea.service" giteaServiceLoc="/etc/systemd/system/gitea.service" step_config() { if [ -z $giteaVersion ] ; then echoerr " [E] Couldn't determine latest version of $toolName" fi } step_1_info() { echo "Updating apt"; } step_1() { exe apt update } step_2_info() { echo "Downloading $toolName to user home: $giteaDownload"; } step_2() { exe wget -O ~/gitea $giteaDownload saveReturn $? endReturn } step_3_info() { echo "Adding user for $toolName (git:git)"; } step_3() { exe adduser \ --system \ --shell /bin/bash \ --gecos 'Git Version Control' \ --group \ --disabled-password \ --home /home/git \ git saveReturn $? endReturn } step_4_info() { echo "Create required directory structure"; } step_4() { exe mkdir -p /var/lib/gitea/{custom,data,log} exe chown -R git: /var/lib/gitea/ exe chmod -R 750 /var/lib/gitea/ exe mkdir /etc/gitea exe chown root:git /etc/gitea exe chmod 770 /etc/gitea echo -n "Copying gitea to global location and making it executable..." exe chmod +x ~/gitea exe cp -ar ~/gitea "$giteaLoc" && echo "ok" saveReturn $? endReturn } step_5_info() { echo "Creating systemd service"; } step_5() { exe wget -O "$giteaServiceLoc" "$giteaService" echo -en "Uncomment needed services mysql (enter to continue): " exe read exe vi $giteaServiceLoc } step_6_info() { echo -e "Starting $toolName service\n"; } step_6() { exe systemctl enable gitea exe systemctl start gitea echo "Before proceeding to installation you may need to create a database first with step 10" echo echo "Goto http://[yourip]:3000/install and complete installation" echo echo "Afterwards please execute step 20 to secure configuration" } step_7_info() { echo "Show configuration notes"; } step_7_alias() { ALIAS="config"; } step_7() { echo -e "Final configuration notes for app.ini:\n\n" echo "$CONFIG_NOTES" } CONFIG_NOTES="\ [repository] DEFAULT_CLOSE_ISSUES_VIA_COMMITS_IN_ANY_BRANCH = true [server] # Don't show home page LANDING_PAGE = explore [mailer] # Allow local MTA without valid certificate SKIP_VERIFY = true [service] # Use correct user identity when changing files in the web frontend NO_REPLY_ADDRESS = yourdomain.com [attachment] # Allow more archives to be uploaded ALLOWED_TYPES=application/zip|application/gzip|application/x-zip|application/x-gzip|application/x-shellscript|text/markdown" step_10_info() { echo -e "Create mysql database for $toolName\n"; } step_10() { local mysqlDatabase local mysqlUser local mysqlPass echo "Existing mysql databases:" exe mysql -u root -e 'SHOW DATABASES;' echo -en "Enter database name: " read mysqlDatabase endCheckEmpty mysqlDatabase "database name" exe mysql -u root -e 'CREATE DATABASE '$mysqlDatabase' CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;' saveReturn $? endReturn echo "Existing mysql user:" exe mysql -u root -e 'SELECT User, Host FROM mysql.user;' echo -en "Enter mysql user name: " read mysqlUser endCheckEmpty mysqlUser "user name" echo -en "Enter mysql user password: " read mysqlPass endCheckEmpty mysqlPass "password" exe mysql -u root -e 'CREATE USER '"'"$mysqlUser"'"'@'"'"'localhost'"'"' IDENTIFIED BY '"'"$mysqlPass"'"';' saveReturn $? endReturn exe mysql -u root -e 'GRANT ALL PRIVILEGES ON '$mysqlDatabase'.* TO '"'"$mysqlUser"'"'@'"'"'localhost'"'"';' saveReturn $? endReturn exe mysql -u root -e 'FLUSH PRIVILEGES;' } step_12_info() { echo "Download new version $giteaVersion to /usr/local/bin"; } step_12_alias() { ALIAS="upgrade"; } step_12() { if [ -f "$giteaLoc" ] ; then local versionNow=$(gitea --version | sed 's/.*version \([0-9.]\+\).*/\1/') local toolBackup="${giteaDir}/gitea_${versionNow}" exe service gitea stop saveReturn $? endReturn echo -n "Backuping up existing executable to ${toolBackup}..." exe cp -ar "$giteaLoc" "$toolBackup" && echo "ok" fi exe wget -O "$giteaLoc" $giteaDownload exe chmod +x "$giteaLoc" exe service gitea start } step_20_info() { echo "Secure settings after installation"; } step_20() { exe chmod 750 /etc/gitea exe chmod 644 /etc/gitea/app.ini } # Sequence Revision VERSION_SEQREV=10 # Path to sequencer . /usr/local/bin/sequencer.sh