Skip to content

Instantly share code, notes, and snippets.

@z2z
Created February 28, 2019 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save z2z/217e46ee9f93edc5bb83b72751539bbc to your computer and use it in GitHub Desktop.
Save z2z/217e46ee9f93edc5bb83b72751539bbc to your computer and use it in GitHub Desktop.
pixelserv-tls-install-beta.sh
#!/usr/bin/env sh
_scriptver=v0.1.7
# DESCRIPTION
#
# A script to automate installation of the latest pixelserv-tls test version
#
# (c) 2017-19 kvic (aka kvic-z@github)
#
# https://kazoo.ga/pixelserv-tls/
#
# HISTORY
#
# 2018-12-15 Support installing last prod version
# 2018-9-22 Support static binary for ARM routers
# 2018-3-22 Added a copyright notice
# 2018-3-5 Added armv8 64-bit installlation
# 2017-11-20 Fixed a glitch in 'text busy'.
# Fixed a glitch in backup prod version binary
# 2017-11-18 Initial release
_beta=2.2.1-1
_tag=2.2.1
_prodver=2.2.1-1
[[ "$_prod" = "1" ]] && _beta=$_prodver && _tag=$_prodver
_bin=/opt/bin/pixelserv-tls
_gpath=https://github.com/kvic-z/pixelserv-tls/releases/download
_arm7z=pixelserv-tls.${_beta}.Entware-ng.armv7softfloat.zip
_mipselz=pixelserv-tls.${_beta}.Entware-ng.mipsel.zip
_armv8z=pixelserv-tls.${_beta}.Entware-3.x.aarch64softfloat.zip
_tmp=/opt/tmp/pixelserv-tls-beta
[[ "$_binfavor" != "static" ]] && _binfavor=dynamic
cat <<EOF
(c) 2017, 2018, 2019 kvic (aka kvic-z@github)
https://kazoo.ga/pixelserv-tls/
PERMISSION IS GRANTED TO USE OR MODIFY THIS SCRIPT FREE OF CHARGE
AS LONG AS THE ABOVE COPYRIGHT NOTICE REMAINS INTACT.
NO WARRANTY IS PROVIDED. PLEASE DECIDE AND USE AT YOUR OWN RISK.
This script (${_scriptver}) will download and install pixelserv-tls beta version ${_beta}.
The script will guide you through and automate the process.
The following Entware-ng/3x architectures are currently provided:
1. armv7 (RT-AC56U/68U/etc) - backup prod versoin and install 32-bit ${_beta}
2. mipsel (RT-N66U/AC66U/etc) - backup prod version and install 32-bit ${_beta}
3. armv8 (RT-AC86U/etc) - backup prod version and install 64-bit ${_beta}
4. restore - revert back to prod version and clean up test directory
Type 1, 2, 3, or 4 to proceed or anything else to quit:
EOF
read ans
echo ""
if [ "$ans" = "4" ]; then
[ ! -L "${_bin}" ] && [ -e "${_bin}" ] && \
echo "pixelserv-tls test version not installed." && exit 1
if [ -h "${_bin}.backup" ]; then
sleep 1
echo "ATTENTION: '"${_bin}.backup"' doesn't seem to be a correct backup."
echo ""
echo "You may have run into a glitch caused by an earlier version (< v0.1.1) of this script."
echo "Auto restore will not proceed. The steps to manually fix:"
echo ""
echo "1. Backup '/opt/etc/init.d/S80pixelserv-tls' by:"
echo ""
echo " mv /opt/etc/init.d/S80pixelserv-tls /opt/etc/init.d/S80pixelserv-tls.backup"
echo ""
echo "2. Force re-install prod version from Entware-ng:"
echo ""
echo " opkg --force-reinstall install pixelserv-tls"
echo ""
echo "3. Restore '/opt/etc/init.d/S80pixelserv-tls' by:"
echo ""
echo " mv /opt/etc/init.d/S80pixelserv-tls.backup /opt/etc/init.d/S80pixelserv-tls"
echo ""
echo "4. Clean up the erroneous backup of 'pixelserv-tls' binary by:"
echo ""
echo " rm -i ${_bin}.backup"
echo ""
echo "5. Restart pixelserv-tls by:"
echo ""
echo " /opt/etc/init.d/S80pixelserv-tls restart"
echo ""
echo "If in doubt, please contact kvic for assistance."
echo ""
exit 1
fi
if [ ! -e "${_bin}.backup" ]; then
sleep 1
echo "ATTENTION: '"${_bin}.backup"' doesn't exist (why?). Auto restore cannot proceed."
echo "You may manually revert back to original state before the very first run of this script."
echo ""
echo "The steps are:"
echo ""
echo "1. Backup '/opt/etc/init.d/S80pixelserv-tls' by:"
echo ""
echo " mv /opt/etc/init.d/S80pixelserv-tls /opt/etc/init.d/S80pixelserv-tls.backup"
echo ""
echo "2. Force re-install prod version from Entware-ng:"
echo ""
echo " opkg --force-reinstall install pixelserv-tls"
echo ""
echo "3. Restore '/opt/etc/init.d/S80pixelserv-tls' by:"
echo ""
echo " mv /opt/etc/init.d/S80pixelserv-tls.backup /opt/etc/init.d/S80pixelserv-tls"
echo ""
echo "4. Restart pixelserv-tls by:"
echo ""
echo " /opt/etc/init.d/S80pixelserv-tls restart"
echo ""
echo "If in doubt, please contact kvic for assistance."
echo ""
exit 1
fi
sleep 1 # pretend we're working hard :-)
(
cd /opt/bin
mv ${_bin}.backup ${_bin} && chmod +x ${_bin}
)
echo "prod version successfully restored."
[ -e "${_tmp}" ] && rm -rf ${_tmp} && echo "Test directory cleaned up"
echo ""
echo "Please restart pixelserv-tls:"
echo ""
echo " /opt/etc/init.d/S80pixelserv-tls restart"
echo ""
exit 0
fi
_arch=""
[ "$ans" = "1" ] && _arch=arm7
[ "$ans" = "2" ] && _arch=mipsel
[ "$ans" = "3" ] && _arch=armv8
if [ "$_arch" = "" ]; then
exit 1
fi
if [ "$_arch" = armv8 ] && [ ! -f /opt/lib/ld-linux-aarch64.so.1 ]; then
echo "This 64-bit armv8 binary is not compatible with your Entware."
echo "You may try \"1. armv7\" on RT-AC86U with 32-bit Entware."
exit 1
fi
if [ "$_arch" = mipsel ] && [ "$_binfavor" = "static" ]; then
echo "Statically linked binary is not available for mipsel. Normal version will be installed instead\n"
_binfavor=dynamic
fi
# check tools
for t in unzip wget; do
_tool=$(which "$t")
if [ "$(basename ${_tool})" != "$t" ] || [ ! -f "${_tool}" ] || [ ! -x "${_tool}" ]; then
echo "Your system doesn't appear to have '${t}' installed."
echo "'${t}' is required to get/install the beta binary file."
echo "You may consider install the Entware-ng's version of '${t}'."
echo ""
echo " opkg install ${t}"
echo ""
echo "then run this script again."
exit 1
fi
done
# check prod version
if [ ! -f ${_bin} -o ! -x ${_bin} ]; then
echo "${_bin} missing or non-executable."
echo ""
echo "Your system doesn't seem to have pixelserv-tls installed."
echo "Please install the prod version from Entware-ng first."
echo ""
echo " opkg install pixelserv-tls"
echo ""
echo "then run this script again."
exit 1
fi
# confirm ?
[ "$_arch" == "arm7" ] && _file=${_arm7z} \
&& _betabin=pixelserv-tls.arm.ent.performance.${_binfavor}
[ "$_arch" == "mipsel" ] && _file=${_mipselz} \
&& _betabin=pixelserv-tls.mips.ent.performance.dynamic
[ "$_arch" == "armv8" ] && _file=${_armv8z} \
&& _betabin=pixelserv-tls.armv8.ent.performance.${_binfavor}
echo "Now we'll attempt to download"
echo ""
echo " ${_file}"
echo "to"
echo " ${_tmp}"
# download the beta version
(
mkdir -p ${_tmp}
cd ${_tmp}
wget -q ${_gpath}/${_tag}/${_file}
if [ "$?" -ne 0 ]; then
echo "Failed to download ${_gpath}/${_tag}/${_file}."
echo "Please check your Internet connectivity."
exit 1
fi
echo ""
echo "Downloaded ${_file}"
echo "Unzipping..."
echo ""
unzip -o ${_file}
[ "$?" -ne 0 ] && echo "Failed to unzip ${_file}" \
&& touch .unzip_failed && exit 1
mv dist/${_betabin} dist/pixelserv-tls-beta
chmod +x dist/pixelserv-tls-beta
echo ""
echo "Unzipped successfully"
)
[ ! -e ${_tmp}/${_file} ] && exit 1
[ -e ${_tmp}/.unzip_failed ] && rm ${_tmp}/.unzip_failed && exit 1
rm ${_tmp}/${_file}
echo ""
echo "Now we'll proceed to backup ${_bin} and install the beta binary"
echo "Type 'yes' to continue.."
echo ""
read ans
[ "$ans" != "yes" ] && echo "You chose not to proceed." \
&& echo "You can manually clean up downloaded files:" \
&& echo "" \
&& echo " rm -rf ${_tmp}" && exit 1
sleep 1 #pretend to be working hard :-)
(
cd /opt/bin
[ ! -e "pixelserv-tls.backup" ] && mv pixelserv-tls pixelserv-tls.backup
ln -sf ${_tmp}/dist/pixelserv-tls-beta pixelserv-tls
)
echo ""
echo "Congratulations. pixelserv-tls ${_beta} is installed."
echo ""
echo "To take immediate effect, restart pixelserv-tls:"
echo ""
echo " /opt/etc/init.d/S80pixelserv-tls restart"
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment