diff --git a/docker-compose.rc.yml b/docker-compose.rc.yml index 7cfb3a52..ed93e464 100644 --- a/docker-compose.rc.yml +++ b/docker-compose.rc.yml @@ -6,8 +6,8 @@ services: image: traefik:v2.6 restart: always ports: - - 80:80 - - 8080:8080 + - ${NGINX_PORT}:80 + - ${PROXY_PORT}:8080 command: --api.insecure=true --providers.docker volumes: - /var/run/docker.sock:/var/run/docker.sock:ro diff --git a/docker-compose.yml b/docker-compose.yml index 99622c80..42e98e43 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,8 +6,8 @@ services: image: traefik:v2.6 restart: always ports: - - 80:80 - - 8080:8080 + - ${NGINX_PORT}:80 + - ${PROXY_PORT}:8080 command: --api.insecure=true --providers.docker volumes: - /var/run/docker.sock:/var/run/docker.sock:ro @@ -15,7 +15,6 @@ services: networks: - tipi_main_network - api: image: meienberger/tipi-api:${TIPI_VERSION} container_name: api diff --git a/scripts/app.sh b/scripts/app.sh index 055d70e9..dbb01911 100755 --- a/scripts/app.sh +++ b/scripts/app.sh @@ -12,7 +12,7 @@ ROOT_FOLDER="$($rdlk -f $(dirname "${BASH_SOURCE[0]}")/..)" STATE_FOLDER="${ROOT_FOLDER}/state" show_help() { - cat << EOF + cat < /dev/null + echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list >/dev/null fi # Add deb repo for docker (Ubuntu) if [[ "${LSB}" == "Ubuntu" ]]; then - echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null + echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list >/dev/null fi sudo apt-get update sudo apt-get install -y docker-ce docker-ce-cli containerd.io # Install docker compose if not here -if ! command -v docker-compose > /dev/null; then +if ! command -v docker-compose >/dev/null; then sudo curl -L "https://github.com/docker/compose/releases/download/v2.3.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose fi # create docker group -if ! getent group docker > /dev/null; then +if ! getent group docker >/dev/null; then sudo groupadd docker fi sudo usermod -aG docker "${USERNAME}" @@ -65,4 +65,4 @@ sudo usermod -aG docker "${USERNAME}" # find "$ROOT_FOLDER" -path "$ROOT_FOLDER/app-data" -prune -o -exec chown 1000:1000 {} + || true # Create configured status -touch "${ROOT_FOLDER}/state/configured" \ No newline at end of file +touch "${ROOT_FOLDER}/state/configured" diff --git a/scripts/start.sh b/scripts/start.sh index fb04a602..7bd88bb7 100755 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -e # Exit immediately if a command exits with a non-zero status. +set -e # Exit immediately if a command exits with a non-zero status. # use greadlink instead of readlink on osx if [[ "$(uname)" == "Darwin" ]]; then @@ -8,18 +8,42 @@ else readlink=readlink fi -while [ -n "$1" ]; do # while loop starts +NGINX_PORT=80 +PROXY_PORT=8080 - case "$1" in - --rc) rc="true" ;; - --ci) ci="true" ;; - --) - shift # The double dash makes them parameters - break - ;; - *) echo "Option $1 not recognized" && exit 1 ;; - esac - shift +while [ -n "$1" ]; do # while loop starts + case "$1" in + --rc) rc="true" ;; + --ci) ci="true" ;; + --port) + port="$2" + + if [[ "${port}" =~ ^[0-9]+$ ]]; then + NGINX_PORT="${port}" + else + echo "--port must be a number" + exit 1 + fi + shift + ;; + --proxy-port) + proxy_port="$2" + + if [[ "${proxy_port}" =~ ^[0-9]+$ ]]; then + PROXY_PORT="${proxy_port}" + else + echo "--proxy-port must be a number" + exit 1 + fi + shift + ;; + --) + shift # The double dash makes them parameters + break + ;; + *) echo "Option $1 not recognized" && exit 1 ;; + esac + shift done # Check we are on linux @@ -40,10 +64,10 @@ if [[ "$ARCHITECTURE" == "aarch64" ]]; then fi if [[ $UID != 0 ]]; then - echo "Tipi must be started as root" - echo "Please re-run this script as" - echo " sudo ./scripts/start" - exit 1 + echo "Tipi must be started as root" + echo "Please re-run this script as" + echo " sudo ./scripts/start" + exit 1 fi # Configure Tipi if it isn't already configured @@ -53,20 +77,20 @@ fi # Get field from json file function get_json_field() { - local json_file="$1" - local field="$2" + local json_file="$1" + local field="$2" - echo $(jq -r ".${field}" "${json_file}") + echo $(jq -r ".${field}" "${json_file}") } # Deterministically derives 128 bits of cryptographically secure entropy function derive_entropy() { SEED_FILE="${STATE_FOLDER}/seed" identifier="${1}" - tipi_seed=$(cat "${SEED_FILE}") || true + tipi_seed=$(cat "${SEED_FILE}") || true if [[ -z "$tipi_seed" ]] || [[ -z "$identifier" ]]; then - >&2 echo "Missing derivation parameter, this is unsafe, exiting." + echo >&2 "Missing derivation parameter, this is unsafe, exiting." exit 1 fi @@ -107,7 +131,7 @@ fi # Create seed file with cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1 if [[ ! -f "${STATE_FOLDER}/seed" ]]; then echo "Generating seed..." - cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1 > "${STATE_FOLDER}/seed" + cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1 >"${STATE_FOLDER}/seed" fi export DOCKER_CLIENT_TIMEOUT=240 @@ -136,7 +160,8 @@ for template in "${ENV_FILE}"; do sed -i "s//${SED_ROOT_FOLDER}/g" "${template}" sed -i "s//$(cat "${ROOT_FOLDER}/VERSION")/g" "${template}" sed -i "s//${ARCHITECTURE}/g" "${template}" - + sed -i "//${NGINX_PORT}" "${template}" + sed -i "//${PROXY_PORT}" "${template}" done mv -f "$ENV_FILE" "$ROOT_FOLDER/.env" @@ -170,7 +195,7 @@ fi echo "Tipi is now running" echo "" -cat << "EOF" +cat <<"EOF" _,. ,` -.) '( _/'-\\-. @@ -195,5 +220,3 @@ EOF echo "" echo "Visit http://${INTERNAL_IP}/ to view the dashboard" echo "" - - diff --git a/scripts/stop.sh b/scripts/stop.sh index e76c285b..f43a6fcb 100755 --- a/scripts/stop.sh +++ b/scripts/stop.sh @@ -8,12 +8,11 @@ else readlink=readlink fi - if [[ $UID != 0 ]]; then - echo "Tipi must be stopped as root" - echo "Please re-run this script as" - echo " sudo ./scripts/stop" - exit 1 + echo "Tipi must be stopped as root" + echo "Please re-run this script as" + echo " sudo ./scripts/stop" + exit 1 fi ROOT_FOLDER="$($readlink -f $(dirname "${BASH_SOURCE[0]}")/..)" @@ -27,10 +26,10 @@ export DOCKER_CLIENT_TIMEOUT=240 export COMPOSE_HTTP_TIMEOUT=240 function get_json_field() { - local json_file="$1" - local field="$2" + local json_file="$1" + local field="$2" - echo $(jq -r ".${field}" "${json_file}") + echo $(jq -r ".${field}" "${json_file}") } str=$(get_json_field ${STATE_FOLDER}/apps.json installed) @@ -38,11 +37,11 @@ apps_to_start=($str) # If apps_to_start is not empty, then we're stopping all apps if [[ ${#apps_to_start[@]} -gt 0 ]]; then - for app in "${apps_to_start[@]}"; do - "${ROOT_FOLDER}/scripts/app.sh" stop $app - done + for app in "${apps_to_start[@]}"; do + "${ROOT_FOLDER}/scripts/app.sh" stop $app + done fi echo "Stopping Docker services..." echo -docker-compose down --remove-orphans --rmi local \ No newline at end of file +docker-compose down --remove-orphans --rmi local diff --git a/scripts/system-info.sh b/scripts/system-info.sh index 5d8737d4..28ee1158 100755 --- a/scripts/system-info.sh +++ b/scripts/system-info.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -e # Exit immediately if a command exits with a non-zero status. +set -e # Exit immediately if a command exits with a non-zero status. ROOT_FOLDER="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/..)" STATE_FOLDER="${ROOT_FOLDER}/state" @@ -19,7 +19,7 @@ MEM_USED_BYTES=$(($MEM_TOTAL_BYTES - $MEM_AVAILABLE_BYTES)) # Create temporary json file TEMP_JSON_FILE=$(mktemp) -echo '{ "cpu": { "load": '"${CPU_LOAD_PERCENTAGE}"' }, "memory": { "total": '"${MEM_TOTAL_BYTES}"' , "used": '"${MEM_USED_BYTES}"', "available": '"${MEM_AVAILABLE_BYTES}"' }, "disk": { "total": '"${TOTAL_DISK_SPACE_BYTES}"' , "used": '"${USED_DISK_SPACE_BYTES}"', "available": '"${AVAILABLE_DISK_SPACE_BYTES}"' } }' > "${TEMP_JSON_FILE}" +echo '{ "cpu": { "load": '"${CPU_LOAD_PERCENTAGE}"' }, "memory": { "total": '"${MEM_TOTAL_BYTES}"' , "used": '"${MEM_USED_BYTES}"', "available": '"${MEM_AVAILABLE_BYTES}"' }, "disk": { "total": '"${TOTAL_DISK_SPACE_BYTES}"' , "used": '"${USED_DISK_SPACE_BYTES}"', "available": '"${AVAILABLE_DISK_SPACE_BYTES}"' } }' >"${TEMP_JSON_FILE}" # Write to state file -echo "$(cat "${TEMP_JSON_FILE}")" > "${STATE_FOLDER}/system-info.json" +echo "$(cat "${TEMP_JSON_FILE}")" >"${STATE_FOLDER}/system-info.json" diff --git a/templates/env-sample b/templates/env-sample index 2441dd7c..4aa5e58c 100644 --- a/templates/env-sample +++ b/templates/env-sample @@ -10,3 +10,5 @@ ARCHITECTURE= TIPI_VERSION= JWT_SECRET= ROOT_FOLDER_HOST= +NGINX_PORT= +PROXY_PORT= \ No newline at end of file