only sudo as fallback, use mktemp -d

This commit is contained in:
AJ ONeal 2018-06-23 16:29:13 -06:00
parent a443dd04d3
commit bad41027ad
3 changed files with 38 additions and 28 deletions

View File

@ -33,6 +33,8 @@ NO_FAIL2BAN="nope"
OS="unsupported"
ARCH=""
SETUP_FILE=""
my_tmp=$(mktemp -d)
export my_tmp
clear
@ -179,13 +181,13 @@ fi
INSTALL_DEPS_FILE="setup-deps-${SETUP_FILE}.bash"
INSTALL_FILE="setup-node-${SETUP_FILE}.bash"
if [ ! -e "/tmp/${INSTALL_FILE}" ]; then
if [ ! -e "$my_tmp/${INSTALL_FILE}" ]; then
if [ -n "$(type -p curl)" ]; then
curl --silent -L "${BASE_URL}/${INSTALL_FILE}" \
-o "/tmp/${INSTALL_FILE}" || echo 'error downloading os setup script'
-o "$my_tmp/${INSTALL_FILE}" || echo 'error downloading os setup script'
elif [ -n "$(type -p wget)" ]; then
wget --quiet "${BASE_URL}/${INSTALL_FILE}" \
-O "/tmp/${INSTALL_FILE}" || echo 'error downloading os setup script'
-O "$my_tmp/${INSTALL_FILE}" || echo 'error downloading os setup script'
else
echo "Found neither 'curl' nor 'wget'. Can't Continue."
exit 1
@ -193,13 +195,13 @@ if [ ! -e "/tmp/${INSTALL_FILE}" ]; then
fi
if [ "--dev-deps" == "$deps_flag" ]; then
if [ ! -e "/tmp/${INSTALL_DEPS_FILE}" ]; then
if [ ! -e "$my_tmp/${INSTALL_DEPS_FILE}" ]; then
if [ -n "$(type -p curl)" ]; then
curl --silent -L "${BASE_URL}/${INSTALL_DEPS_FILE}" \
-o "/tmp/${INSTALL_DEPS_FILE}" || echo 'error downloading os deps script: '"${BASE_URL}/${INSTALL_DEPS_FILE}"
-o "$my_tmp/${INSTALL_DEPS_FILE}" || echo 'error downloading os deps script: '"${BASE_URL}/${INSTALL_DEPS_FILE}"
elif [ -n "$(type -p wget)" ]; then
wget --quiet "${BASE_URL}/${INSTALL_DEPS_FILE}" \
-O "/tmp/${INSTALL_DEPS_FILE}" || echo 'error downloading os deps script: '"${BASE_URL}/${INSTALL_DEPS_FILE}"
-O "$my_tmp/${INSTALL_DEPS_FILE}" || echo 'error downloading os deps script: '"${BASE_URL}/${INSTALL_DEPS_FILE}"
else
echo "Found neither 'curl' nor 'wget'. Can't Continue."
exit 1
@ -207,14 +209,14 @@ if [ "--dev-deps" == "$deps_flag" ]; then
fi
fi
if [ ! -e "/tmp/${INSTALL_FILE}" ]
if [ ! -e "$my_tmp/${INSTALL_FILE}" ]
then
echo "Error Downloading Install File"
exit 1
fi
if [ "--dev-deps" == "$deps_flag" ]; then
if [ ! -e "/tmp/${INSTALL_DEPS_FILE}" ]
if [ ! -e "$my_tmp/${INSTALL_DEPS_FILE}" ]
then
echo "Error Downloading Deps File"
exit 1
@ -227,10 +229,10 @@ fi
if [ -z "${NODEJS_VER:-}" ]; then
# For backwards compat
if [ -f "/tmp/NODEJS_VER" ]; then
NODEJS_VER=$(cat /tmp/NODEJS_VER | grep v)
if [ -f "$my_tmp/NODEJS_VER" ]; then
NODEJS_VER=$(cat $my_tmp/NODEJS_VER | grep v)
elif [ -f "/tmp/IOJS_VER" ]; then
NODEJS_VER=$(cat /tmp/IOJS_VER | grep v)
NODEJS_VER=$(cat $my_tmp/IOJS_VER | grep v)
fi
fi
@ -292,10 +294,10 @@ if [ -e "$node_install_path/bin/node" ]; then
fi
if [ -n "${NODEJS_VER}" ]; then
bash "/tmp/${INSTALL_FILE}" "${NODEJS_VER}"
bash "$my_tmp/${INSTALL_FILE}" "${NODEJS_VER}"
fi
$sudo_cmd chown -R $(whoami) $node_install_path/lib/node_modules
chown -R $(whoami) $node_install_path/lib/node_modules || $sudo_cmd chown -R $(whoami) $node_install_path/lib/node_modules
echo ""
@ -339,7 +341,7 @@ if [ "--dev-deps" == "$deps_flag" ]; then
# fi
#fi
bash "/tmp/${INSTALL_DEPS_FILE}" "${NO_FAIL2BAN}"
bash "$my_tmp/${INSTALL_DEPS_FILE}" "${NO_FAIL2BAN}"
# yarn
#if [ -z "$(type -p yarn)" ]; then

View File

