Files
shell_sequencer/seqs/gitea.sh
2020-12-25 01:36:35 +01:00

188 lines
5.0 KiB
Bash
Executable File

#!/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_alias() { ALIAS="install"; }
step_1() {
exe apt update
}
step_2_info() {
echo "Downloading $toolName to user home from:"
echoinfo "$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 -e "Show configuration notes\n"; }
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() {
if [ ! -z $versionNow ] ; then
if [ "$giteaVersion" == "$versionNow" ] ; then
echo "No upgrade available. Already on latest: $versionNow"
else
echo "Download new version $giteaVersion to /usr/local/bin"
echoinfo " - installed version: $versionNow -"
fi
else
echo "Download new version $giteaVersion to /usr/local/bin"
fi
echo
}
step_12_alias() { ALIAS="upgrade"; }
step_12() {
if [ -f "$giteaLoc" ] ; then
local toolBackup="${giteaDir}/gitea_${versionNow}"
exe service gitea stop
saveReturn $?
endReturn
echo -n "Backing 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
}
versionNow=$(gitea --version | sed 's/.*version \([0-9.]\+\).*/\1/')
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