Gitea - Now configurable with default pathes in one place for better backup/migration
This commit is contained in:
57
seqs/gitea.cfg.example
Normal file
57
seqs/gitea.cfg.example
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
SEQ_GITEA_USER="git"
|
||||||
|
SEQ_GITEA_BIN_LOC="/usr/local/bin/gitea"
|
||||||
|
SEQ_GITEA_BASE_DIR="/var/lib/gitea"
|
||||||
|
SEQ_GITEA_WORK_DIR="$SEQ_GITEA_BASE_DIR/work"
|
||||||
|
SEQ_GITEA_HOME_DIR="$SEQ_GITEA_BASE_DIR/home"
|
||||||
|
SEQ_GITEA_CONF_DIR="$SEQ_GITEA_BASE_DIR/config"
|
||||||
|
SEQ_GITEA_BACKUP_DIR="$SEQ_GITEA_BASE_DIR/backup"
|
||||||
|
|
||||||
|
# Service Derived from
|
||||||
|
# https://raw.githubusercontent.com/go-gitea/gitea/master/contrib/systemd/gitea.service
|
||||||
|
SEQ_GITEA_SERVICE="[Unit]
|
||||||
|
Description=Gitea (Git with a cup of tea)
|
||||||
|
After=syslog.target
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
Requires=mysql.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
# Modify these two values and uncomment them if you have
|
||||||
|
# repos with lots of files and get an HTTP error 500 because
|
||||||
|
# of that
|
||||||
|
###
|
||||||
|
#LimitMEMLOCK=infinity
|
||||||
|
#LimitNOFILE=65535
|
||||||
|
|
||||||
|
RestartSec=2s
|
||||||
|
Type=simple
|
||||||
|
User=$SEQ_GITEA_USER
|
||||||
|
Group=$SEQ_GITEA_USER
|
||||||
|
WorkingDirectory=$SEQ_GITEA_WORK_DIR
|
||||||
|
|
||||||
|
# If using Unix socket: tells systemd to create the /run/gitea folder, which will contain the gitea.sock f
|
||||||
|
# (manually creating /run/gitea doesn't work, because it would not persist across reboots)
|
||||||
|
#RuntimeDirectory=gitea
|
||||||
|
ExecStart=/usr/local/bin/gitea web --config \"$SEQ_GITEA_CONF_DIR/app.ini\"
|
||||||
|
|
||||||
|
Restart=always
|
||||||
|
Environment=USER=\"$SEQ_GITEA_USER\" HOME=\"$SEQ_GITEA_HOME_DIR\" GITEA_WORK_DIR=\"$SEQ_GITEA_WORK_DIR\"
|
||||||
|
|
||||||
|
# If you install Git to directory prefix other than default PATH (which happens
|
||||||
|
# for example if you install other versions of Git side-to-side with
|
||||||
|
# distribution version), uncomment below line and add that prefix to PATH
|
||||||
|
# Don't forget to place git-lfs binary on the PATH below if you want to enable
|
||||||
|
# Git LFS support
|
||||||
|
#Environment=PATH=/path/to/git/bin:/bin:/sbin:/usr/bin:/usr/sbin
|
||||||
|
|
||||||
|
# If you want to bind Gitea to a port below 1024, uncomment
|
||||||
|
# the two values below, or use socket activation to pass Gitea its ports as above
|
||||||
|
###
|
||||||
|
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE
|
||||||
|
#AmbientCapabilities=CAP_NET_BIND_SERVICE
|
||||||
|
###
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target"
|
140
seqs/gitea.sh
140
seqs/gitea.sh
@@ -4,20 +4,68 @@
|
|||||||
## Installation of self hosted git service Gitea
|
## Installation of self hosted git service Gitea
|
||||||
|
|
||||||
toolName="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"
|
giteaLatestUrl="https://api.github.com/repos/go-gitea/gitea/releases/latest"
|
||||||
giteaVersion=$(curl --silent "$giteaLatestUrl" | grep -Po '"tag_name": "v\K.*?(?=")')
|
giteaVersion=$(curl --silent "$giteaLatestUrl" | grep -Po '"tag_name": "v\K.*?(?=")')
|
||||||
giteaDownload="https://dl.gitea.io/gitea/${giteaVersion}/gitea-${giteaVersion}-linux-arm-6"
|
giteaArch=
|
||||||
|
giteaDownloadEval='https://dl.gitea.io/gitea/${giteaVersion}/gitea-${giteaVersion}-linux-${giteaArch}'
|
||||||
|
giteaDownload=$(eval echo $giteaDownloadEval)
|
||||||
giteaDir="/usr/local/bin"
|
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"
|
giteaServiceLoc="/etc/systemd/system/gitea.service"
|
||||||
giteaConfigDir="/etc/gitea"
|
giteaLogDir="/var/log/gitea"
|
||||||
giteaIniLoc="${giteaConfigDir}/app.ini"
|
giteaIniLoc=
|
||||||
|
giteaDownFile="/tmp/giteaDown"
|
||||||
|
giteaUser="git"
|
||||||
|
versionNow=
|
||||||
|
|
||||||
step_config() {
|
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
|
if [ -z $giteaVersion ] ; then
|
||||||
echoerr " [E] Couldn't determine latest version of $toolName"
|
echoerr " [E] Couldn't determine latest version of $toolName"
|
||||||
fi
|
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_info() { echo "Updating apt"; }
|
||||||
@@ -27,16 +75,17 @@ step_1() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
step_2_info() {
|
step_2_info() {
|
||||||
|
[ -z "$giteaArch" ] && checkArchitecture
|
||||||
echo "Downloading $toolName to user home from:"
|
echo "Downloading $toolName to user home from:"
|
||||||
echoinfo "$giteaDownload"
|
echoinfo "$giteaDownload"
|
||||||
}
|
}
|
||||||
step_2() {
|
step_2() {
|
||||||
exe wget -O ~/gitea $giteaDownload
|
exe wget -O "$giteaDownFile" $giteaDownload
|
||||||
saveReturn $?
|
saveReturn $?
|
||||||
endReturn
|
endReturn
|
||||||
}
|
}
|
||||||
|
|
||||||
step_3_info() { echo "Adding user for $toolName (git:git)"; }
|
step_3_info() { echo "Adding user for $toolName ($giteaUser)"; }
|
||||||
step_3() {
|
step_3() {
|
||||||
exe adduser \
|
exe adduser \
|
||||||
--system \
|
--system \
|
||||||
@@ -44,48 +93,39 @@ step_3() {
|
|||||||
--gecos 'Git Version Control' \
|
--gecos 'Git Version Control' \
|
||||||
--group \
|
--group \
|
||||||
--disabled-password \
|
--disabled-password \
|
||||||
--home /home/git \
|
--home "$SEQ_GITEA_HOME_DIR" \
|
||||||
git
|
"$SEQ_GITEA_USER"
|
||||||
saveReturn $?
|
saveReturn $?
|
||||||
endReturn
|
endReturn
|
||||||
}
|
}
|
||||||
|
|
||||||
step_4_info() { echo "Create required directory structure"; }
|
step_4_info() { echo "Create required directory structure"; }
|
||||||
step_4() {
|
step_4() {
|
||||||
exe mkdir -p /var/lib/gitea/{custom,data,log}
|
exe install -o $SEQ_GITEA_USER -g $SEQ_GITEA_USER -m 750 \
|
||||||
exe chown -R git: /var/lib/gitea/
|
-d "$SEQ_GITEA_BACKUP_DIR" "$SEQ_GITEA_CONF_DIR" \
|
||||||
exe chmod -R 750 /var/lib/gitea/
|
"$SEQ_GITEA_HOME_DIR" "$SEQ_GITEA_WORK_DIR"/{custom,data,log}
|
||||||
exe mkdir /etc/gitea
|
exe chown root:$SEQ_GITEA_USER "$SEQ_GITEA_CONF_DIR"
|
||||||
exe chown root:git /etc/gitea
|
exe chmod 770 $SEQ_GITEA_CONF_DIR
|
||||||
exe chmod 770 /etc/gitea
|
echoseq "Creating $giteaLogDir"
|
||||||
echo "Creating /var/log/gitea"
|
exe install -g $SEQ_GITEA_USER -m 770 -d "$giteaLogDir"
|
||||||
exe mkdir -p /var/log/gitea
|
echoseq -n "Copying gitea to global location and making it executable..."
|
||||||
exe chown root:git /var/log/gitea
|
exe install -b -m 755 -T "$giteaDownFile" "$SEQ_GITEA_BIN_LOC" && echo "ok"
|
||||||
exe chmod 770 /var/log/gitea
|
endReturn "Failed to install $SEQ_GITEA_BIN_LOC"
|
||||||
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_info() { echo "Creating systemd service"; }
|
||||||
step_5() {
|
step_5() {
|
||||||
exe wget -O "$giteaServiceLoc" "$giteaService"
|
addConf -c "$SEQ_GITEA_SERVICE" "$giteaServiceLoc"
|
||||||
echo -en "Uncomment needed services mysql (enter to continue): "
|
|
||||||
exe read
|
|
||||||
exe vi $giteaServiceLoc
|
|
||||||
}
|
}
|
||||||
|
|
||||||
step_6_info() { echo "Starting $toolName service"; }
|
step_6_info() { echo "Starting $toolName service"; }
|
||||||
step_6() {
|
step_6() {
|
||||||
exe systemctl enable gitea
|
exe systemctl enable gitea --now
|
||||||
exe systemctl start gitea
|
echoseq "Before proceeding to installation you may need to create a database first with step 10"
|
||||||
echo "Before proceeding to installation you may need to create a database first with step 10"
|
echoseq
|
||||||
echo
|
echoseq "Goto http://[yourip]:3000/install and complete installation"
|
||||||
echo "Goto http://[yourip]:3000/install and complete installation"
|
echoseq
|
||||||
echo
|
echoseq "Afterwards please execute step 20 to secure configuration"
|
||||||
echo "Afterwards please execute step 20 to secure configuration"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
step_7_info() { echo "Show configuration notes"; }
|
step_7_info() { echo "Show configuration notes"; }
|
||||||
@@ -122,7 +162,7 @@ step_10() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
step_12_info() {
|
step_12_info() {
|
||||||
if [ ! -z $versionNow ] ; then
|
if [ ! -z "$versionNow" ] ; then
|
||||||
if [ "$giteaVersion" == "$versionNow" ] ; then
|
if [ "$giteaVersion" == "$versionNow" ] ; then
|
||||||
echo "No upgrade available. Already on latest: $versionNow"
|
echo "No upgrade available. Already on latest: $versionNow"
|
||||||
else
|
else
|
||||||
@@ -130,37 +170,39 @@ step_12_info() {
|
|||||||
echoinfo " - installed version: $versionNow -"
|
echoinfo " - installed version: $versionNow -"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "Download new version $giteaVersion to /usr/local/bin"
|
echo "Upgrade existing $toolName installation"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
step_12_alias() { ALIAS="upgrade"; }
|
step_12_alias() { ALIAS="upgrade"; }
|
||||||
step_12() {
|
step_12() {
|
||||||
exe wget -O "$giteaDownLoc" $giteaDownload
|
endCheckEmpty versionNow "Please install $toolName first"
|
||||||
|
exe wget -O "$giteaDownFile" $giteaDownload
|
||||||
endReturn -o $? "Download failed"
|
endReturn -o $? "Download failed"
|
||||||
|
|
||||||
if [ -f "$giteaLoc" ] ; then
|
if [ -f "$SEQ_GITEA_BIN_LOC" ] ; then
|
||||||
local toolBackup="${giteaDir}/gitea_${versionNow}"
|
local toolBackup="${SEQ_GITEA_BACKUP_DIR}/gitea_${versionNow}"
|
||||||
exe service gitea stop
|
exe service gitea stop
|
||||||
saveReturn $?
|
saveReturn $?
|
||||||
endReturn
|
endReturn
|
||||||
echoseq -n "Backing up existing executable to ${toolBackup}..."
|
echoseq -n "Backing up existing executable to ${toolBackup}..."
|
||||||
exe cp -ar "$giteaLoc" "$toolBackup" && echoseq "ok" || echoseq "nok"
|
exe cp -ar "$SEQ_GITEA_BIN_LOC" "$toolBackup" && echoseq "ok" || echoseq "nok"
|
||||||
fi
|
fi
|
||||||
exe mv "$giteaDownLoc" "$giteaLoc"
|
exe install -m 755 -T "$giteaDownFile" "$SEQ_GITEA_BIN_LOC"
|
||||||
exe chmod +x "$giteaLoc"
|
endReturn -o $? "Upgrade failed"
|
||||||
exe service gitea start
|
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_info() { echo "Secure settings after installation"; }
|
||||||
step_20() {
|
step_20() {
|
||||||
exe chmod 750 "$giteaConfigDir"
|
exe chmod 750 "$SEQ_GITEA_CONF_DIR"
|
||||||
exe chmod 644 "$giteaIniLoc"
|
exe chmod 644 "$giteaIniLoc"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Sequence Revision
|
step_22_info() { echo "Open $toolName config file"; }
|
||||||
VERSION_SEQREV=12
|
step_22_alias() { ALIAS="config"; }
|
||||||
|
step_22() {
|
||||||
|
exe vi "$giteaIniLoc"
|
||||||
|
}
|
||||||
|
|
||||||
# Path to sequencer
|
VERSION_SEQREV=14
|
||||||
. /usr/local/bin/sequencer.sh
|
. /usr/local/bin/sequencer.sh
|
||||||
|
Reference in New Issue
Block a user