Skip to content

Commit

Permalink
Allow to use wget in addition to curl when installing workspace agent…
Browse files Browse the repository at this point in the history
… + terminal agent (eclipse-che#4029)

* For example alpine images have natively wget tool installed (in a busybox version) but not curl by default

so, we could check that either curl or wget is installed instead of only checking if curl is installed as we only need to download binaries which wget can perform easily as well

Change-Id: I7d02fb70f5f2fb03432072f4f33ff27532c8601e
Signed-off-by: Florent BENOIT <fbenoit@codenvy.com>
  • Loading branch information
benoitf committed Mar 31, 2017
1 parent 339ea53 commit 950dd69
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 19 deletions.
52 changes: 44 additions & 8 deletions agents/exec/src/main/resources/org.eclipse.che.exec.script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@
unset PACKAGES
unset SUDO
command -v tar >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" tar"; }
command -v curl >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" curl"; }
CURL_INSTALLED=false
WGET_INSTALLED=false
command -v curl >/dev/null 2>&1 && CURL_INSTALLED=true
command -v wget >/dev/null 2>&1 && WGET_INSTALLED=true

# no curl, no wget, install curl
if [ ${CURL_INSTALLED} = false ] && [ ${WGET_INSTALLED} = false ]; then
PACKAGES=${PACKAGES}" curl";
fi

test "$(id -u)" = 0 || SUDO="sudo -E"

CHE_DIR=$HOME/che
Expand Down Expand Up @@ -148,23 +157,50 @@ eval "LOCAL_AGENT_BINARIES_URI=${LOCAL_AGENT_BINARIES_URI}"
eval "DOWNLOAD_AGENT_BINARIES_URI=${DOWNLOAD_AGENT_BINARIES_URI}"
eval "TARGET_AGENT_BINARIES_URI=${TARGET_AGENT_BINARIES_URI}"

LOCAL_AGENT_PATH=
if [ -f "${LOCAL_AGENT_BINARIES_URI}" ]; then
AGENT_BINARIES_URI="file://${LOCAL_AGENT_BINARIES_URI}"
LOCAL_AGENT_PATH=${LOCAL_AGENT_BINARIES_URI}
elif [ -f $(echo "${LOCAL_AGENT_BINARIES_URI}" | sed "s/-${PREFIX}//g") ]; then
AGENT_BINARIES_URI="file://"$(echo "${LOCAL_AGENT_BINARIES_URI}" | sed "s/-${PREFIX}//g")
LOCAL_AGENT_PATH=$(echo "${LOCAL_AGENT_BINARIES_URI}" | sed "s/-${PREFIX}//g")
else
echo "Exec Agent will be downloaded from Workspace Master"
AGENT_BINARIES_URI=${DOWNLOAD_AGENT_BINARIES_URI}
fi


