Browse Source

Fix: Username detection

Nicolas Meienberger 3 years ago
parent
commit
8d19e1f5ed
3 changed files with 10 additions and 5 deletions
  1. 1 1
      ansible/tasks/common/essential.yml
  2. 2 1
      scripts/configure.sh
  3. 7 3
      scripts/start.sh

+ 1 - 1
ansible/tasks/common/essential.yml

@@ -26,7 +26,7 @@
 #     line: "PasswordAuthentication no"
 #     line: "PasswordAuthentication no"
 #   register: sshd_config
 #   register: sshd_config
 
 
-- name: Enable passwordless sudo for user
+- name: "Enable passwordless sudo for {{ username }}"
   lineinfile:
   lineinfile:
     dest: /etc/sudoers
     dest: /etc/sudoers
     regexp: "^%wheel"
     regexp: "^%wheel"

+ 2 - 1
scripts/configure.sh

@@ -2,6 +2,7 @@
 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)"
 
 
 echo
 echo
 echo "======================================"
 echo "======================================"
@@ -24,7 +25,7 @@ fi
 
 
 
 
 
 
-ansible-playbook ansible/setup.yml -i ansible/hosts -K -e username="$USER"
+ansible-playbook ansible/setup.yml -i ansible/hosts -K -e username="$USERNAME"
 
 
 # echo "Configuring permissions..."
 # echo "Configuring permissions..."
 # echo
 # echo

+ 7 - 3
scripts/start.sh

@@ -13,6 +13,7 @@ STATE_FOLDER="${ROOT_FOLDER}/state"
 SED_ROOT_FOLDER="$(echo $ROOT_FOLDER | sed 's/\//\\\//g')"
 SED_ROOT_FOLDER="$(echo $ROOT_FOLDER | sed 's/\//\\\//g')"
 INTERNAL_IP="$(hostname -I | awk '{print $1}')"
 INTERNAL_IP="$(hostname -I | awk '{print $1}')"
 DNS_IP=9.9.9.9 # Default to Quad9 DNS
 DNS_IP=9.9.9.9 # Default to Quad9 DNS
+USERNAME="$(id -nu 1000)"
 
 
 if [[ $UID != 0 ]]; then
 if [[ $UID != 0 ]]; then
     echo "Tipi must be started as root"
     echo "Tipi must be started as root"
@@ -65,14 +66,17 @@ TZ="$(cat /etc/timezone | sed 's/\//\\\//g' || echo "Europe/Berlin")"
 
 
 # Copy the app state if it isn't here
 # Copy the app state if it isn't here
 if [[ ! -f "${STATE_FOLDER}/apps.json" ]]; then
 if [[ ! -f "${STATE_FOLDER}/apps.json" ]]; then
-  cp "${ROOT_FOLDER}/templates/apps-sample.json" "${STATE_FOLDER}/apps.json" && chown -R "1000:1000" "${STATE_FOLDER}/apps.json"
+  cp "${ROOT_FOLDER}/templates/apps-sample.json" "${STATE_FOLDER}/apps.json"
 fi
 fi
 
 
 # Copy the user state if it isn't here
 # Copy the user state if it isn't here
 if [[ ! -f "${STATE_FOLDER}/users.json" ]]; then
 if [[ ! -f "${STATE_FOLDER}/users.json" ]]; then
-  cp "${ROOT_FOLDER}/templates/users-sample.json" "${STATE_FOLDER}/users.json" && chown -R "1000:1000" "${STATE_FOLDER}/users.json"
+  cp "${ROOT_FOLDER}/templates/users-sample.json" "${STATE_FOLDER}/users.json"
 fi
 fi
 
 
+chown -R 1000:1000 "${STATE_FOLDER}/apps.json"
+chown -R 1000:1000 "${STATE_FOLDER}/users.json"
+
 # 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..."
@@ -114,7 +118,7 @@ done
 mv -f "$ENV_FILE" "$ROOT_FOLDER/.env"
 mv -f "$ENV_FILE" "$ROOT_FOLDER/.env"
 mv -f "$ENV_FILE_SYSTEM_API" "$ROOT_FOLDER/packages/system-api/.env"
 mv -f "$ENV_FILE_SYSTEM_API" "$ROOT_FOLDER/packages/system-api/.env"
 
 
-ansible-playbook ansible/start.yml -i ansible/hosts -K -e username="$USER"
+ansible-playbook ansible/start.yml -i ansible/hosts -K -e username="$USERNAME"
 
 
 # Run docker-compose
 # Run docker-compose
 docker-compose --env-file "${ROOT_FOLDER}/.env" up --detach --remove-orphans --build || {
 docker-compose --env-file "${ROOT_FOLDER}/.env" up --detach --remove-orphans --build || {