2018-05-27 10:26:34 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#<pre><code>
|
|
|
|
|
2018-06-02 08:25:41 +00:00
|
|
|
# This script does exactly 3 things for 1 good reason:
|
|
|
|
#
|
|
|
|
# What this does:
|
|
|
|
#
|
|
|
|
# 1. Detects either curl or wget and wraps them in helpers
|
|
|
|
# 2. Exports the helpers for the real installer
|
|
|
|
# 3. Downloads and runs the real installer
|
|
|
|
#
|
|
|
|
# Why
|
|
|
|
#
|
|
|
|
# 1. 'curl <smth> | bash -- some args here` breaks interactive input
|
|
|
|
# See https://stackoverflow.com/questions/16854041/bash-read-is-being-skipped-when-run-from-curl-pipe
|
|
|
|
#
|
|
|
|
# 2. It also has practical risks of running a partially downloaded script, which could be dangeresque
|
|
|
|
# See https://news.ycombinator.com/item?id=12767636
|
|
|
|
|
2018-05-27 10:26:34 +00:00
|
|
|
set -e
|
|
|
|
set -u
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# #
|
|
|
|
# http_get #
|
|
|
|
# boilerplate for curl / wget #
|
|
|
|
# #
|
|
|
|
###############################
|
|
|
|
|
|
|
|
# See https://git.coolaj86.com/coolaj86/snippets/blob/master/bash/http-get.sh
|
|
|
|
|
2018-06-01 19:14:59 +00:00
|
|
|
export _my_http_get=""
|
|
|
|
export _my_http_opts=""
|
|
|
|
export _my_http_out=""
|
2018-05-27 10:26:34 +00:00
|
|
|
|
|
|
|
detect_http_get()
|
|
|
|
{
|
|
|
|
set +e
|
|
|
|
if type -p curl >/dev/null 2>&1; then
|
|
|
|
_my_http_get="curl"
|
|
|
|
_my_http_opts="-fsSL"
|
|
|
|
_my_http_out="-o"
|
|
|
|
elif type -p wget >/dev/null 2>&1; then
|
|
|
|
_my_http_get="wget"
|
|
|
|
_my_http_opts="--quiet"
|
|
|
|
_my_http_out="-O"
|
|
|
|
else
|
2019-07-11 04:00:19 +00:00
|
|
|
echo "Failed to find 'curl' or 'wget' to download setup files."
|
2018-05-27 10:26:34 +00:00
|
|
|
return 7
|
|
|
|
fi
|
|
|
|
set -e
|
|
|
|
}
|
|
|
|
|
|
|
|
http_get()
|
|
|
|
{
|
|
|
|
$_my_http_get $_my_http_opts $_my_http_out "$2" "$1"
|
|
|
|
touch "$2"
|
|
|
|
}
|
|
|
|
|
|
|
|
http_bash()
|
|
|
|
{
|
2018-09-25 04:44:39 +00:00
|
|
|
local _http_bash_url=$1
|
|
|
|
local _http_bash_args=${2:-}
|
|
|
|
local _http_bash_tmp=$(mktemp)
|
2018-06-24 05:37:49 +00:00
|
|
|
$_my_http_get $_my_http_opts $_my_http_out "$_http_bash_tmp" "$_http_bash_url"
|
|
|
|
bash "$_http_bash_tmp" $_http_bash_args; rm "$_http_bash_tmp"
|
2018-05-27 10:26:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
detect_http_get
|
2018-06-02 09:30:13 +00:00
|
|
|
export -f http_get
|
|
|
|
export -f http_bash
|
2018-05-27 10:26:34 +00:00
|
|
|
|
|
|
|
###############################
|
|
|
|
## END HTTP_GET ##
|
|
|
|
###############################
|
|
|
|
|
2019-07-11 02:45:36 +00:00
|
|
|
# Priority
|
|
|
|
#darwin-x64 tar.gz 28-May-2019 21:25 17630540
|
|
|
|
#linux-arm64 tar.gz 28-May-2019 21:14 20114146
|
|
|
|
#linux-armv6l tar.gz 28-May-2019 21:19 19029391
|
|
|
|
#linux-armv7l tar.gz 28-May-2019 21:22 18890540
|
|
|
|
#linux-x64 tar.gz 28-May-2019 21:36 20149492
|
|
|
|
#win-x64 zip 28-May-2019 22:08 17455164
|
|
|
|
#win-x86 zip 28-May-2019 21:57 15957629
|
|
|
|
|
|
|
|
# TODO
|
|
|
|
#aix-ppc64 tar.gz 28-May-2019 21:45 24489408
|
|
|
|
#linux-ppc64le tar.gz 28-May-2019 21:18 20348655
|
|
|
|
#linux-s390x tar.gz 28-May-2019 21:19 20425501
|
|
|
|
#sunos-x64 tar.gz 28-May-2019 21:19 21382759
|
|
|
|
#... cygwin?
|
|
|
|
|
|
|
|
# Extra
|
|
|
|
#x64 msi 28-May-2019 22:09 18186240
|
|
|
|
#x86 msi 28-May-2019 21:57 16601088
|
|
|
|
#(darwin) pkg 28-May-2019 21:22 17869062
|
|
|
|
|
|
|
|
###############################
|
|
|
|
## PLATFORM DETECTION ##
|
|
|
|
###############################
|
|
|
|
|
2019-07-11 02:48:15 +00:00
|
|
|
echo "Detecting your system..."
|
|
|
|
sleep 0.5
|
|
|
|
echo ""
|
|
|
|
|
2019-07-11 02:45:36 +00:00
|
|
|
# OSTYPE https://stackoverflow.com/a/8597411/151312
|
|
|
|
|
|
|
|
my_os=''
|
2019-07-11 04:00:19 +00:00
|
|
|
my_os_friendly=''
|
2019-07-11 02:45:36 +00:00
|
|
|
my_arch=''
|
2019-07-11 04:00:19 +00:00
|
|
|
my_arch_friendly=''
|
2019-07-11 02:45:36 +00:00
|
|
|
if [ "$(uname | grep -i 'Darwin')" ]; then
|
|
|
|
#OSX_VER="$(sw_vers | grep ProductVersion | cut -d':' -f2 | cut -f2)"
|
|
|
|
#OSX_MAJOR="$(echo ${OSX_VER} | cut -d'.' -f1)"
|
|
|
|
my_os='darwin'
|
2019-07-11 04:00:19 +00:00
|
|
|
my_os_friendly='MacOS'
|
2019-07-11 02:45:36 +00:00
|
|
|
#if [ -n "$(sysctl hw | grep 64bit | grep ': 1')" ]; then
|
|
|
|
# my_arch="amd64"
|
|
|
|
#fi
|
2019-07-11 04:00:19 +00:00
|
|
|
my_unarchiver="tar"
|
2019-07-11 02:45:36 +00:00
|
|
|
elif [ "$(uname | grep -i 'MING')" ] || [[ "$OSTYPE" == "msys" ]]; then
|
|
|
|
my_os='windows'
|
2019-07-11 04:00:19 +00:00
|
|
|
# although it's not quite our market, many people don't know if they have "microsoft" OR "windows"
|
|
|
|
my_os_friendly='Microsoft Windows'
|
|
|
|
my_unarchiver="unzip"
|
2019-07-11 02:45:36 +00:00
|
|
|
elif [ "$(uname | grep -i 'Linux')" ] || [[ "$OSTYPE" == "linux-gnu" ]]; then
|
|
|
|
my_os='linux'
|
2019-07-11 04:00:19 +00:00
|
|
|
my_os_friendly='Linux'
|
2019-07-11 02:45:36 +00:00
|
|
|
# Find out which linux... but there are too many
|
|
|
|
#cat /etc/issue
|
2019-07-11 04:00:19 +00:00
|
|
|
my_unarchiver="tar"
|
2019-07-11 02:45:36 +00:00
|
|
|
else
|
|
|
|
>&2 echo "You don't appear to be on Mac (darwin), Linux, or Windows (mingw32)."
|
|
|
|
>&2 echo "Help us support your platform by filing an issue:"
|
|
|
|
>&2 echo " https://git.rootprojects.org/root/telebit.js/issues"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-07-11 04:00:19 +00:00
|
|
|
export _my_unarchiver=""
|
|
|
|
export _my_unarchive_opts=""
|
|
|
|
export _my_unarchive_out=""
|
|
|
|
export archive_ext=""
|
|
|
|
|
|
|
|
detect_unarchiver()
|
|
|
|
{
|
|
|
|
set +e
|
|
|
|
if type -p "$my_unarchiver" >/dev/null 2>&1; then
|
|
|
|
if type -p tar >/dev/null 2>&1; then
|
|
|
|
_my_unarchiver="tar"
|
|
|
|
_my_unarchive_opts="-xf"
|
|
|
|
_my_unarchive_out="-C"
|
|
|
|
archive_ext="tar.gz"
|
|
|
|
elif type -p unzip >/dev/null 2>&1; then
|
|
|
|
_my_unarchiver="unzip"
|
|
|
|
_my_unarchive_opts="-qq"
|
|
|
|
_my_unarchive_out="-d"
|
|
|
|
archive_ext="zip"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Failed to find '$my_unarchiver' which is needed to unpack downloaded files."
|
|
|
|
return 21
|
|
|
|
fi
|
|
|
|
set -e
|
|
|
|
}
|
|
|
|
|
|
|
|
unarchiver()
|
|
|
|
{
|
|
|
|
$_my_unarchiver $_my_unarchive_opts "$1" $_my_unarchive_out "$2"
|
|
|
|
}
|
|
|
|
|
|
|
|
detect_unarchiver
|
|
|
|
export -f unarchiver
|
|
|
|
|
|
|
|
|
2019-07-11 02:45:36 +00:00
|
|
|
if [ "$(uname -m | grep -i 'ARM')" ]; then
|
|
|
|
if [ "$(uname -m | grep -i 'v5')" ]; then
|
|
|
|
my_arch="armv5"
|
|
|
|
elif [ "$(uname -m | grep -i 'v6')" ]; then
|
|
|
|
my_arch="armv6"
|
|
|
|
elif [ "$(uname -m | grep -i 'v7')" ]; then
|
|
|
|
my_arch="armv7"
|
|
|
|
elif [ "$(uname -m | grep -i 'v8')" ]; then
|
|
|
|
my_arch="armv8"
|
|
|
|
elif [ "$(uname -m | grep -i '64')" ]; then
|
|
|
|
my_arch="armv8"
|
|
|
|
fi
|
|
|
|
elif [ "$(uname -m | grep -i '86')" ]; then
|
|
|
|
if [ "$(uname -m | grep -i '64')" ]; then
|
|
|
|
my_arch="amd64"
|
2019-07-11 04:00:19 +00:00
|
|
|
my_arch_friendly="64-bit"
|
2019-07-11 02:45:36 +00:00
|
|
|
else
|
|
|
|
my_arch="386"
|
2019-07-11 04:00:19 +00:00
|
|
|
my_arch_friendly="32-bit"
|
2019-07-11 02:45:36 +00:00
|
|
|
fi
|
|
|
|
elif [ "$(uname -m | grep -i '64')" ]; then
|
|
|
|
my_arch="amd64"
|
2019-07-11 04:00:19 +00:00
|
|
|
my_arch_friendly="64-bit"
|
2019-07-11 02:45:36 +00:00
|
|
|
else
|
|
|
|
>&2 echo "Your CPU doesn't appear to be 386, amd64 (x64), armv6, armv7, or armv8 (arm64)."
|
|
|
|
>&2 echo "Help us support your platform by filing an issue:"
|
|
|
|
>&2 echo " https://git.rootprojects.org/root/telebit.js/issues"
|
2018-07-08 01:08:14 +00:00
|
|
|
fi
|
2019-07-11 02:45:36 +00:00
|
|
|
|
|
|
|
export TELEBIT_ARCH="$my_arch"
|
|
|
|
export TELEBIT_OS="$my_os"
|
|
|
|
TELEBIT_VERSION=${TELEBIT_VERSION:-stable}
|
|
|
|
export TELEBIT_RELEASE=${TELEBIT_RELEASE:-$TELEBIT_VERSION}
|
2019-07-11 04:00:19 +00:00
|
|
|
export TELEBIT_ARCHIVER="$my_unarchiver"
|
2019-07-11 02:45:36 +00:00
|
|
|
|
2019-07-11 04:00:19 +00:00
|
|
|
echo " Operating System: $my_os_friendly"
|
|
|
|
echo " Processor Family: ${my_arch_friendly:-$my_arch}"
|
|
|
|
echo " Download Type: $archive_ext"
|
|
|
|
echo " Release Channel: $TELEBIT_VERSION"
|
2019-07-11 02:45:36 +00:00
|
|
|
echo ""
|
|
|
|
sleep 0.3
|
|
|
|
echo "Downloading the Telebit installer for your system..."
|
|
|
|
sleep 0.5
|
|
|
|
echo ""
|
|
|
|
|
2019-08-10 04:12:41 +00:00
|
|
|
#if [ -e "usr/share/install_helper.sh" ]; then
|
|
|
|
# bash usr/share/install_helper.sh "$@"
|
|
|
|
#else
|
|
|
|
# http_bash https://git.coolaj86.com/coolaj86/telebit.js/raw/branch/$TELEBIT_VERSION/usr/share/install_helper.sh "$@"
|
|
|
|
#fi
|
|
|
|
|
|
|
|
mkdir -p $HOME/Downloads
|
|
|
|
my_tmp="$(mktemp -d -t telebit.XXXX)"
|
|
|
|
|
|
|
|
http_get "https://rootprojects.org/telebit/dist/index.tab" "$my_tmp/index.tab"
|
|
|
|
meta=$(grep $TELEBIT_RELEASE $my_tmp/index.tab | grep $TELEBIT_OS | grep $TELEBIT_ARCH | head -n 1)
|
|
|
|
latest=$(echo "$meta" | cut -f 1)
|
|
|
|
major=$(grep $TELEBIT_RELEASE $my_tmp/index.tab | grep $TELEBIT_OS | grep $TELEBIT_ARCH | head -n 1 | cut -f 2)
|
|
|
|
size=$(grep $TELEBIT_RELEASE $my_tmp/index.tab | grep $TELEBIT_OS | grep $TELEBIT_ARCH | head -n 1 | cut -f 3)
|
|
|
|
t_sha256=$(grep $TELEBIT_RELEASE $my_tmp/index.tab | grep $TELEBIT_OS | grep $TELEBIT_ARCH | head -n 1 | cut -f 4)
|
|
|
|
t_channel=$(grep $TELEBIT_RELEASE $my_tmp/index.tab | grep $TELEBIT_OS | grep $TELEBIT_ARCH | head -n 1 | cut -f 5)
|
|
|
|
t_os=$(grep $TELEBIT_RELEASE $my_tmp/index.tab | grep $TELEBIT_OS | grep $TELEBIT_ARCH | head -n 1 | cut -f 6)
|
|
|
|
t_arch=$(grep $TELEBIT_RELEASE $my_tmp/index.tab | grep $TELEBIT_OS | grep $TELEBIT_ARCH | head -n 1 | cut -f 7)
|
|
|
|
t_url=$(grep $TELEBIT_RELEASE $my_tmp/index.tab | grep $TELEBIT_OS | grep $TELEBIT_ARCH | head -n 1 | cut -f 8)
|
|
|
|
|
|
|
|
my_dir="telebit-$latest-$TELEBIT_OS-$TELEBIT_ARCH"
|
|
|
|
my_file="$my_dir.$archive_ext"
|
|
|
|
if [ -f "$HOME/Downloads/$my_file" ]; then
|
|
|
|
my_size=$(($(wc -c < "$HOME/Downloads/$my_file")))
|
|
|
|
if [ "$my_size" -eq "$size" ]; then
|
2019-08-10 07:34:39 +00:00
|
|
|
echo "~/Downloads/ exists, skipping download"
|
2019-08-10 04:12:41 +00:00
|
|
|
else
|
|
|
|
echo "Removing corrupt download '~/Downloads/$my_file'"
|
2019-08-10 07:34:39 +00:00
|
|
|
# change into $HOME because we don't ever want to perform
|
|
|
|
# a destructive action on a variable we didn't set
|
|
|
|
pushd "$HOME"
|
|
|
|
rm -f "Downloads/$my_file"
|
|
|
|
popd
|
2019-08-10 04:12:41 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f "$HOME/Downloads/$my_file" ]; then
|
|
|
|
#echo "Downloading from https://rootprojects.org/telebit/dist/$major/$my_file ..."
|
|
|
|
echo "Downloading from $t_url ..."
|
|
|
|
sleep 0.3
|
|
|
|
#http_get "https://rootprojects.org/telebit/dist/$major/$my_file" "$HOME/Downloads/$my_file"
|
|
|
|
http_get "$t_url" "$HOME/Downloads/$my_file"
|
|
|
|
echo "Saved to '$HOME/Downloads/$my_file' ..."
|
|
|
|
echo ""
|
|
|
|
sleep 0.3
|
2018-05-27 10:26:34 +00:00
|
|
|
fi
|
2019-08-10 04:12:41 +00:00
|
|
|
|
|
|
|
echo "Unpacking and installing Telebit ..."
|
2019-08-10 07:34:39 +00:00
|
|
|
unarchiver "$HOME/Downloads/$my_file" "$my_tmp"
|
|
|
|
echo "extracting '$my_file' to '$my_tmp'"
|
|
|
|
|
|
|
|
# make sure that telebit is not in use
|
|
|
|
pushd "$my_tmp" > /dev/null
|
|
|
|
./bin/node ./bin/npm --scripts-prepend-node-path=true run preinstall
|
|
|
|
popd > /dev/null
|
|
|
|
|
|
|
|
# move only once there are not likely to be any open files
|
|
|
|
# (especially important on windows)
|
|
|
|
pushd "$HOME" > /dev/null
|
|
|
|
if [ -e ".local/opt/telebit" ]; then
|
|
|
|
mv ".local/opt/telebit" ".local/opt/telebit-old-$(date "+%s")"
|
|
|
|
fi
|
|
|
|
mv "$my_tmp" ".local/opt/telebit"
|
|
|
|
popd > /dev/null
|
|
|
|
|
|
|
|
# make sure that telebit is not in use
|
|
|
|
pushd "$HOME/.local/opt/telebit" > /dev/null
|
|
|
|
./node_modules/.bin/pathman add "$HOME/.local/opt/telebit/bin-public" > /dev/null
|
|
|
|
./bin/node ./bin/npm --scripts-prepend-node-path=true run postinstall
|
|
|
|
popd > /dev/null
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo ""
|
|
|
|
echo ""
|
|
|
|
echo "Open a new terminal and run the following:"
|
|
|
|
echo ""
|
|
|
|
printf "\ttelebit init"
|
|
|
|
echo ""
|