Files
shell_sequencer/seqs/gitea.sh

209 lines
5.8 KiB
Bash
Executable File

#!/bin/bash
#
## Installation of self hosted git service Gitea
toolName="gitea"
# Get script working directory
# (when called from a different directory)
WDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >>/dev/null 2>&1 && pwd)"
APTOPT=
CONFIG=0
SCRIPT_FILE=$(basename -- $0)
SCRIPT_NAME=${SCRIPT_FILE%%.*}
CONFIG_FILE_NAME="${SCRIPT_NAME}.cfg"
CONFIG_FILE_TEMPLATE="$WDIR/${CONFIG_FILE_NAME}.example"
giteaLatestUrl="https://api.github.com/repos/go-gitea/gitea/releases/latest"
giteaVersion=$(curl --silent "$giteaLatestUrl" | grep -Po '"tag_name": "v\K.*?(?=")')
giteaArch=
giteaDownloadEval='https://dl.gitea.io/gitea/${giteaVersion}/gitea-${giteaVersion}-linux-${giteaArch}'
giteaDownload=$(eval echo $giteaDownloadEval)
giteaDir="/usr/local/bin"
giteaServiceLoc="/etc/systemd/system/gitea.service"
giteaLogDir="/var/log/gitea"
giteaIniLoc=
giteaDownFile="/tmp/giteaDown"
giteaUser="git"
versionNow=
step_config() {
initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE"
if [ $? -eq 0 ] ; then
CONFIG=1
else
# End if no configuration file exists
[ $DRY -eq 0 ] && return -1
fi
## Apt cmdline option to suppress user interaction
[ $QUIET -ne 0 ] && APTOPT="-y"
if [ -z $giteaVersion ] ; then
echoerr " [E] Couldn't determine latest version of $toolName"
fi
[ ! -z "$(command -v gitea)" ] && versionNow=$(gitea --version | sed 's/.*version \([0-9.]\+\).*/\1/')
checkArchitecture
giteaIniLoc="${SEQ_GITEA_CONF_DIR}/app.ini"
echoseq " [I] Gitea work: $SEQ_GITEA_WORK_DIR"
echoseq " Gitea config: $SEQ_GITEA_CONF_DIR"
echoseq " Git user home: $SEQ_GITEA_HOME_DIR"
echoseq
outColor yellow
echoseq " [W] Don't forget to adapt $SEQ_GITEA_CONF_DIR/app.ini"
outColor
## Return of non zero value will abort the sequence
return 0
}
checkArchitecture() {
[ ! -z "$(command -v dpkg)" ] && giteaArch=$(dpkg --print-architecture)
case $giteaArch in
armhf)
giteaArch="arm-6";;
esac
giteaDownload=$(eval echo $giteaDownloadEval)
}
step_1_info() { echo "Updating apt"; }
step_1_alias() { ALIAS="install"; }
step_1() {
exe apt update
}
step_2_info() {
[ -z "$giteaArch" ] && checkArchitecture
echo "Downloading $toolName to user home from:"
echoinfo "$giteaDownload"
}
step_2() {
exe wget -O "$giteaDownFile" $giteaDownload
saveReturn $?
endReturn
}
step_3_info() { echo "Adding user for $toolName ($giteaUser)"; }
step_3() {
exe adduser \
--system \
--shell /bin/bash \
--gecos 'Git Version Control' \
--group \
--disabled-password \
--home "$SEQ_GITEA_HOME_DIR" \
"$SEQ_GITEA_USER"
saveReturn $?
endReturn
}
step_4_info() { echo "Create required directory structure"; }
step_4() {
exe install -o $SEQ_GITEA_USER -g $SEQ_GITEA_USER -m 750 \
-d "$SEQ_GITEA_BACKUP_DIR" "$SEQ_GITEA_CONF_DIR" \
"$SEQ_GITEA_HOME_DIR" "$SEQ_GITEA_WORK_DIR"/{custom,data,log}
exe chown root:$SEQ_GITEA_USER "$SEQ_GITEA_CONF_DIR"
exe chmod 770 $SEQ_GITEA_CONF_DIR
echoseq "Creating $giteaLogDir"
exe install -g $SEQ_GITEA_USER -m 770 -d "$giteaLogDir"
echoseq -n "Copying gitea to global location and making it executable..."
exe install -b -m 755 -T "$giteaDownFile" "$SEQ_GITEA_BIN_LOC" && echo "ok"
endReturn "Failed to install $SEQ_GITEA_BIN_LOC"
}
step_5_info() { echo "Creating systemd service"; }
step_5() {
addConf -c "$SEQ_GITEA_SERVICE" "$giteaServiceLoc"
}
step_6_info() { echo "Starting $toolName service"; }
step_6() {
exe systemctl enable gitea --now
echoseq "Before proceeding to installation you may need to create a database first with step 10"
echoseq
echoseq "Goto http://[yourip]:3000/install and complete installation"
echoseq
echoseq "Afterwards please execute step 20 to secure configuration"
}
step_7_info() { echo "Show configuration notes"; }
step_7_alias() { ALIAS="notes"; }
step_7() {
outColor green
cat <<NOTES_END
Final configuration notes for $giteaIniLoc:
[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
NOTES_END
}
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 "Upgrade existing $toolName installation"
fi
}
step_12_alias() { ALIAS="upgrade"; }
step_12() {
endCheckEmpty versionNow "Please install $toolName first"
exe wget -O "$giteaDownFile" $giteaDownload
endReturn -o $? "Download failed"
if [ -f "$SEQ_GITEA_BIN_LOC" ] ; then
local toolBackup="${SEQ_GITEA_BACKUP_DIR}/gitea_${versionNow}"
exe service gitea stop
saveReturn $?
endReturn
echoseq -n "Backing up existing executable to ${toolBackup}..."
exe cp -ar "$SEQ_GITEA_BIN_LOC" "$toolBackup" && echoseq "ok" || echoseq "nok"
fi
exe install --backup=none -m 755 -T "$giteaDownFile" "$SEQ_GITEA_BIN_LOC"
endReturn -o $? "Upgrade failed"
exe service gitea start
}
step_20_info() { echo "Secure settings after installation"; }
step_20() {
exe chmod 750 "$SEQ_GITEA_CONF_DIR"
exe chmod 644 "$giteaIniLoc"
}
step_22_info() { echo "Open $toolName config file"; }
step_22_alias() { ALIAS="config"; }
step_22() {
exe vi "$giteaIniLoc"
}
VERSION_SEQREV=14
. /usr/local/bin/sequencer.sh