193 lines
5.4 KiB
Bash
Executable File
193 lines
5.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
#
|
|
## Installation of self hosted git service Gitea
|
|
|
|
readonly toolName="gitea"
|
|
readonly giteaLatestUrl="https://api.github.com/repos/go-gitea/gitea/releases/latest"
|
|
readonly giteaVersion=$(curl --silent "$giteaLatestUrl" | grep -Po '"tag_name": "v\K.*?(?=")')
|
|
readonly giteaDir="/usr/local/bin"
|
|
readonly giteaServiceLoc="/etc/systemd/system/gitea.service"
|
|
readonly giteaLogDir="/var/log/gitea"
|
|
readonly giteaDownFile="/tmp/giteaDown"
|
|
readonly giteaUser="git"
|
|
|
|
giteaArch=
|
|
giteaDownloadEval='https://dl.gitea.io/gitea/${giteaVersion}/gitea-${giteaVersion}-linux-${giteaArch}'
|
|
giteaDownload=$(eval echo $giteaDownloadEval)
|
|
giteaIniLoc=
|
|
versionNow=
|
|
|
|
seq_config() {
|
|
if ! initSeqConfig "${seq_configName:?}" "${seq_configTemplate:?}" ; then
|
|
# End if no configuration file exists
|
|
dry || return 1
|
|
fi
|
|
|
|
if [ -z $giteaVersion ] ; then
|
|
error -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"
|
|
|
|
info "Gitea work: $SEQ_GITEA_WORK_DIR"
|
|
info -a "Gitea config: $SEQ_GITEA_CONF_DIR"
|
|
info -a "Git user home: $SEQ_GITEA_HOME_DIR"
|
|
info
|
|
color yellow
|
|
warning "Don't forget to adapt $SEQ_GITEA_CONF_DIR/app.ini"
|
|
color
|
|
|
|
## Return of non zero value will abort the sequence
|
|
return 0
|
|
}
|
|
|
|
checkArchitecture() {
|
|
[ -n "$giteaArch" ] && return 0
|
|
[ ! -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() { echo "install"; }
|
|
step_1() {
|
|
exe apt update
|
|
}
|
|
|
|
step_2_info() {
|
|
checkArchitecture
|
|
echo "Downloading $toolName to user home from:"
|
|
echoinfo "$giteaDownload"
|
|
}
|
|
step_2() {
|
|
exe wget -O "$giteaDownFile" $giteaDownload
|
|
}
|
|
|
|
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"
|
|
}
|
|
|
|
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
|
|
info "Creating $giteaLogDir"
|
|
exe install -g $SEQ_GITEA_USER -m 770 -d "$giteaLogDir"
|
|
info -n "Copying gitea to global location and making it executable..."
|
|
exe install -b -m 755 -T "$giteaDownFile" "$SEQ_GITEA_BIN_LOC" && info -d "ok"
|
|
endReturn -o $? "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
|
|
info "Before proceeding to installation you may need to create a database first with step 10"
|
|
info
|
|
info "Goto http://[yourip]:3000/install and complete installation"
|
|
info
|
|
info "Afterwards please execute step 20 to secure configuration"
|
|
}
|
|
|
|
step_7_info() { echo "Show configuration notes"; }
|
|
step_7_alias() { echo "notes"; }
|
|
step_7() {
|
|
color 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 "${seq_origin}/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() { echo "upgrade"; }
|
|
step_12() {
|
|
endIfEmpty 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
|
|
sqr::echo -n "Backing up existing executable to ${toolBackup}..."
|
|
exe cp -ar "$SEQ_GITEA_BIN_LOC" "$toolBackup" && sqr::echo "ok" || sqr::echo "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() { echo "config"; }
|
|
step_22() {
|
|
exe vi "$giteaIniLoc"
|
|
}
|
|
|
|
# shellcheck disable=SC2034 # Appears unused
|
|
readonly sqr_minVersion=16
|
|
# shellcheck disable=SC1091 # Don't follow this source
|
|
. /usr/local/bin/sequencer.sh
|