diff --git a/nextcloud-startup-script.sh b/nextcloud-startup-script.sh index ad414326..3e8a91cf 100644 --- a/nextcloud-startup-script.sh +++ b/nextcloud-startup-script.sh @@ -19,6 +19,27 @@ is_root() { fi } +msg_box() { +local PROMPT="$1" + whiptail --msgbox "${PROMPT}" "$WT_HEIGHT" "$WT_WIDTH" +} + +root_check() { +if ! is_root +then +msg_box "Sorry, you are not root. You now have two options: +1. With SUDO directly: + a) :~$ sudo bash $SCRIPTS/name-of-script.sh +2. Become ROOT and then type your command: + a) :~$ sudo -i + b) :~# $SCRIPTS/name-of-script.sh +In both cases above you can leave out $SCRIPTS/ if the script +is directly in your PATH. +More information can be found here: https://unix.stackexchange.com/a/3064" + exit 1 +fi +} + network_ok() { echo "Testing if network is OK..." service networking restart @@ -70,6 +91,36 @@ Please report this issue here: $ISSUES" exit 1 fi +# Is this run as a pure root user? +if is_root +then + if [[ "$UNIXUSER" == "ncadmin" ]] + then + sleep 1 + else + if [ -z "$UNIXUSER" ] + then +msg_box "You seem to be running this as the pure root user. +You must run this as a regular user with sudo permissions. + +Please create a user with sudo permissions and the run this command: +sudo -u [user-with-sudo-permissions] sudo bash /var/scripts/nextcloud-startup-script.sh + +We will do this for you when you hit OK." + run_static_script adduser $SCRIPTS/nextcloud-startup-script.sh + else +msg_box "You probably see this message if the user 'ncadmin' does not exist on the system, +which could be the case if you are running directly from the scripts and not the VM. + +As long as the user you created have sudo permissions it's safe to continue. +This would be the case if you in the previous step created a new user with the script. + +If the user you are running this script with doesn't have sudo permissions, +please abort this script and report this issue to $ISSUES." + fi + fi +fi + # Check if dpkg or apt is running is_process_running dpkg is_process_running apt diff --git a/nextcloud_install_production.sh b/nextcloud_install_production.sh index 395a4393..c55a4bc5 100644 --- a/nextcloud_install_production.sh +++ b/nextcloud_install_production.sh @@ -35,7 +35,7 @@ ram_check 2 Nextcloud cpu_check 1 Nextcloud # Create new current user -run_static_script adduser +run_static_script adduser nextcloud_install_production.sh # Check Ubuntu version echo "Checking server OS and version..." diff --git a/static/adduser.sh b/static/adduser.sh index 43569e7b..ee09fadf 100644 --- a/static/adduser.sh +++ b/static/adduser.sh @@ -35,6 +35,6 @@ then do sudo passwd "$NEWUSER" && break done - sudo -u "$NEWUSER" sudo bash nextcloud_install_production.sh + sudo -u "$NEWUSER" sudo bash "$1" fi fi diff --git a/static/change-root-profile.sh b/static/change-root-profile.sh index 9392dd08..4b07e03b 100644 --- a/static/change-root-profile.sh +++ b/static/change-root-profile.sh @@ -27,23 +27,6 @@ then fi fi -if [[ "$(whoami)" == "root" ]] -then - if id -u ncadmin > /dev/null - then - sleep 1 - else - echo - echo "You seem to be running this as the pure root user." - echo "You must run this as a regular user with sudo permissions." - echo "Please copy the line below and run it with the user that have sudo permissions:" - echo "sudo -u [user] sudo bash /var/scripts/nextcloud-startup-script.sh" - echo - echo "Please press CTRL+C within 60 seconds." - sleep 60 - fi -fi - if [ -x /var/scripts/nextcloud-startup-script.sh ] then /var/scripts/nextcloud-startup-script.sh