If I run this script, how do I pass super user permissions to it? I wrote this just to setup new machines with the basics. I don't want to run every command with elevated permissions, but the commands that do have
sudo I want to run with them.
How do I have some commands run with
sudo and others run as the regular user?
#!/bin/sh # If Linux, install nodeJS if $(uname) = 'Linux'; then export IS_LINUX=1 # Does it have aptitude? if -x "which apt-get"; then export HAS_APT=1 # Install NodeJS sudo apt-get install --yes nodejs fi # Does it have yum? if -x "which yum" ; then export HAS_YUM=1 # Install NodeJS sudo yum install nodejs npm fi # Does it have pacman? if -x "which pacman" ; then export HAS_PACMAN=1 # Install NodeJS pacman -S nodejs npm fi fi # If OSx, install Homebrew and NodeJS if $(uname) = 'Darwin' ; then export IS_MAC=1 if test ! "$(which brew)" then echo "================================" echo " Installing Homebrew for you." echo "================================" ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" export HAS_BREW=1 elif -x 'which brew' ; then export HAS_BREW=1 brew update fi # Install NodeJS brew install --quiet node fi # Does it have python? if -x "which python" ; then export HAS_PYTHON=1 if -x "which pip" ; then pip list --outdated | cut -d ' ' -f1 | xargs -n1 pip install -U export HAS_PIP=1 fi fi # Does it have node package manager? if -x "which npm" ; then export HAS_NPM=1 else echo "NPM install failed, please do manually" fi # Does it have ruby gems? if -x "which gem" ; then export HAS_GEM=1 fi
The rest of the bash script (that I didn't include for length) installs packages from an array using npm, apt, yum, brew, or pacman, depending on the machine. It only installs simple things like