if curl -o /dev/null --silent --head --fail $(echo ${AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g'); then
curl -o $(echo ${TARGET_AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g' | sed 's/file:\/\///g') -s $(echo ${AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g')
elif curl -o /dev/null --silent --head --fail $(echo ${AGENT_BINARIES_URI} | sed 's/-\${PREFIX}//g'); then
curl -o $(echo ${TARGET_AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g' | sed 's/file:\/\///g') -s $(echo ${AGENT_BINARIES_URI} | sed 's/-\${PREFIX}//g')
# If file is already on the filesystem, use it
if [ ! -z ${LOCAL_AGENT_PATH} ]; then
tar zxf ${LOCAL_AGENT_PATH} -C ${CHE_DIR}
else
echo "Exec Agent binary is downloaded remotely"
# Use curl
if [ ${CURL_INSTALLED} = true ]; then
if curl -o /dev/null --silent --head --fail $(echo ${AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g'); then
curl -o $(echo ${TARGET_AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g' | sed 's/file:\/\///g') -s $(echo ${AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g')
elif curl -o /dev/null --silent --head --fail $(echo ${AGENT_BINARIES_URI} | sed 's/-\${PREFIX}//g'); then
curl -o $(echo ${TARGET_AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g' | sed 's/file:\/\///g') -s $(echo ${AGENT_BINARIES_URI} | sed 's/-\${PREFIX}//g')
fi
curl -s $(echo ${TARGET_AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g') | tar xzf - -C ${CHE_DIR}
else
# replace https by http as wget may not be able to handle ssl
AGENT_BINARIES_URI=$(echo ${AGENT_BINARIES_URI} | sed 's/https/http/g')

# use wget
WGET_SPIDER="wget --spider"
if wget 2>&1 | grep -q BusyBox; then
WGET_SPIDER="wget -s"
fi
LOCAL_DOWNLOAD=$(echo ${TARGET_AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g' | sed 's/file:\/\///g')
if ${WGET_SPIDER} -q $(echo ${AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g') >/dev/null; then
wget -qO ${LOCAL_DOWNLOAD} $(echo ${AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g')
elif ${WGET_SPIDER} -q $(echo ${AGENT_BINARIES_URI} | sed 's/-\${PREFIX}//g'); then
wget -qO- ${LOCAL_DOWNLOAD} $(echo ${AGENT_BINARIES_URI} | sed 's/-\${PREFIX}//g')
fi
tar xzf ${LOCAL_DOWNLOAD} -C ${CHE_DIR}
fi
fi

curl -s $(echo ${TARGET_AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g') | tar xzf - -C ${CHE_DIR}


if [ -f /bin/bash ]; then
SHELL_INTERPRETER="/bin/bash"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@
unset PACKAGES
unset SUDO
command -v tar >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" tar"; }
command -v curl >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" curl"; }
CURL_INSTALLED=false
WGET_INSTALLED=false
command -v curl >/dev/null 2>&1 && CURL_INSTALLED=true
command -v wget >/dev/null 2>&1 && WGET_INSTALLED=true

# no curl, no wget, install curl
if [ ${CURL_INSTALLED} = false ] && [ ${WGET_INSTALLED} = false ]; then
PACKAGES=${PACKAGES}" curl";
fi

test "$(id -u)" = 0 || SUDO="sudo -E"

CHE_DIR=$HOME/che
Expand Down Expand Up @@ -149,23 +158,50 @@ eval "LOCAL_AGENT_BINARIES_URI=${LOCAL_AGENT_BINARIES_URI}"
eval "DOWNLOAD_AGENT_BINARIES_URI=${DOWNLOAD_AGENT_BINARIES_URI}"
eval "TARGET_AGENT_BINARIES_URI=${TARGET_AGENT_BINARIES_URI}"

LOCAL_AGENT_PATH=
if [ -f "${LOCAL_AGENT_BINARIES_URI}" ]; then
AGENT_BINARIES_URI="file://${LOCAL_AGENT_BINARIES_URI}"
LOCAL_AGENT_PATH=${LOCAL_AGENT_BINARIES_URI}
elif [ -f $(echo "${LOCAL_AGENT_BINARIES_URI}" | sed "s/-${PREFIX}//g") ]; then
AGENT_BINARIES_URI="file://"$(echo "${LOCAL_AGENT_BINARIES_URI}" | sed "s/-${PREFIX}//g")
LOCAL_AGENT_PATH=$(echo "${LOCAL_AGENT_BINARIES_URI}" | sed "s/-${PREFIX}//g")
else
echo "Terminal Agent will be downloaded from Workspace Master"
AGENT_BINARIES_URI=${DOWNLOAD_AGENT_BINARIES_URI}
fi


if curl -o /dev/null --silent --head --fail $(echo ${AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g'); then
curl -o $(echo ${TARGET_AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g' | sed 's/file:\/\///g') -s $(echo ${AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g')
elif curl -o /dev/null --silent --head --fail $(echo ${AGENT_BINARIES_URI} | sed 's/-\${PREFIX}//g'); then
curl -o $(echo ${TARGET_AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g' | sed 's/file:\/\///g') -s $(echo ${AGENT_BINARIES_URI} | sed 's/-\${PREFIX}//g')
# If file is already on the filesystem, use it
if [ ! -z ${LOCAL_AGENT_PATH} ]; then
tar zxf ${LOCAL_AGENT_PATH} -C ${CHE_DIR}
else
echo "Terminal Agent binary is downloaded remotely"
# Use curl
if [ ${CURL_INSTALLED} = true ]; then
if curl -o /dev/null --silent --head --fail $(echo ${AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g'); then
curl -o $(echo ${TARGET_AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g' | sed 's/file:\/\///g') -s $(echo ${AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g')
elif curl -o /dev/null --silent --head --fail $(echo ${AGENT_BINARIES_URI} | sed 's/-\${PREFIX}//g'); then
curl -o $(echo ${TARGET_AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g' | sed 's/file:\/\///g') -s $(echo ${AGENT_BINARIES_URI} | sed 's/-\${PREFIX}//g')
fi
curl -s $(echo ${TARGET_AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g') | tar xzf - -C ${CHE_DIR}
else
# replace https by http as wget may not be able to handle ssl
AGENT_BINARIES_URI=$(echo ${AGENT_BINARIES_URI} | sed 's/https/http/g')

# use wget
WGET_SPIDER="wget --spider"
if wget 2>&1 | grep -q BusyBox; then
WGET_SPIDER="wget -s"
fi
LOCAL_DOWNLOAD=$(echo ${TARGET_AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g' | sed 's/file:\/\///g')
if ${WGET_SPIDER} -q $(echo ${AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g') >/dev/null; then
wget -qO ${LOCAL_DOWNLOAD} $(echo ${AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g')
elif ${WGET_SPIDER} -q $(echo ${AGENT_BINARIES_URI} | sed 's/-\${PREFIX}//g'); then
wget -qO- ${LOCAL_DOWNLOAD} $(echo ${AGENT_BINARIES_URI} | sed 's/-\${PREFIX}//g')
fi
tar xzf ${LOCAL_DOWNLOAD} -C ${CHE_DIR}
fi
fi

curl -s $(echo ${TARGET_AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g') | tar xzf - -C ${CHE_DIR}


if [ -f /bin/bash ]; then
SHELL_INTERPRETER="/bin/bash"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@
unset PACKAGES
unset SUDO
command -v tar >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" tar"; }
command -v curl >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" curl"; }
CURL_INSTALLED=false
WGET_INSTALLED=false
command -v curl >/dev/null 2>&1 && CURL_INSTALLED=true
command -v wget >/dev/null 2>&1 && WGET_INSTALLED=true

# no curl, no wget, install curl
if [ ${CURL_INSTALLED} = false ] && [ ${WGET_INSTALLED} = false ]; then
PACKAGES=${PACKAGES}" curl";
fi

test "$(id -u)" = 0 || SUDO="sudo -E"

LOCAL_AGENT_BINARIES_URI="/mnt/che/ws-agent.tar.gz"
Expand Down Expand Up @@ -233,13 +242,23 @@ eval "DOWNLOAD_AGENT_BINARIES_URI=${DOWNLOAD_AGENT_BINARIES_URI}"

if [ -f "${LOCAL_AGENT_BINARIES_URI}" ] && [ -s "${LOCAL_AGENT_BINARIES_URI}" ]
then
AGENT_BINARIES_URI="file://${LOCAL_AGENT_BINARIES_URI}"
tar zxf "${LOCAL_AGENT_BINARIES_URI}" -C ${CHE_DIR}/ws-agent
else
echo "Workspace Agent will be downloaded from Workspace Master"
AGENT_BINARIES_URI=${DOWNLOAD_AGENT_BINARIES_URI}
if [ ${CURL_INSTALLED} = true ]; then
curl -s ${AGENT_BINARIES_URI} | tar xzf - -C ${CHE_DIR}/ws-agent
else
# replace https by http as wget may not be able to handle ssl
AGENT_BINARIES_URI=$(echo ${AGENT_BINARIES_URI} | sed 's/https/http/g')

# use wget
wget -qO- ${AGENT_BINARIES_URI} | tar xzf - -C ${CHE_DIR}/ws-agent
fi

fi

curl -s ${AGENT_BINARIES_URI} | tar xzf - -C ${CHE_DIR}/ws-agent


###############################################
### ws-agent run command will be added here ###
Expand Down

0 comments on commit 950dd69

Please sign in to comment.