#!/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 "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 <