add more logic to check if it's run as a pure root user (#428)

This commit is contained in:
Daniel Hansson 2017-12-10 03:43:29 +01:00 committed by GitHub
parent 80d38d7d10
commit 508bd812f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 19 deletions

View File

@ -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

View File

@ -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..."

View File

@ -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

View File

@ -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