Files
shell_sequencer/seqs/gitea.sh
Martin Winkler bfccac6b28 Comment update
2019-04-03 09:52:41 +02:00

135 lines
3.3 KiB
Bash
Executable File

#!/bin/bash
#
## Installation of self hosted git service Gitea
toolName="gitea"
giteaDownload="https://dl.gitea.io/gitea/1.7.5/gitea-1.7.5-linux-arm-7"
giteaService="https://raw.githubusercontent.com/go-gitea/gitea/master/contrib/systemd/gitea.service"
giteaServiceLoc="/etc/systemd/system/gitea.service"
function step_1 {
echo -e "Updating apt\n"
apt update
}
function step_2 {
echo -e "Downloading $toolName to user home: $giteaDownload\n"
cd
wget -O gitea $giteaDownload
saveReturn $?
endReturn
}
function step_3 {
echo -e "Adding user for $toolName (git:git)"
adduser \
--system \
--shell /bin/bash \
--gecos 'Git Version Control' \
--group \
--disabled-password \
--home /home/git \
git
saveReturn $?
endReturn
}
function step_4 {
echo -e "Create required directory structure"
mkdir -p /var/lib/gitea/{custom,data,log}
chown -R git: /var/lib/gitea/
chmod -R 750 /var/lib/gitea/
mkdir /etc/gitea
chown root:git /etc/gitea
chmod 770 /etc/gitea
echo "Copying gitea to global location and making it executable"
chmod +x ~/gitea
cp ~/gitea /usr/local/bin/gitea
saveReturn $?
endReturn
}
function step_5 {
echo -e "Creating systemd service"
wget -O $giteaServiceLoc $giteaService
echo -en "Uncomment needed services (enter to continue): "
read
vi $giteaServiceLoc
}
function step_6 {
echo -e "Starting $toolName service"
systemctl enable gitea
systemctl start gitea
echo "Before proceeding to installation you may need to create a database first with step 10"
echo
echo "Goto http://[yourip]:3000/install and complete installation"
echo
echo "Afterwards please execute step 20 to secure configuration"
}
function step_10 {
local mysqlDatabase
local mysqlUser
local mysqlPass
echo "Setup mysql database"
echo "Existing mysql databases:"
mysql -u root -e 'SHOW DATABASES;'
echo -en "Enter database name: "
read mysqlDatabase
endCheckEmpty mysqlDatabase "database name"
mysql -u root -e 'CREATE DATABASE '$mysqlDatabase' CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;'
saveReturn $?
endReturn
echo "Existing mysql user:"
mysql -u root -e 'SELECT User, Host FROM mysql.user;'
echo -en "Enter mysql user name: "
read mysqlUser
endCheckEmpty mysqlDatabase "user name"
echo -en "Enter mysql user password: "
read mysqlPass
endCheckEmpty mysqlPass "password"
mysql -u root -e 'CREATE USER '"'"$mysqlUser"'"'@'"'"'localhost'"'"' IDENTIFIED BY '"'"$mysqlPass"'"';'
saveReturn $?
endReturn
mysql -u root -e 'GRANT ALL PRIVILEGES ON '$mysqlDatabase'.* TO '"'"$mysqlUser"'"'@'"'"'localhost'"'"';'
saveReturn $?
endReturn
mysql -u root -e 'FLUSH PRIVILEGES;'
}
function step_20 {
echo -e "Secure settings after installation"
chmod 750 /etc/gitea
chmod 644 /etc/gitea/app.ini
}
help() {
echo " $toolName Documentation"
echo " 1: Updating apt"
echo " 2: Downloading $toolName to user home: $giteaDownload"
echo " 3: Adding user for $toolName (git:git)"
echo " 4: Create required directory structure"
echo " 5: Creating systemd service"
echo " 6: Starting $toolName service"
echo
echo " 10: Setup mysql database"
echo
echo " 20: Secure settings after installation"
echo
}
#
## Path to sequencer
. ../sequencer/sequencer.sh