From c25f73b9094bf0fff62221492f467b621e9ad248 Mon Sep 17 00:00:00 2001 From: allan Date: Thu, 24 Oct 2024 12:58:14 +0200 Subject: [PATCH] initial commit --- LICENSE | 21 ++++++ README.md | 61 +++++++++++++++ giteainstall | 205 +++++++++++++++++++++++++++++++++++++++++++++++++++ postinstall | 85 +++++++++++++++++++++ version | 1 + 5 files changed, 373 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100755 giteainstall create mode 100755 postinstall create mode 100644 version diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..57f408b --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Allan Christensen + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..f2724fe --- /dev/null +++ b/README.md @@ -0,0 +1,61 @@ +## Gitea install script for a single instance of Gitea for Ubuntu 22.04 and 24.04 server. + +### Prerequisites +Ubuntu 22.04 or higher with Nginx and MariaDB. Nginx can be installed from +[\[Here\]](https://git.x-files.dk/ubuntu-web-server/nginx-install) +and MariaDB can be install from +[\[Here\]](https://git.x-files.dk/ubuntu-database-server/mariadb-install) + +> **NOTE** +> +> If you in the future plan to install a second or third instance of Gitea I would recomend using the Gitea multiple instance script from +[\[Here\]](https://git.x-files.dk/ubuntu-web-application/gitea-multi-install) + +### Download the script +``` +git clone https://git.x-files.dk/ubuntu-web-application/gitea-install.git +``` + +### Usage + cd gitea-install + sudo ./giteainstall [-n] [-p] + +### Example + sudo ./giteainstall -n git.something.xyz -p giteadatabasepwd + +This will create a Gitea site running on port 80 with the domain name you chose under the installation. +Don't worry though this can easily be fixed by modifying the Nginx configuration later. +If you need an example on how to configure Nginx to run this on port 443 I an example +[\[Here\]](https://git.x-files.dk/ubuntu-web-server/nginx-install/src/branch/main/cfg-apps/gitea.443.conf). Also make sure that you correct the /etc/gitea/app.ini to reflect the changes as well i.e change http to https in the app.ini file and then restart Nginx and the Gitea instance. + +### Configuration +Once the script is done browse to http://git.something.xyz and fill out the mandatory fields marked with green. +

+Gitea Configuration +

