Browse Source

Allow custom port

Nicolas Meienberger 3 years ago
parent
commit
287999caca
8 changed files with 81 additions and 58 deletions
  1. 2 2
      docker-compose.rc.yml
  2. 2 3
      docker-compose.yml
  3. 6 6
      scripts/app.sh
  4. 6 6
      scripts/configure.sh
  5. 49 26
      scripts/start.sh
  6. 11 12
      scripts/stop.sh
  7. 3 3
      scripts/system-info.sh
  8. 2 0
      templates/env-sample

+ 2 - 2
docker-compose.rc.yml

@@ -6,8 +6,8 @@ services:
     image: traefik:v2.6
     image: traefik:v2.6
     restart: always
     restart: always
     ports:
     ports:
-      - 80:80
-      - 8080:8080
+      - ${NGINX_PORT}:80
+      - ${PROXY_PORT}:8080
     command: --api.insecure=true --providers.docker
     command: --api.insecure=true --providers.docker
     volumes:
     volumes:
       - /var/run/docker.sock:/var/run/docker.sock:ro
       - /var/run/docker.sock:/var/run/docker.sock:ro

+ 2 - 3
docker-compose.yml

@@ -6,8 +6,8 @@ services:
     image: traefik:v2.6
     image: traefik:v2.6
     restart: always
     restart: always
     ports:
     ports:
-      - 80:80
-      - 8080:8080
+      - ${NGINX_PORT}:80
+      - ${PROXY_PORT}:8080
     command: --api.insecure=true --providers.docker
     command: --api.insecure=true --providers.docker
     volumes:
     volumes:
       - /var/run/docker.sock:/var/run/docker.sock:ro
       - /var/run/docker.sock:/var/run/docker.sock:ro
@@ -15,7 +15,6 @@ services:
     networks:
     networks:
       - tipi_main_network
       - tipi_main_network
 
 
-  
   api:
   api:
     image: meienberger/tipi-api:${TIPI_VERSION}
     image: meienberger/tipi-api:${TIPI_VERSION}
     container_name: api
     container_name: api

+ 6 - 6
scripts/app.sh

