Skip to content

Commit 433ec79

Browse files
committed
Support running as root on Linux
1 parent fcc47b8 commit 433ec79

1 file changed

Lines changed: 23 additions & 16 deletions

File tree

linux-installer/idt-installer

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ GIT_URL="https://github.com/IBM-Bluemix/ibm-cloud-developer-tools"
1414
SLACK_URL="https://slack-invite-ibm-cloud-tech.mybluemix.net/"
1515
DEFAULT_BMX_URL="https://clis.ng.bluemix.net/install"
1616

17+
# Only use sudo if not running as root:
18+
[ "$(id -u)" -ne 0 ] && SUDO=sudo || SUDO=""
19+
1720
if [[ "$IDT_INSTALL_USE_PROD" != false ]]; then
1821
unset IDT_INSTALL_BMX_URL IDT_INSTALL_BMX_REPO_NAME IDT_INSTALL_BMX_REPO_URL
1922
fi
@@ -125,20 +128,20 @@ function uninstall {
125128
fi
126129
fi
127130
warn "Starting Uninstall..."
128-
log "You may be prompted for 'sudo' password."
131+
[ "$SUDO" ] && log "You may be prompted for 'sudo' password."
129132

130133
log "Removing IBM Cloud 'bx' CLI..."
131134
if [[ "${PLATFORM}" == "Darwin" && "$USEBREW" == true ]]; then
132135
brew cask uninstall "bluemix-cli"
133136
fi
134137
#-- Run the following regardless
135-
sudo rm -f /usr/local/bin/bluemix
136-
sudo rm -f /usr/local/bin/bx
137-
sudo rm -f /usr/local/bin/bluemix-analytics
138-
sudo rm -rf /usr/local/Bluemix
138+
$SUDO rm -f /usr/local/bin/bluemix
139+
$SUDO rm -f /usr/local/bin/bx
140+
$SUDO rm -f /usr/local/bin/bluemix-analytics
141+
$SUDO rm -rf /usr/local/Bluemix
139142
#-- Taken from bluemix CLI brew uninstaller
140143
if [[ -f /etc/profile ]]; then
141-
sudo sed -E -i ".bluemix_uninstall_bak" \
144+
$SUDO sed -E -i ".bluemix_uninstall_bak" \
142145
-e '/^### Added by the Bluemix CLI$/d' \
143146
-e '/^source \/usr\/local\/Bluemix\/bx\/bash_autocomplete$/d' \
144147
/etc/profile
@@ -165,7 +168,7 @@ function uninstall {
165168
#------------------------------------------------------------------------------
166169
function install {
167170
log "Starting Full Installation..."
168-
log "Note: You may be prompted for your 'sudo' password during install."
171+
[ "$SUDO" ] && log "Note: You may be prompted for your 'sudo' password during install."
169172
install_deps
170173
install_bx
171174
install_plugins
@@ -206,22 +209,26 @@ function install_deps {
206209
elif [[ "$prog_bin" == "git" ]]; then
207210
if [[ -n "$(which "apt-get")" ]]; then
208211
# Make sure add-apt-repository is installed.
209-
sudo apt-get install software-properties-common python-software-properties
212+
$SUDO apt-get install -y software-properties-common python-software-properties
210213
# Get up-to-date git.
211-
sudo add-apt-repository -y ppa:git-core/ppa
212-
sudo apt-get -y update
213-
sudo apt-get -y install git
214+
$SUDO add-apt-repository -y ppa:git-core/ppa
215+
$SUDO apt-get -y update
216+
$SUDO apt-get -y install git
214217
log "Review any setup requirements for '${prog_bin}' from: ${prog_url}"
215218
else
216219
warn_unsupported
217220
fi
218221
elif [[ "$prog_bin" == "docker" ]]; then
219222
case $PLATFORM in
220223
"Linux")
221-
curl -fsSL get.docker.com | sudo sh -
222-
# Allow docker to run as a non-root user.
223-
sudo groupadd docker
224-
sudo usermod -aG docker $USER
224+
curl -fsSL get.docker.com | $SUDO sh -
225+
if [ "$SUDO" ]; then
226+
# Allow docker to run as a non-root user (if not running as root).
227+
sudo groupadd docker
228+
sudo usermod -aG docker $USER
229+
else
230+
log 'If you want to run docker without sudo run: "sudo groupadd docker && sudo usermod -aG docker $USER"'
231+
fi
225232
log "Review any setup requirements for '${prog_bin}' from: ${prog_url}"
226233
;;
227234
*)
@@ -242,7 +249,7 @@ function install_deps {
242249
;;
243250
esac
244251
chmod +x ./kubectl
245-
sudo mv ./kubectl /usr/local/bin/kubectl
252+
$SUDO mv ./kubectl /usr/local/bin/kubectl
246253
log "Review any setup requirements for '${prog_bin}' from: ${prog_url}"
247254
elif [[ "$prog_bin" == "helm" ]]; then
248255
curl -fsSL https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get | bash

0 commit comments

Comments
 (0)