minor changes

This commit is contained in:
allan 2025-05-27 15:12:47 +02:00
parent b26309551d
commit c440935b5c

View File

@ -12,12 +12,11 @@ if [[ $(id -u) -ne 0 ]]; then echo "" && echo "Must be root or use sudo" && echo
# Are we in the right directory
#
scriptdir="gitea-multi-install" && whereami=$(pwd |awk -F'/' '{print $NF}')
if [ $whereami != $scriptdir ]; then printf "\nWrong directory! Script must be run from $scriptdir\n\n" ; exit ; fi
if [ "$whereami" != "$scriptdir" ]; then printf "\nWrong directory! Script must be run from %s\n\n" "$scriptdir"; exit 1; fi
#
# Define variables and functions
#
red='\033[0;31m' ; bred='\033[1;31m' ; green='\033[0;92m' ; blue='\033[0;36m' ; bold='\033[1m' ; normal='\033[0m'
line (){ for i in {1..50}; do echo -n "$1"; done && printf "\n"; }
line () { printf -- '-%.0s' {1..50}; printf '\n'; }
giteauser=$(cat /etc/passwd |grep "gitea" |awk -F':' '{print $1}' | sort -V |sed 's/gitea//g' |tail -n 1)
giteadb="db"
giteaport="3000"
@ -32,24 +31,24 @@ title () { printf "\nGitea multi instance install script V1.0 \n\n"; }
# Function usage
#
usage () { clear ; printf -- "\n"
printf -- "${bold}giteamultiinstall${normal} \n\n"
printf -- "${bold}Usage:${normal} \n"
printf -- "giteamultiinstall \n\n"
printf -- "Usage: \n"
printf -- "./giteainstall [-n] <gitea domain> \n"
printf -- " [-p] <gitea database password> \n"
printf -- " [-help] <this screen> \n\n"
printf -- "${bold}Examples:${normal} \n"
printf -- "Examples: \n"
printf -- "./giteamultiinstall -n git.something.xyz -p giteadatabsepwd\n\n"; }
#
# Function to check if a service is already running or not
#
serviceno () { printf "\n$service is not running cannot continue...\n\n"; }
serviceno () { printf "\n%s" $service ; printf " is not running cannot continue...\n\n"; }
servicedead () { status=$(systemctl is-active $service); if [[ "$status" != "active" ]]; then serviceno ; exit; fi; }
#
# Function input check
#
inputcheck () {
if [[ -z "$hostname" ]]; then usage ; printf "${bold}Error! ${normal}Hostname Empty...\n\n" ; exit; fi
if [[ -z "$giteapwd" ]]; then usage ; printf "${bold}Error! ${normal}Database Password Empty...\n\n" ; exit; fi; }
if [[ -z "$hostname" ]]; then usage ; printf "Error! Hostname Empty...\n\n" ; exit; fi
if [[ -z "$giteapwd" ]]; then usage ; printf "Error! Database Password Empty...\n\n" ; exit; fi; }
#
# If Nginx and MariaDB is not running then die
#
@ -58,10 +57,15 @@ service="mariadb" ; servicedead ; service="nginx" ; servicedead
# Display title
#
clear ; title
#
# Configure command line options
#
if [[ ! $@ =~ ^\-.+ ]]; then usage; fi
# Removed due to SC2199 and not really needed start
# if [[ ! $@ =~ ^\-.+ ]]; then usage; fi
# Removed due to SC2199 and not really needed stop
# shellcheck disable=SC2086
while getopts "n:p:h:" option; do
case $option in
@ -76,13 +80,13 @@ while getopts "n:p:h:" option; do
usage ; exit;;
\?) # invalid option
printf "Type $0 -help for help\n\n" ; exit;;
printf "\nType sudo " ; printf "%s" "$0" ; printf " -help for help\n\n" ; exit;;
esac
done
#
# Check if input conditions are met
#
inputcheck $hostname $giteapwd
inputcheck "$hostname" "$giteapwd"
#
# Check if a Nginx conf file with the hostname allready exists
#
@ -92,8 +96,8 @@ if [ ! -z "$hostcheck" ]; then printf "Found a configuration file already contai
# Download gitea only if gitea does not allready exists in /etc/gitea
#
if [ ! -f $gitealocation ]
then wget --no-verbose https://dl.gitea.com/gitea/$giteaversion/gitea-$giteaversion-linux-amd64
mv gitea-$giteaversion-linux-amd64 /usr/local/bin/gitea ; chmod +x /usr/local/bin/gitea
then wget --no-verbose https://dl.gitea.com/gitea/"$giteaversion"/gitea-"$giteaversion"-linux-amd64
mv gitea-"$giteaversion"-linux-amd64 /usr/local/bin/gitea ; chmod +x /usr/local/bin/gitea
else : ; fi
#
# Check if nginxsnippets exist if not download them
@ -122,8 +126,8 @@ mysql < giteasql.sql
#
# Create a Gitea Nginx configuration file
#
curl --silent curl https://git.x-files.dk/ubuntu-web-server/nginx-install/raw/branch/main/cfg-apps/gitea.80.conf > /etc/nginx/conf.d/$hostname.conf
sed -s -i "s/DOMAIN/$hostname/g" /etc/nginx/conf.d/$hostname.conf
curl --silent curl https://git.x-files.dk/ubuntu-web-server/nginx-install/raw/branch/main/cfg-apps/gitea.80.conf > /etc/nginx/conf.d/"$hostname".conf
sed -s -i "s/DOMAIN/$hostname/g" /etc/nginx/conf.d/"$hostname".conf
#
# Restarting Nginx for changes to take effect
systemctl restart nginx
@ -219,7 +223,7 @@ clear ; printf '%s\n' "${giteanotice[@]}"
#
# Adding gitea user number to cfg for use with postinstall
#
echo $giteauser > giteainfo ; echo $giteaport >> giteainfo ; echo $hostname.conf >> giteainfo
echo $giteauser > giteainfo ; echo $giteaport >> giteainfo ; echo "$hostname".conf >> giteainfo
#
# Cleaning up
#