#!/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= seq_config() { initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE" if [ $? -eq 0 ] ; then CONFIG=1 else # End if no configuration file exists dry || return -1 fi ## Apt cmdline option to suppress user interaction quiet && APTOPT="-y" 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 " Gitea config: $SEQ_GITEA_CONF_DIR" info " 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() { [ ! -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() { [ -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 info "Creating $giteaLogDir" exe install -g $SEQ_GITEA_USER -m 770 -d "$giteaLogDir" sqr::echo -n "Copying gitea to global location and making it executable..." exe install -b -m 755 -T "$giteaDownFile" "$SEQ_GITEA_BIN_LOC" && sqr::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 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 <