Update install.sh to use portable `sudo_cmd` syntax

This commit is contained in:
richdex14 2017-09-04 13:30:10 -06:00
parent bb1ee7ab99
commit 32f835aa30
1 changed files with 7 additions and 3 deletions

View File

@ -1,5 +1,9 @@
#!/bin/bash #!/bin/bash
# Not every platform has or needs sudo, gotta save them O(1)s...
sudo_cmd=""
((EUID)) && [[ -z "$ANDROID_ROOT" ]] && sudo_cmd="sudo"
set -e set -e
set -u set -u
@ -54,9 +58,9 @@ detect_http_get
install_walnut() install_walnut()
{ {
sudo mkdir -p /srv/walnut/{var,etc,packages,node_modules} $sudo_cmd mkdir -p /srv/walnut/{var,etc,packages,node_modules}
# www-data exists on linux, _www exists on mac OS # www-data exists on linux, _www exists on mac OS
sudo chown -R $(whoami):www-data /srv/walnut || sudo chown -R $(whoami):_www /srv/walnut $sudo_cmd chown -R $(whoami):www-data /srv/walnut || $sudo_cmd chown -R $(whoami):_www /srv/walnut
if [ ! -d "/srv/walnut/core/" ]; then if [ ! -d "/srv/walnut/core/" ]; then
git clone https://git.daplie.com/Daplie/walnut.js.git /srv/walnut/core git clone https://git.daplie.com/Daplie/walnut.js.git /srv/walnut/core
fi fi
@ -72,7 +76,7 @@ install_walnut()
/srv/walnut/core/install-helper.sh /srv/walnut /srv/walnut/core/install-helper.sh /srv/walnut
# Now that the install is finished we need to set the owner to the user that will actually # Now that the install is finished we need to set the owner to the user that will actually
# be running the walnut server. # be running the walnut server.
sudo chown -R www-data:www-data /srv/walnut || sudo chown -R _www:_www /srv/walnut $sudo_cmd chown -R www-data:www-data /srv/walnut || $sudo_cmd chown -R _www:_www /srv/walnut
} }
# Install node # Install node