@@ -12,7 +12,7 @@ ROOT_FOLDER="$($rdlk -f $(dirname "${BASH_SOURCE[0]}")/..)"
 STATE_FOLDER="${ROOT_FOLDER}/state"
 STATE_FOLDER="${ROOT_FOLDER}/state"
 
 
 show_help() {
 show_help() {
-  cat << EOF
+  cat <<EOF
 app 0.0.1
 app 0.0.1
 
 
 CLI for managing Tipi apps
 CLI for managing Tipi apps
@@ -31,10 +31,10 @@ EOF
 
 
 # Get field from json file
 # Get field from json file
 function get_json_field() {
 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}")
 }
 }
 
 
 list_installed_apps() {
 list_installed_apps() {
@@ -98,7 +98,7 @@ compose() {
   # Pick arm architecture if running on arm and if the app has a docker-compose.arm.yml file
   # Pick arm architecture if running on arm and if the app has a docker-compose.arm.yml file
   if [[ "$architecture" == "arm"* ]] && [[ -f "${app_dir}/docker-compose.arm.yml" ]]; then
   if [[ "$architecture" == "arm"* ]] && [[ -f "${app_dir}/docker-compose.arm.yml" ]]; then
     app_compose_file="${app_dir}/docker-compose.arm.yml"
     app_compose_file="${app_dir}/docker-compose.arm.yml"
-  fi  
+  fi
 
 
   local common_compose_file="${ROOT_FOLDER}/apps/docker-compose.common.yml"
   local common_compose_file="${ROOT_FOLDER}/apps/docker-compose.common.yml"
   local app_dir="${ROOT_FOLDER}/apps/${app}"
   local app_dir="${ROOT_FOLDER}/apps/${app}"
@@ -183,4 +183,4 @@ fi
 # If we get here it means no valid command was supplied
 # If we get here it means no valid command was supplied
 # Show help and exit
 # Show help and exit
 show_help
 show_help
-exit 1
+exit 1

+ 6 - 6
scripts/configure.sh

@@ -1,5 +1,5 @@
 #!/usr/bin/env bash
 #!/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]}")/..)"
 ROOT_FOLDER="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/..)"
 USERNAME="$(id -nu 1000)"
 USERNAME="$(id -nu 1000)"
@@ -37,25 +37,25 @@ fi
 
 
 # Add deb repo for docker (Debian)
 # Add deb repo for docker (Debian)
 if [[ "${LSB}" == "Debian" ]]; then
 if [[ "${LSB}" == "Debian" ]]; then
-  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
+  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
 fi
 
 
 # Add deb repo for docker (Ubuntu)
 # Add deb repo for docker (Ubuntu)
 if [[ "${LSB}" == "Ubuntu" ]]; then
 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
 fi
 
 
 sudo apt-get update
 sudo apt-get update
 sudo apt-get install -y docker-ce docker-ce-cli containerd.io
 sudo apt-get install -y docker-ce docker-ce-cli containerd.io
 
 
 # Install docker compose if not here
 # 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 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
   sudo chmod +x /usr/local/bin/docker-compose
 fi
 fi
 
 
 # create docker group
 # create docker group
-if ! getent group docker > /dev/null; then
+if ! getent group docker >/dev/null; then
   sudo groupadd docker
   sudo groupadd docker
 fi
 fi
 sudo usermod -aG docker "${USERNAME}"
 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
 # find "$ROOT_FOLDER" -path "$ROOT_FOLDER/app-data" -prune -o -exec chown 1000:1000 {} + || true
 
 
 # Create configured status
 # Create configured status
-touch "${ROOT_FOLDER}/state/configured"
+touch "${ROOT_FOLDER}/state/configured"

+ 49 - 26
scripts/start.sh

@@ -1,5 +1,5 @@
 #!/usr/bin/env bash
 #!/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
 # use greadlink instead of readlink on osx
 if [[ "$(uname)" == "Darwin" ]]; then
 if [[ "$(uname)" == "Darwin" ]]; then
@@ -8,18 +8,42 @@ else
   readlink=readlink
   readlink=readlink
 fi
 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
 done
 
 
 # Check we are on linux
 # Check we are on linux
@@ -40,10 +64,10 @@ if [[ "$ARCHITECTURE" == "aarch64" ]]; then
 fi
 fi
 
 
 if [[ $UID != 0 ]]; then
 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
 fi
 
 
 # Configure Tipi if it isn't already configured
 # Configure Tipi if it isn't already configured
@@ -53,20 +77,20 @@ fi
 
 
 # Get field from json file
 # Get field from json file
 function get_json_field() {
 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
 # Deterministically derives 128 bits of cryptographically secure entropy
 function derive_entropy() {
 function derive_entropy() {
   SEED_FILE="${STATE_FOLDER}/seed"
   SEED_FILE="${STATE_FOLDER}/seed"
   identifier="${1}"
   identifier="${1}"
-  tipi_seed=$(cat "${SEED_FILE}") || true 
+  tipi_seed=$(cat "${SEED_FILE}") || true
 
 
   if [[ -z "$tipi_seed" ]] || [[ -z "$identifier" ]]; then
   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
     exit 1
   fi
   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
 # 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
 if [[ ! -f "${STATE_FOLDER}/seed" ]]; then
   echo "Generating seed..."
   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
 fi
 
 
 export DOCKER_CLIENT_TIMEOUT=240
 export DOCKER_CLIENT_TIMEOUT=240
@@ -136,7 +160,8 @@ for template in "${ENV_FILE}"; do
   sed -i "s/<root_folder>/${SED_ROOT_FOLDER}/g" "${template}"
   sed -i "s/<root_folder>/${SED_ROOT_FOLDER}/g" "${template}"
   sed -i "s/<tipi_version>/$(cat "${ROOT_FOLDER}/VERSION")/g" "${template}"
   sed -i "s/<tipi_version>/$(cat "${ROOT_FOLDER}/VERSION")/g" "${template}"
   sed -i "s/<architecture>/${ARCHITECTURE}/g" "${template}"
   sed -i "s/<architecture>/${ARCHITECTURE}/g" "${template}"
-
+  sed -i "/<nginx_port>/${NGINX_PORT}" "${template}"
+  sed -i "/<proxy_port>/${PROXY_PORT}" "${template}"
 done
 done
 
 
 mv -f "$ENV_FILE" "$ROOT_FOLDER/.env"
 mv -f "$ENV_FILE" "$ROOT_FOLDER/.env"
@@ -170,7 +195,7 @@ fi
 
 
 echo "Tipi is now running"
 echo "Tipi is now running"
 echo ""
 echo ""
-cat << "EOF"
+cat <<"EOF"
        _,.
        _,.
      ,` -.)
      ,` -.)
     '( _/'-\\-.               
     '( _/'-\\-.               
@@ -195,5 +220,3 @@ EOF
 echo ""
 echo ""
 echo "Visit http://${INTERNAL_IP}/ to view the dashboard"
 echo "Visit http://${INTERNAL_IP}/ to view the dashboard"
 echo ""
 echo ""
-
-

+ 11 - 12
scripts/stop.sh

@@ -8,12 +8,11 @@ else
   readlink=readlink
   readlink=readlink
 fi
 fi
 
 
-
 if [[ $UID != 0 ]]; then
 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
 fi
 
 
 ROOT_FOLDER="$($readlink -f $(dirname "${BASH_SOURCE[0]}")/..)"
 ROOT_FOLDER="$($readlink -f $(dirname "${BASH_SOURCE[0]}")/..)"
@@ -27,10 +26,10 @@ export DOCKER_CLIENT_TIMEOUT=240
 export COMPOSE_HTTP_TIMEOUT=240
 export COMPOSE_HTTP_TIMEOUT=240
 
 
 function get_json_field() {
 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)
 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 is not empty, then we're stopping all apps
 if [[ ${#apps_to_start[@]} -gt 0 ]]; then
 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
 fi
 
 
 echo "Stopping Docker services..."
 echo "Stopping Docker services..."
 echo
 echo
-docker-compose down --remove-orphans --rmi local
+docker-compose down --remove-orphans --rmi local

+ 3 - 3
scripts/system-info.sh

@@ -1,5 +1,5 @@
 #!/usr/bin/env bash
 #!/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]}")/..)"
 ROOT_FOLDER="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/..)"
 STATE_FOLDER="${ROOT_FOLDER}/state"
 STATE_FOLDER="${ROOT_FOLDER}/state"
@@ -19,7 +19,7 @@ MEM_USED_BYTES=$(($MEM_TOTAL_BYTES - $MEM_AVAILABLE_BYTES))
 
 
 # Create temporary json file
 # Create temporary json file
 TEMP_JSON_FILE=$(mktemp)
 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
 # Write to state file
-echo "$(cat "${TEMP_JSON_FILE}")" > "${STATE_FOLDER}/system-info.json"
+echo "$(cat "${TEMP_JSON_FILE}")" >"${STATE_FOLDER}/system-info.json"

+ 2 - 0
templates/env-sample

@@ -10,3 +10,5 @@ ARCHITECTURE=<architecture>
 TIPI_VERSION=<tipi_version>
 TIPI_VERSION=<tipi_version>
 JWT_SECRET=<jwt_secret>
 JWT_SECRET=<jwt_secret>
 ROOT_FOLDER_HOST=<root_folder>
 ROOT_FOLDER_HOST=<root_folder>
+NGINX_PORT=<nginx_port>
+PROXY_PORT=<proxy_port>