froxlor/froxlor.sh hinzugefügt
This commit is contained in:
263
froxlor/froxlor.sh
Normal file
263
froxlor/froxlor.sh
Normal file
@@ -0,0 +1,263 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
#
|
||||||
|
# Froxlor for Linux installation script
|
||||||
|
#
|
||||||
|
# !!! EXPERIMENTAL VERSION AHEAD !!!
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
# This script is meant for quick & easy install via:
|
||||||
|
# $ curl -fsSL https://get.froxlor.dev | sudo bash
|
||||||
|
#
|
||||||
|
|
||||||
|
SCRIPT_VERSION="develop"
|
||||||
|
|
||||||
|
source /etc/os-release
|
||||||
|
|
||||||
|
# test if the terminal supports colors
|
||||||
|
if test -t 1; then
|
||||||
|
ncolors=$(which tput >/dev/null && tput colors)
|
||||||
|
if test -n "$ncolors" && test "$ncolors" -ge 8; then
|
||||||
|
termcols=$(tput cols)
|
||||||
|
bold="$(tput bold)"
|
||||||
|
underline="$(tput smul)"
|
||||||
|
standout="$(tput smso)"
|
||||||
|
normal="$(tput sgr0)"
|
||||||
|
black="$(tput setaf 0)"
|
||||||
|
red="$(tput setaf 1)"
|
||||||
|
green="$(tput setaf 2)"
|
||||||
|
yellow="$(tput setaf 3)"
|
||||||
|
blue="$(tput setaf 4)"
|
||||||
|
magenta="$(tput setaf 5)"
|
||||||
|
cyan="$(tput setaf 6)"
|
||||||
|
white="$(tput setaf 7)"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
#
|
||||||
|
# The main installation script
|
||||||
|
#
|
||||||
|
do_install() {
|
||||||
|
# Root Check
|
||||||
|
if [ "$EUID" -ne 0 ]; then
|
||||||
|
alert "Please run as root (e.g. with sudo)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
LOG_FILE="/var/log/froxlor-install.log"
|
||||||
|
INSTALL_DIR="/opt/froxlor"
|
||||||
|
COMPOSE_FILE="$INSTALL_DIR/docker-compose.yml"
|
||||||
|
ENV_FILE="$INSTALL_DIR/froxlor.env"
|
||||||
|
|
||||||
|
mkdir -p /var/log
|
||||||
|
touch "$LOG_FILE"
|
||||||
|
|
||||||
|
# Logging
|
||||||
|
exec > >(tee -a "$LOG_FILE") 2>&1
|
||||||
|
|
||||||
|
intro
|
||||||
|
echo
|
||||||
|
step "Installation started at $(date)"
|
||||||
|
|
||||||
|
# Prerequisites
|
||||||
|
step "Checking prerequisites"
|
||||||
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
|
# Server IP
|
||||||
|
while [[ -z $serveripv4 ]]; do
|
||||||
|
serveripv4="$(curl -fsSL4 https://get.froxlor.org/ip.php)"
|
||||||
|
if [[ $noninteractive == 0 ]]; then
|
||||||
|
read -r -e -p " Enter the public server IPv4: " -i "$serveripv4" serveripv4 </dev/tty
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Check Docker
|
||||||
|
if ! command -v docker &> /dev/null; then
|
||||||
|
run_with_spinner "Installing Docker" bash -c "curl -fsSL https://get.docker.com | sh >>\"$LOG_FILE\" 2>&1"
|
||||||
|
else
|
||||||
|
step "Docker already installed"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create directory
|
||||||
|
step "Create directory $INSTALL_DIR"
|
||||||
|
mkdir -p "$INSTALL_DIR"
|
||||||
|
|
||||||
|
# Environment file
|
||||||
|
if [ ! -f "$ENV_FILE" ]; then
|
||||||
|
step "Create froxlor environment file $ENV_FILE"
|
||||||
|
MYSQL_PASSWORD=$(openssl rand -base64 16)
|
||||||
|
cat > "$ENV_FILE" <<EOF
|
||||||
|
# Froxlor App ENV
|
||||||
|
MYSQL_HOST=db
|
||||||
|
MYSQL_DATABASE=froxlor
|
||||||
|
MYSQL_USER=froxlor
|
||||||
|
MYSQL_PASSWORD=$MYSQL_PASSWORD
|
||||||
|
EOF
|
||||||
|
else
|
||||||
|
warn "$ENV_FILE already existing, skip"
|
||||||
|
MYSQL_PASSWORD=$(grep MYSQL_PASSWORD "$ENV_FILE" | cut -d '=' -f2)
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Docker compose file
|
||||||
|
if [ ! -f "$COMPOSE_FILE" ]; then
|
||||||
|
step "Create docker-compose.yml"
|
||||||
|
DB_ROOT_PASSWORD=$(openssl rand -base64 16)
|
||||||
|
cat > "$COMPOSE_FILE" <<EOF
|
||||||
|
services:
|
||||||
|
db:
|
||||||
|
image: mariadb:10.11
|
||||||
|
container_name: froxlor_db
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
MYSQL_ROOT_PASSWORD: $DB_ROOT_PASSWORD
|
||||||
|
MYSQL_DATABASE: froxlor
|
||||||
|
MYSQL_USER: froxlor
|
||||||
|
MYSQL_PASSWORD: $MYSQL_PASSWORD
|
||||||
|
volumes:
|
||||||
|
- db_data:/var/lib/mysql
|
||||||
|
|
||||||
|
froxlor:
|
||||||
|
image: hub.froxlor.io/froxlor/froxlor:latest
|
||||||
|
container_name: froxlor_app
|
||||||
|
restart: unless-stopped
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
env_file:
|
||||||
|
- froxlor.env
|
||||||
|
volumes:
|
||||||
|
- froxlor_data:/var/www/html
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
db_data:
|
||||||
|
froxlor_data:
|
||||||
|
EOF
|
||||||
|
else
|
||||||
|
warn "$COMPOSE_FILE already existing, skip"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Start container
|
||||||
|
cd "$INSTALL_DIR"
|
||||||
|
run_with_spinner "Starting container" bash -c "docker compose up -d >>\"$LOG_FILE\" 2>&1"
|
||||||
|
|
||||||
|
finish "root" "$ENV_FILE" "$LOG_FILE" "$serveripv4"
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Helper functions
|
||||||
|
#
|
||||||
|
step() {
|
||||||
|
printf "${green}\r [i] ${normal}${1}${normal}"
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
warn() {
|
||||||
|
printf "${yellow}\r [i] ${normal}${1}${normal}"
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
run_with_spinner() {
|
||||||
|
local msg="$1"
|
||||||
|
shift
|
||||||
|
local cmd=("$@")
|
||||||
|
|
||||||
|
# Start command in background
|
||||||
|
"${cmd[@]}" &
|
||||||
|
local pid=$!
|
||||||
|
|
||||||
|
# Spinner chars
|
||||||
|
local spinner=('|' '/' '-' '\')
|
||||||
|
local i=0
|
||||||
|
|
||||||
|
# Display spinner until process is done
|
||||||
|
printf "${green} [i] ${normal}%s " "$msg "
|
||||||
|
while kill -0 "$pid" 2>/dev/null; do
|
||||||
|
printf "\b%s" "${spinner[i]}"
|
||||||
|
i=$(( (i+1) % 4 ))
|
||||||
|
sleep 0.1
|
||||||
|
done
|
||||||
|
|
||||||
|
wait "$pid"
|
||||||
|
local status=$?
|
||||||
|
|
||||||
|
# Finish line
|
||||||
|
if [ $status -eq 0 ]; then
|
||||||
|
printf "\b${green}Done!${normal}\n"
|
||||||
|
step "$msg completed"
|
||||||
|
else
|
||||||
|
printf "\b${red}Error!${normal}\n"
|
||||||
|
echo "${red}Command failed: ${cmd[*]}${normal}"
|
||||||
|
exit $status
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
intro() {
|
||||||
|
echo
|
||||||
|
echo "${green}================================================================================${normal}"
|
||||||
|
echo -e " ${bold}${green} __ _ ${normal}"
|
||||||
|
echo -e " ${bold}${green} / _|_ __ _____ _| | ___ _ __ ${normal}"
|
||||||
|
echo -e " ${bold}${green}| |_| '__/ _ \ \/ / |/ _ \| '__|${normal}"
|
||||||
|
echo -e " ${bold}${green}| _| | | (_) > <| | (_) | | ${normal}"
|
||||||
|
echo -e " ${bold}${green}|_| |_| \___/_/\_\_|\___/|_| ${normal}"
|
||||||
|
echo
|
||||||
|
echo -e " ${bold}${green}Welcome to the froxlor for Linux installation script ($SCRIPT_VERSION)${normal}"
|
||||||
|
echo
|
||||||
|
echo -e " We guide you through the installation steps and setup your system :)"
|
||||||
|
echo
|
||||||
|
if [[ $noninteractive == 1 ]]; then
|
||||||
|
echo -e " ${bold}${green}Running in noninteractive mode. ${normal}"
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
echo "${green}================================================================================${normal}"
|
||||||
|
}
|
||||||
|
|
||||||
|
alert() {
|
||||||
|
echo
|
||||||
|
echo "${red}================================================================================${normal}"
|
||||||
|
echo
|
||||||
|
echo -e " ${bold}${yellow}${1}${normal}"
|
||||||
|
echo
|
||||||
|
echo -e " ${2}"
|
||||||
|
echo
|
||||||
|
echo "${red}================================================================================${normal}"
|
||||||
|
}
|
||||||
|
|
||||||
|
section() {
|
||||||
|
echo
|
||||||
|
echo "${white}================================================================================${normal}"
|
||||||
|
echo
|
||||||
|
echo -e " ${bold}${white}${1}${normal}"
|
||||||
|
echo
|
||||||
|
echo "${white}================================================================================${normal}"
|
||||||
|
}
|
||||||
|
|
||||||
|
finish() {
|
||||||
|
echo
|
||||||
|
echo "${green}================================================================================${normal}"
|
||||||
|
echo
|
||||||
|
echo -e " ${bold}${green}The installation of froxlor was successful!${normal}"
|
||||||
|
echo
|
||||||
|
echo -e " ${bold}${green}Your environment variables are stored in: ${2}${normal}"
|
||||||
|
echo -e " ${bold}${green}Log file is stored in: ${3}${normal}"
|
||||||
|
echo
|
||||||
|
echo -e " ${bold}${green}You can enter http://${4}:8000 to access your panel!${normal}"
|
||||||
|
echo
|
||||||
|
echo "${green}================================================================================${normal}"
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Call the installer at the end of the script, so we make sure all functions
|
||||||
|
# are defined and not got cut off by curl, wget or something else...
|
||||||
|
#
|
||||||
|
do_install
|
||||||
Reference in New Issue
Block a user