+ +### Post install +This is needed in order to change a few configurations in app.ini which is first created when you are done with the setup screen. + + cd gitea-install + sudo ./postinstall + +### Custom layout +Gitea takes the favicon in form of a svg file and a png file as fallback for browsers that does not support it. A custom logo can also be used. For all 3 files goes the following. They need to be placed in the folowing directory:\ +\/var\/lib\/gitea\/custom\/public\/assets\/img\/ + +Gitea can also serve a splash page instead of the build in one you will need to create a home.tmpl and place it in the following directory:\ +\/var\/lib\/gitea\/custom\/templates\/ + +### Troubleshooting +Most issues will probably be caused by the fact that we all set up and configure Nginx diffrently. If you encounter problems I would suggest you look at the Nginx configuration I use +[\[Here\]](https://git.x-files.dk/ubuntu-web-server/nginx-install/src/branch/main/cfg/nginx.conf) +and also the default "sites-enabled" Nginx configurarion I use +[\[Here\]](https://git.x-files.dk/ubuntu-web-server/nginx-install/src/branch/main/cfg/default) +when you start troubleshooting. + +### More guides +More guides can be found on [\[wiki.x-files.dk\]](https://wiki.x-files.dk) + +### Last tested +October 10th 2024 on Ubuntu 24.04. diff --git a/giteainstall b/giteainstall new file mode 100755 index 0000000..5e4bc1f --- /dev/null +++ b/giteainstall @@ -0,0 +1,205 @@ +#!/bin/bash + +################################################################################################### +# First Created: 12032021 Author: Allan Desc: Installs Gitea on Ubuntu requires Nginx and MariaDB # +################################################################################################### + +# +# Are we root +# +if [[ $(id -u) -ne 0 ]]; then echo "" && echo "Must be root or use sudo" && echo "" ; exit ; fi +# +# Are we in the right directory +# +scriptdir="gitea-install" && whereami=$(pwd |awk -F'/' '{print $NF}') +if [ $whereami != $scriptdir ]; then printf "\nWrong directory! Script must be run from $scriptdir\n\n" ; exit ; 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"; } +giteaversion=$(tail -1 version) +nginxfiles="/etc/nginx/nginxsnippets" +# +# Function title +# +title () { printf "\nGitea install script V1.0\n\n"; } +# +# Function usage +# +usage () { clear ; printf -- "\n" +printf -- "${bold}giteainstall${normal} \n\n" +printf -- "${bold}Usage:${normal} \n" +printf -- "./giteainstall [-n] \n" +printf -- " [-p] \n" +printf -- " [-help] \n\n" +printf -- "${bold}Examples:${normal} \n" +printf -- "./giteainstall -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"; } +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 Nginx and MariaDB is not running then die +# +service="mariadb" ; servicedead ; service="nginx" ; servicedead +# +# Display title +# +clear ; title +# +# Configure command line options +# +if [[ ! $@ =~ ^\-.+ ]]; then usage; fi + +while getopts "n:p:h:" option; do + case $option in + + n) # hostname + hostname=$(echo ${OPTARG} | tr '[:upper:]' '[:lower:]');; + + p) # database password + giteapwd=$OPTARG;; + + h) # display help + usage ; exit;; + + \?) # invalid option + printf "Type $0 -help for help\n\n" ; exit;; + esac +done +# +# Check if input conditions are met +# +inputcheck $hostname $giteapwd +# +# Download and install Gitea +# +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 +# +# Check if nginxsnippets exist if not download them +# +if [[ ! -d "$nginxfiles" ]]; then +git clone --quiet https://git.x-files.dk/ubuntu-web-server/nginx-install.git ; cp -R nginx-install/nginxsnippets /etc/nginx +fi +# +# Create Gitea database +# +giteasql=" +connect mysql +create database gitea; +GRANT ALL PRIVILEGES ON gitea.* TO 'gitea'@'127.0.0.1' IDENTIFIED BY '$giteapwd'; +FLUSH PRIVILEGES; +" +printf '%s\n' "${giteasql[@]}" |sed '1d; $d' > giteasql.sql +mysql < giteasql.sql +# +# Create a Gitea Nginx configuration file +# +curl --silent 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 ; echo "$hostname" > $hostname.conf +# +# Restarting Nginx for changes to take effect +systemctl restart nginx +# +# Create Gitea user +# +adduser --system --group --disabled-password --shell /bin/bash --home /home/git --gecos 'Git Version Control' git +# +# Create Gitea standard folders +# +mkdir -p /var/lib/gitea/{custom,data,indexers,public,log} +chown git:git /var/lib/gitea/{data,indexers,log} +chmod 750 /var/lib/gitea/{data,indexers,log} +mkdir /etc/gitea +chown root:git /etc/gitea +chmod 770 /etc/gitea +# +# Create Gitea systemd script +# +giteasystemd=" +[Unit] +Description=Gitea (Git with a cup of tea) +After=syslog.target +After=network.target +Requires=mysql.service + +[Service] +LimitMEMLOCK=infinity +LimitNOFILE=65535 +RestartSec=2s +Type=simple +User=git +Group=git +WorkingDirectory=/var/lib/gitea/ +ExecStart=/usr/local/bin/gitea web -c /etc/gitea/app.ini +Restart=always +Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea +#CapabilityBoundingSet=CAP_NET_BIND_SERVICE +#AmbientCapabilities=CAP_NET_BIND_SERVICE + +[Install] +WantedBy=multi-user.target +" +printf '%s\n' "${giteasystemd[@]}" |sed '1d; $d' > giteasystemd +cat giteasystemd > /etc/systemd/system/gitea.service +# +# Create Gitea customization directories +# +mkdir -p /var/lib/gitea/custom/templates +mkdir -p /var/lib/gitea/custom/public/assets/img +# +# Start Gitea services +# +systemctl daemon-reload +systemctl enable gitea +systemctl start gitea +# +# Gitea postinstall notice +# +giteanotice=" +--------------------------------------------------------------------------------------------------- +IMPORTANT: Go to http://$hostname and modify the following settings: + +DATABASE SETTINGS --------------------------------------------------------------------------------- +DATABASE PASSWORD = $giteapwd + +GENERAL SETTINGS ---------------------------------------------------------------------------------- +SITE TITLE = YOUR SITE TITLE HERE + +SERVER AND THIRD-PARTY SERVICE SETTINGS ----------------------------------------------------------- +HIDE EMAIL ADDRESSES BY DEFAULT = CHECKMARK + +ADMINISTRATOR ACCOUNT SETTINGS -------------------------------------------------------------------- +ADMINISTRATOR USERNAME = ADMINUSERNAME +PASSWORD = ADMINPASSWORD +EMAIL ADDRESS = ADMINEMAIL +--------------------------------------------------------------------------------------------------- + +IMPORTANT: Once done go back to \"gitea-install\" and run the following as root or using sudo. + + ./postinstall + +NOTE: SSH will be disabled after running postinsall. You can modify this in /etc/gitea/app.ini + All other options in /etc/gitea/app.ini are optional and can be modified as you see fit. +--------------------------------------------------------------------------------------------------- +" +# +# Display post install note +# +clear ; printf '%s\n' "${giteanotice[@]}" +# +# Cleaning up +# +rm -Rf giteasql.sql version giteasystemd nginx-install +# +# End of script +# diff --git a/postinstall b/postinstall new file mode 100755 index 0000000..8337137 --- /dev/null +++ b/postinstall @@ -0,0 +1,85 @@ +#!/bin/bash + +######################################################################## +# First Created: 12032021 Author: Allan Desc: Gitea postinstall script # +######################################################################## + +# +# Are we root +# +if [[ $(id -u) -ne 0 ]]; then echo "" && echo "Must be root or use sudo" && echo ""; exit 1; fi + +# +# Are we in the right directory +# +scriptdir="gitea-install" && whereami=$(pwd |awk -F'/' '{print $NF}') +if [ $whereami != $scriptdir ]; then printf "\nWrong directory! Script must be run from $scriptdir\n\n"; exit 1; fi + +# +# Define variables and functions +# +nginxconfig=$(ls -la |grep "conf" |awk '{print $9}') +line (){ for i in {1..50}; do echo -n "$1"; done && printf "\n"; } +# +# Function to check if a service is already running or not +# +serviceno () { printf "\n$service is not running cannot continue...\n\n"; } +servicedead () { status=$(systemctl is-active $service); if [[ "$status" != "active" ]]; then serviceno ; exit; fi; } +# +# Function title +# +title () { printf "\nGitea postinstall script V1.0${normal}\n\n"; } +# +# If Gitea is not running then die +# +service="gitea" ; servicedead +# +# Adjusting Gitea configuration parameters +# +cp -Rp /etc/gitea/app.ini /etc/gitea/app.ini.orig +sed -i '/gitea-repositories/a MAX_FILES = 500' /etc/gitea/app.ini +sed -i '/gitea-repositories/a FILE_MAX_SIZE = 200' /etc/gitea/app.ini +sed -i 's/LEVEL = info/LEVEL = warn/' /etc/gitea/app.ini +sed -i 's/MODE = console/MODE = file/' /etc/gitea/app.ini +sed -i 's/DISABLE_SSH = false/DISABLE_SSH = true/' /etc/gitea/app.ini +# +# Gitea post configuration values +# +giteaconfig=" +[ui.admin] +USER_PAGING_NUM = 50 +REPO_PAGING_NUM = 50 +NOTICE_PAGING_NUM = 25 +ORG_PAGING_NUM = 25 + +[ui.user] +USER_PAGING_NUM = 50 +REPO_PAGING_NUM = 50 +NOTICE_PAGING_NUM = 25 +ORG_PAGING_NUM = 25 + +[ui] +THEMES = gitea,arc-green + +[other] +SHOW_FOOTER_BRANDING = false +SHOW_FOOTER_VERSION = false +SHOW_FOOTER_TEMPLATE_LOAD_TIME = false +ENABLE_FEED = false +" +printf '%s\n' "${giteaconfig[@]}" |sed '$d' >> /etc/gitea/app.ini +# +# Adjusting gitea nginx configuration and cleaning up +# +sed -i 's/# Optional //' /etc/nginx/conf.d/$nginxconfig ; rm $nginxconfig +# +# Restart Gitea and Nginx in order for changes to take effect +# +systemctl restart gitea ; systemctl restart nginx +# +# All done +# +clear ; printf "\n" ; line '-' ; printf "All Done...\n" ; line '-' ; printf "\n" +# +# End of script +# diff --git a/version b/version new file mode 100644 index 0000000..89144db --- /dev/null +++ b/version @@ -0,0 +1 @@ +1.22.3