From 65a428ce59da6d10ebf0b73193786911b75ee004 Mon Sep 17 00:00:00 2001 From: vhaudiquet Date: Wed, 20 Aug 2025 17:33:29 +0200 Subject: [PATCH] Update user information order for non-root infos --- mymachine.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/mymachine.sh b/mymachine.sh index dfc0aad..d6b0bea 100755 --- a/mymachine.sh +++ b/mymachine.sh @@ -40,16 +40,6 @@ handle_int() { exit 1 } -# Make sure we are running as root -if [[ $EUID -ne 0 ]]; then - # If we are not running as root, try to relaunch ourselves as root - echo -e "${BNC}Testing root access...${NC}" - sudo bash -c "USERNAME=${USERNAME} GIT_USER=${GIT_USER} EMAIL=${EMAIL} USER_COMMENT=${USER_COMMENT} USER_PICTURE_URL=${USER_PICTURE_URL} PASSWORD=${PASSWORD} ${script_dir}/${script_name}" - exit $? -else - echo -e "${BNC}Root access obtained.${NC}" -fi - # Ask the user to input PASSWORD if not set if [ -z "${USERNAME}" ] || [ ${USERNAME} = "root" ]; then read -p "Username: " USERNAME @@ -70,9 +60,9 @@ if ! id "${USERNAME}" >/dev/null 2>&1; then fi echo "" fi -if [ -z ${EMAIL} ]; then +if [ -z "${EMAIL}" ]; then EMAIL=$(git config --global user.email) - if [ -z ${EMAIL} ]; then + if [ -z "${EMAIL}" ]; then read -p "Email: " EMAIL fi fi @@ -80,6 +70,16 @@ if [ -z "${USER_PICTURE_URL}" ] && [ ! -f "/var/lib/AccountsService/icons/${USER read -p "User profile picture URL (leave blank for none): " USER_PICTURE_URL fi +# Make sure we are running as root +if [[ $EUID -ne 0 ]]; then + # If we are not running as root, try to relaunch ourselves as root + echo -e "${BNC}Testing root access...${NC}" + sudo bash -c "USERNAME=${USERNAME} GIT_USER=${GIT_USER} EMAIL=${EMAIL} USER_COMMENT=${USER_COMMENT} USER_PICTURE_URL=${USER_PICTURE_URL} PASSWORD=${PASSWORD} ${script_dir}/${script_name}" + exit $? +else + echo -e "${BNC}Root access obtained.${NC}" +fi + # Detect distribution source /etc/os-release if ! [[ -d ${current_dir}/distribution/${ID} ]]; then