@ -4,6 +4,9 @@ set -e
set -u
set -o pipefail
if [ -z "${my_tmp-}" ]; then
my_tmp=$(mkdir -p)
fi
if [ -z "${PREFIX-}" ]; then
PREFIX=""
fi
@ -33,23 +36,25 @@ fi
#NODEJS_PKG="/tmp/${NODEJS_NAME}-${NODEJS_VER}.pkg"
NODEJS_REMOTE="$NODEJS_BASE_URL/dist/${NODEJS_VER}/${NODEJS_NAME}-${NODEJS_VER}-darwin-x64.tar.gz"
NODEJS_PKG="/tmp/${NODEJS_NAME}-${NODEJS_VER}-darwin-x64.tar.gz"
NODEJS_UNTAR="/tmp/${NODEJS_NAME}-${NODEJS_VER}-darwin-x64"
NODEJS_PKG="$my_tmp/${NODEJS_NAME}-${NODEJS_VER}-darwin-x64.tar.gz"
NODEJS_UNTAR="$my_tmp/${NODEJS_NAME}-${NODEJS_VER}-darwin-x64"
if [ -n "${NODEJS_VER}" ]; then
echo "installing ${NODEJS_NAME} as ${NODEJS_NAME} ${NODEJS_VER}..."
curl -fsSL "${NODEJS_REMOTE}" -o "${NODEJS_PKG}"
# When using .pkg
#sudo /usr/sbin/installer -pkg "${NODEJS_PKG}" -target /
# When using .tar.gz
mkdir -p ${NODEJS_UNTAR}/
tar xf "${NODEJS_PKG}" -C "${NODEJS_UNTAR}/" --strip-components=1
rm -f ${NODEJS_UNTAR}/{LICENSE,CHANGELOG.md,README.md}
sudo rsync -a "${NODEJS_UNTAR}/" "$node_install_path/"
sudo chown -R $(whoami) "$node_install_path/lib/node_modules/"
sudo chown $(whoami) "$node_install_path/bin/"
mkdir -p "$node_install_path/" || sudo mkdir -p "$node_install_path/"
rsync -a "${NODEJS_UNTAR}/" "$node_install_path/" || sudo rsync -a "${NODEJS_UNTAR}/" "$node_install_path/"
chown -R $(whoami) "$node_install_path/lib/node_modules/" || sudo chown -R $(whoami) "$node_install_path/lib/node_modules/"
chown $(whoami) "$node_install_path/bin/" || sudo chown $(whoami) "$node_install_path/bin/"
fi

View File

@ -8,6 +8,9 @@ set -e
set -u
set -o pipefail
if [ -z "${my_tmp-}" ]; then
my_tmp=$(mkdir -p)
fi
if [ -z "${PREFIX-}" ]; then
PREFIX=""
fi
@ -46,8 +49,8 @@ else
fi
NODEJS_REMOTE="${NODEJS_BASE_URL}/dist/${NODEJS_VER}/${NODEJS_NAME}-${NODEJS_VER}-linux-${ARCH}.tar.gz"
NODEJS_LOCAL="/tmp/${NODEJS_NAME}-${NODEJS_VER}-linux-${ARCH}.tar.gz"
NODEJS_UNTAR="/tmp/${NODEJS_NAME}-${NODEJS_VER}-linux-${ARCH}"
NODEJS_LOCAL="$my_tmp/${NODEJS_NAME}-${NODEJS_VER}-linux-${ARCH}.tar.gz"
NODEJS_UNTAR="$my_tmp/${NODEJS_NAME}-${NODEJS_VER}-linux-${ARCH}"
if [ -n "${NODEJS_VER}" ]; then
echo "installing ${NODEJS_NAME} as ${NODEJS_NAME} ${NODEJS_VER}..."
@ -58,7 +61,7 @@ if [ -n "${NODEJS_VER}" ]; then
wget --quiet ${NODEJS_REMOTE} -O ${NODEJS_LOCAL} || echo 'error downloading ${NODEJS_NAME}'
else
echo "'wget' and 'curl' are missing. Please run the following command and try again"
echo "\tsudo apt-get install --yes curl wget"
echo " sudo apt-get install --yes curl wget"
exit 1
fi
@ -69,9 +72,9 @@ if [ -n "${NODEJS_VER}" ]; then
rm -rf ${NODEJS_UNTAR}/${NODEJS_NAME}-${NODEJS_VER}-linux-${ARCH} # clean up the temporary unzip folder
rm ${NODEJS_UNTAR}/{LICENSE,CHANGELOG.md,README.md}
echo $sudo_cmd rsync -a "${NODEJS_UNTAR}/" "$node_install_path/"
$sudo_cmd rsync -a "${NODEJS_UNTAR}/" "$node_install_path/"
rsync -a "${NODEJS_UNTAR}/" "$node_install_path/" || $sudo_cmd rsync -a "${NODEJS_UNTAR}/" "$node_install_path/"
rm -rf "${NODEJS_UNTAR}"
$sudo_cmd chown -R $(whoami) "$node_install_path/lib/node_modules/"
$sudo_cmd chown $(whoami) ""$node_install_path"/bin/"
chown -R $(whoami) "$node_install_path/lib/node_modules/" || $sudo_cmd chown -R $(whoami) "$node_install_path/lib/node_modules/"
chown $(whoami) ""$node_install_path"/bin/" || $sudo_cmd chown $(whoami) ""$node_install_path"/bin/"
fi