energy-quants / bootstrap

A repo containing scripts for bootstrapping a development environment
MIT License
0 stars 1 forks source link

Check for `sudo` if required #5

Closed dhirschfeld closed 2 years ago

dhirschfeld commented 2 years ago

Installing mambaforge requires admin permissions so we should error out early if the user doesn't have the required permissions.

Error:

+ filepath=/tmp/install.sh.rxaKyDlyhn6F/Mambaforge-4.12.0-2-Linux-x86_64.sh
+ trap cleanup EXIT
+ USER=sysop
+ chown sysop:sysop /tmp/install.sh.rxaKyDlyhn6F/Mambaforge-4.12.0-2-Linux-x86_64.sh
+ prefix=/opt/mambaforge
+ mkdir -pv /opt/mambaforge/envs
mkdir: cannot create directory ‘/opt/mambaforge’: Permission denied
+ cleanup
+ rm -rf /tmp/install.sh.rxaKyDlyhn6F

sudo -n whoami can be used to test for admin permissions:

$ sudo -n whoami
sudo: a password is required
$ sudo whoami
[sudo] password for sysop:
root
$ sudo -n whoami
root

...which should be added immediately after the command line parsing: https://github.com/energy-quants/bootstrap/blob/8db07162817ec13e5cd46e7f6daf629addaaab58/linux/mambaforge/install.sh#L1-L8