@@ -14,6 +14,9 @@ GIT_URL="https://github.com/IBM-Bluemix/ibm-cloud-developer-tools"
1414SLACK_URL=" https://slack-invite-ibm-cloud-tech.mybluemix.net/"
1515DEFAULT_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+
1720if [[ " $IDT_INSTALL_USE_PROD " != false ]]; then
1821 unset IDT_INSTALL_BMX_URL IDT_INSTALL_BMX_REPO_NAME IDT_INSTALL_BMX_REPO_URL
1922fi
@@ -106,14 +109,6 @@ function prompt {
106109 # -- Use $REPLY to get user's input
107110}
108111
109- function prompt_password {
110- label=${1}
111- echo -en " ${label} : ${CYN} " > /dev/tty
112- read -rs # hide input
113- echo -e " ${NRM} " > /dev/tty
114- # -- Use $REPLY to get user's input
115- }
116-
117112# ------------------------------------------------------------------------------
118113function uninstall {
119114 if [[ -t 0 ]]; then # -- are we in a terminal?
@@ -125,20 +120,20 @@ function uninstall {
125120 fi
126121 fi
127122 warn " Starting Uninstall..."
128- log " You may be prompted for 'sudo' password."
123+ [ " $SUDO " ] && log " You may be prompted for 'sudo' password."
129124
130125 log " Removing IBM Cloud 'bx' CLI..."
131126 if [[ " ${PLATFORM} " == " Darwin" && " $USEBREW " == true ]]; then
132127 brew cask uninstall " bluemix-cli"
133128 fi
134129 # -- 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
130+ $SUDO rm -f /usr/local/bin/bluemix
131+ $SUDO rm -f /usr/local/bin/bx
132+ $SUDO rm -f /usr/local/bin/bluemix-analytics
133+ $SUDO rm -rf /usr/local/Bluemix
139134 # -- Taken from bluemix CLI brew uninstaller
140135 if [[ -f /etc/profile ]]; then
141- sudo sed -E -i " .bluemix_uninstall_bak" \
136+ $SUDO sed -E -i " .bluemix_uninstall_bak" \
142137 -e ' /^### Added by the Bluemix CLI$/d' \
143138 -e ' /^source \/usr\/local\/Bluemix\/bx\/bash_autocomplete$/d' \
144139 /etc/profile
@@ -165,7 +160,7 @@ function uninstall {
165160# ------------------------------------------------------------------------------
166161function install {
167162 log " Starting Full Installation..."
168- log " Note: You may be prompted for your 'sudo' password during install."
163+ [ " $SUDO " ] && log " Note: You may be prompted for your 'sudo' password during install."
169164 install_deps
170165 install_bx
171166 install_plugins
@@ -194,6 +189,14 @@ function install_deps {
194189 fi
195190 [[ -z " $( which brew) " ]] && USEBREW=false
196191
192+ # Install curl if not already installed.
193+ if ! $( which curl > /dev/null 2& > 1) ; then
194+ if [ " $PLATFORM " = Linux ]; then
195+ $SUDO apt-get -y update
196+ $SUDO apt-get -y install curl
197+ fi
198+ fi
199+
197200 for item in " ${EXT_PROGS[@]} " ; do
198201 # -- Parse array item into vars
199202 IFS=" ," read -r prog_bin prog_brew prog_url <<< " $item"
@@ -205,23 +208,31 @@ function install_deps {
205208 log " You should review any setup requirements for '${prog_bin} ' from: ${prog_url} "
206209 elif [[ " $prog_bin " == " git" ]]; then
207210 if [[ -n " $( which " apt-get" ) " ]]; then
208- # Make sure add-apt-repository is installed.
209- sudo apt-get install software-properties-common python-software-properties
210211 # 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
212+ $SUDO apt-get -y update
213+
214+ # Make sure add-apt-repository is installed.
215+ if ! $( which add-apt-repository > /dev/null 2& > 1) ; then
216+ $SUDO apt-get install -y software-properties-common python-software-properties
217+ fi
218+ $SUDO add-apt-repository -y ppa:git-core/ppa
219+ $SUDO apt-get -y update
220+ $SUDO apt-get -y install git
214221 log " Review any setup requirements for '${prog_bin} ' from: ${prog_url} "
215222 else
216223 warn_unsupported
217224 fi
218225 elif [[ " $prog_bin " == " docker" ]]; then
219226 case $PLATFORM in
220227 " 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
228+ curl -fsSL get.docker.com | $SUDO sh -
229+ if [ " $SUDO " ]; then
230+ # Allow docker to run as a non-root user (if not running as root).
231+ sudo groupadd docker
232+ sudo usermod -aG docker $USER
233+ else
234+ log ' If you want to run docker without sudo run: "sudo groupadd docker && sudo usermod -aG docker $USER"'
235+ fi
225236 log " Review any setup requirements for '${prog_bin} ' from: ${prog_url} "
226237 ;;
227238 * )
@@ -242,7 +253,7 @@ function install_deps {
242253 ;;
243254 esac
244255 chmod +x ./kubectl
245- sudo mv ./kubectl /usr/local/bin/kubectl
256+ $SUDO mv ./kubectl /usr/local/bin/kubectl
246257 log " Review any setup requirements for '${prog_bin} ' from: ${prog_url} "
247258 elif [[ " $prog_bin " == " helm" ]]; then
248259 curl -fsSL https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get | bash
@@ -404,7 +415,11 @@ function main {
404415 " Darwin" )
405416 ;;
406417 " Linux" )
407- warn " Linux has only been tested on Ubuntu, please let us know if you use this utility on other Distros"
418+ # Linux distro, e.g "Ubuntu", "RedHatEnterpriseWorkstation", "RedHatEnterpriseServer", "CentOS", "Debian"
419+ DISTRO=$( lsb_release -is 2> /dev/null || echo " " )
420+ if [ " $DISTRO " != Ubuntu ]; then
421+ warn " Linux has only been tested on Ubuntu, please let us know if you use this utility on other Distros"
422+ fi
408423 ;;
409424 * )
410425 warn_unsupported
0 commit comments