Files
shell_sequencer/seqs/gitea.sh
Martin Winkler d3b3a8d60b Download to tmp first in case of errors
database creation from external script
2021-04-08 09:07:58 +02:00

164 lines
4.3 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 "Creating /var/log/gitea"
exe mkdir -p /var/log/gitea
exe chown root:git /var/log/gitea
exe chmod 770 /var/log/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 "Starting $toolName service"; }
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="notes"; }
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 "Create mysql database for $toolName"; }
step_10() {
exe "$WDIR/mysql.sh" -qq createdb --charset utf8mb4
}
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
}
step_12_alias() { ALIAS="upgrade"; }
step_12() {
exe wget -O "$giteaDownLoc" $giteaDownload
endReturn -o $? "Download failed"
if [ -f "$giteaLoc" ] ; then
local toolBackup="${giteaDir}/gitea_${versionNow}"
exe service gitea stop
saveReturn $?
endReturn
echoseq -n "Backing up existing executable to ${toolBackup}..."
exe cp -ar "$giteaLoc" "$toolBackup" && echoseq "ok" || echoseq "nok"
fi
exe mv "$giteaDownLoc" "$giteaLoc"
exe chmod +x "$giteaLoc"
exe service gitea start
}
versionNow=$(gitea --version | sed 's/.*version \([0-9.]\+\).*/\1/')
giteaDownLoc="/tmp/giteaDown"
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=12
# Path to sequencer
. /usr/local/bin/sequencer.sh