From 8d19e1f5ed8c78c4fd062c4d35533344b9ca82ab Mon Sep 17 00:00:00 2001 From: Nicolas Meienberger Date: Fri, 13 May 2022 17:59:49 +0200 Subject: [PATCH] Fix: Username detection --- ansible/tasks/common/essential.yml | 2 +- scripts/configure.sh | 3 ++- scripts/start.sh | 10 +++++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ansible/tasks/common/essential.yml b/ansible/tasks/common/essential.yml index 9a6fc6ef..6c1113a9 100644 --- a/ansible/tasks/common/essential.yml +++ b/ansible/tasks/common/essential.yml @@ -26,7 +26,7 @@ # line: "PasswordAuthentication no" # register: sshd_config -- name: Enable passwordless sudo for user +- name: "Enable passwordless sudo for {{ username }}" lineinfile: dest: /etc/sudoers regexp: "^%wheel" diff --git a/scripts/configure.sh b/scripts/configure.sh index b62fc894..278874bf 100755 --- a/scripts/configure.sh +++ b/scripts/configure.sh @@ -2,6 +2,7 @@ set -e # Exit immediately if a command exits with a non-zero status. ROOT_FOLDER="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/..)" +USERNAME="$(id -nu 1000)" 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 diff --git a/scripts/start.sh b/scripts/start.sh index 4b27dfd4..883d070c 100755 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -13,6 +13,7 @@ STATE_FOLDER="${ROOT_FOLDER}/state" SED_ROOT_FOLDER="$(echo $ROOT_FOLDER | sed 's/\//\\\//g')" INTERNAL_IP="$(hostname -I | awk '{print $1}')" DNS_IP=9.9.9.9 # Default to Quad9 DNS +USERNAME="$(id -nu 1000)" if [[ $UID != 0 ]]; then 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 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 # Copy the user state if it isn't here 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 +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 if [[ ! -f "${STATE_FOLDER}/seed" ]]; then echo "Generating seed..." @@ -114,7 +118,7 @@ done mv -f "$ENV_FILE" "$ROOT_FOLDER/.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 docker-compose --env-file "${ROOT_FOLDER}/.env" up --detach --remove-orphans --build || {