#!/bin/bash ######################################################################################################## # First Created: 14072023 Author: Allan Desc: Installs Focalboard 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="focalboard-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"; } latest=$(curl -s https://github.com/mattermost/focalboard/tags > version) version=$(grep "/mattermost/focalboard/releases/tag/" version |head -n1 |awk -F '/' '{print $6}' |sed 's/\".*//') configfile="/usr/local/bin/focalboard/config.json" nginxfiles="/etc/nginx/nginxsnippets" # # Function title # title () { printf "\nFocalboard install script V1.0\n\n"; } # # Function usage # usage () { clear ; printf -- "\n" printf -- "${bold}focalboardinstall${normal} \n\n" printf -- "${bold}Usage:${normal} \n" printf -- "./focalboardinstall [-n] \n" printf -- " [-d] \n" printf -- " [-u] \n" printf -- " [-p] \n" printf -- " [-help] \n\n" printf -- "${bold}Examples:${normal} \n" printf -- "./focalboardinstall -n focal.something.xyz -d focaldb -u focaluser -p focalpwd \n\n"; } # # Function installation check for success # 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 "$fcdbname" ]]; then usage ; printf "${bold}Error! ${normal}Database name Empty...\n\n" ; exit; fi if [[ -z "$fcdbuser" ]]; then usage ; printf "${bold}Error! ${normal}Database username Empty...\n\n" ; exit; fi if [[ -z "$fcdbpass" ]]; 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:d:u:p:h:" option; do case $option in n) # hostname hostname=$(echo ${OPTARG} | tr '[:upper:]' '[:lower:]');; d) # focalboard database name fcdbname=$OPTARG;; u) # focalboard database user fcdbuser=$OPTARG;; p) # focalboard database password fcdbpass=$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 $wpdbname $wpdbuser $wpdbpass # # Download Focalboard # wget --no-verbose https://github.com/mattermost/focalboard/releases/download/$version/focalboard-server-linux-amd64.tar.gz # # Install and configure Focalboard # tar zxfp focalboard-server-linux-amd64.tar.gz chown -R root: focalboard && mv focalboard /usr/local/bin sed -s -i "s/sqlite3/mysql/" $configfile sed -s -i "s/.\/focalboard.db/focaluser:focalpwd@tcp\(127.0.0.1:3306\)\/focalboard/" $configfile # # # Check if nginxsnippets exist if not download them # if [[ ! -d "$nginxfiles" ]]; then git clone --quiet https://git.x-files.dk/ubuntu-server-files/nginxsnippets.git $nginxfiles; fi # # Create Focalboard database # fcsql=" connect mysql create database $fcdbname; CREATE USER '$fcdbuser'@'127.0.0.1' IDENTIFIED BY '$fcdbpass'; GRANT ALL PRIVILEGES ON $fcdbname.* TO '$fcdbuser'@'127.0.0.1'; FLUSH PRIVILEGES; " printf '%s\n' "${fcsql[@]}" |sed '1d; $d' > fcsql.sql mysql < fcsql.sql # # Create a Focalboard Nginx configuration file # curl --silent https://git.x-files.dk/ubuntu-server-files/nginx-config-examples/raw/branch/main/focalboard.80.conf > /etc/nginx/conf.d/$hostname.conf sed -s -i "s/DOMAIN/$hostname/g" /etc/nginx/conf.d/$hostname.conf # # Restarting Nginx and Phpfpm for changes to take effect # systemctl restart nginx && systemctl restart php8.1-fpm # # Create Focalboard systemd script # focalsystemd=" [Unit] Description=Focalboard server [Service] Type=simple Restart=always RestartSec=5s ExecStart=//usr/local/bin/focalboard/bin/focalboard-server WorkingDirectory=/usr/local/bin/focalboard [Install] WantedBy=multi-user.target " printf '%s\n' "${focalsystemd[@]}" |sed '1d; $d' > focalsystemd cat focalsystemd > /etc/systemd/system/focalboard.service # # Start Focalboard services # systemctl daemon-reload systemctl enable focalboard.service systemctl start focalboard.service # # Focalboard postinstall notice # focalboardnotice=" ------------------------------------------------------------------------------------------ IMPORTANT: Go to http://$hostname select create an account this will be the admin account. All other users are created by an invite link. There is no create user option. ------------------------------------------------------------------------------------------ " # # Display post install note # clear ; printf '%s\n' "${focalboardnotice[@]}" # # Cleaning up # rm -Rf fcsql.sql focalsystemd version nginx-config-examples *.gz # # End of script #