Skip to content

Instantly share code, notes, and snippets.

@robinvanemden
Last active April 21, 2023 08:51
Embed
What would you like to do?
#!/bin/bash
# run as:
#
# sudo bash -c "$(wget -q -O - https://get.sclbl.net)"
#
echo "==========================================================================="
echo "= Welcome to the Scailable Edge AI Manager installer ="
echo "==========================================================================="
echo ""
if ! type "killall" >/dev/null 2>&1; then
if ! type "pkill" >/dev/null 2>&1; then
echo ""
echo 'Error: The POSIX "killall" or "pkill" commands cannot be found. Please install and try again.' >&2
exit 1
else
echo ""
echo " * Stop sclbl processes if running [pkill]. "
# kill running processes if exist
pkill -15 uiprovider 2>/dev/null
pkill -15 sclblmod 2>/dev/null
pkill -15 sclbld 2>/dev/null
pkill -15 sclbl-output-distributor 2>/dev/null
echo ""
fi
else
echo ""
echo " * Stop sclbl processes if running [killall]. "
# kill running processes if exist
killall uiprovider 2>/dev/null
killall sclblmod 2>/dev/null
killall sclbld 2>/dev/null
killall sclbl-output-distributor 2>/dev/null
echo ""
fi
if ! type "uname" >/dev/null 2>&1; then
echo 'Error: The POSIX "uname" command cannot be found. Please install and try again.' >&2
exit 1
fi
if ! type "wget" >/dev/null 2>&1; then
echo 'Error: The POSIX "wget" command cannot be found. Please install and try again.' >&2
exit 1
fi
if ! type "tar" >/dev/null 2>&1; then
echo 'Error: The POSIX "tar" command cannot be found. Please install and try again.' >&2
exit 1
fi
if ! type "sed" >/dev/null 2>&1; then
echo 'Error: The POSIX "sed" command cannot be found. Please install and try again.' >&2
exit 1
fi
if ! type "grep" >/dev/null 2>&1; then
echo 'Error: The POSIX "grep" command cannot be found. Please install and try again.' >&2
exit 1
fi
if [ "$(id -u)" -ne 0 ]; then
echo 'Please run as root.' >&2
exit 1
fi
function get_architecture {
if uname -m | grep -qx "alpha"; then
echo "alpha"
elif uname -m | grep -q "armv4"; then
echo "armv4"
elif uname -m | grep -q "armv5"; then
echo "armv5"
elif uname -m | grep -q "armv6"; then
if grep -q vfp /proc/cpuinfo; then
echo "armv6hf"
else
echo "armv6"
fi
elif uname -m | grep -q "armv7"; then
if grep -q vfp /proc/cpuinfo; then
echo "armv7hf"
else
echo "armv7"
fi
elif uname -m | grep -q "aarch64"; then
echo "aarch64"
elif uname -m | grep -qx "i386"; then
echo "i386"
elif uname -m | grep -qx "i686"; then
echo "i686"
elif uname -m | grep -qx "mips"; then
echo "mips"
elif uname -m | grep -qx "ppc"; then
echo "ppc"
elif uname -m | grep -qx "ppc64"; then
echo "ppc64"
elif uname -m | grep -qx "sparc64"; then
echo "sparc64"
elif uname -m | grep -qx "x86_64"; then
echo "x86_64"
elif uname -m | grep -qx "amd64"; then
echo "x86_64"
else
echo "unknown"
fi
}
archurl=$(get_architecture)
case ${archurl} in
aarch64) archurl="arm64" ;;
arm64) archurl="arm64" ;;
armv7hf) archurl="arm32" ;;
armv7) archurl="arm32" ;;
x86_64) archurl="x86_64" ;;
*)
echo " * Unsupported architecture ${archurl}."
exit 1
;;
esac
platform='unknown'
unamestr=$(uname)
if [ "$unamestr" = 'Linux' ]; then
platform='linux'
elif [ "$unamestr" = 'FreeBSD' ]; then
platform='freebsd'
fi
echo " * Your device's architecture is ${archurl}."
echo " * Your device's platform is ${platform}."
special=""
if [ "$archurl" == "arm64" ]; then
if uname -a | grep -q "tegra" || grep -s -q "CUDA" /usr/local/cuda/version.txt; then
if grep -s -q "ICAM" /opt/version; then
echo -n ' * Advantech ICAM with CUDA support detected'
special="-icam-cuda"
else
if grep -s -q "CUDA" /usr/local/cuda/version.txt; then
cat /usr/local/cuda/version.txt | sed 's/^/ \* NVIDIA acceleration found: /'
fi
echo -n " * Would you like to enable CUDA support? (y/n)? "
read answer
finish="-1"
while [ "$finish" = '-1' ]; do
finish="1"
if [ "$answer" = '' ]; then
answer=""
else
case $answer in
y | Y | yes | YES) answer="y" ;;
n | N | no | NO) answer="n" ;;
*)
finish="-1"
echo -n ' * Invalid response -- please reenter:'
read answer
;;
esac
fi
done
if [ "$answer" = 'y' ]; then
special="-cuda"
fi
fi
fi
if uname -a | grep -q "scailx"; then
echo -n " * Would you like to select the Videology distribution? (y/n)? "
read answer
finish="-1"
while [ "$finish" = '-1' ]; do
finish="1"
if [ "$answer" = '' ]; then
answer=""
else
case $answer in
y | Y | yes | YES) answer="y" ;;
n | N | no | NO) answer="n" ;;
*)
finish="-1"
echo -n ' * Invalid response -- please reenter:'
read answer
;;
esac
fi
done
if [ "$answer" = 'y' ]; then
special="-videology"
fi
fi
fi
echo ""
echo " * Start downloading package lonelinux-sclbl-${archurl}${special}.tgz."
echo ""
echo "----------------------------------------------------------------------------"
echo ""
# if /opt doesn't exist, create it
mkdir -p /opt
# get sclbl package
wget --help 2> /dev/null | grep -q '\--show-progress' >/dev/null 2>&1 &&
_PROGRESS_OPT="-q --show-progress --inet4-only --no-check-certificate " || _PROGRESS_OPT="-q"
wget --no-check-certificate $_PROGRESS_OPT https://u330311-sub1:wP5dyndg9cxqwQyO@u330311-sub1.your-storagebox.de/lonelinux-sclbl-${archurl}${special}.tgz -O sclbl.tgz | sed 's/^/ \* /'
echo ""
echo "----------------------------------------------------------------------------"
file=sclbl.tgz
minimumsize=8000000 # 8mb
if [ ! -f "$file" ]; then
echo ""
echo " * Error: Download of lonelinux-sclbl-${archurl}${special}.tgz failed." >&2
echo ""
exit 1
fi
actualsize=$(wc -c <"$file")
if [ $actualsize -ge $minimumsize ]; then
echo ""
echo " * Download of lonelinux-sclbl-${archurl}${special}.tgz succesfull."
else
echo ""
echo " * Download of lonelinux-sclbl-${archurl}${special}.tgz failed." >&2
echo ""
exit 1
fi
# extract the sclbl standalone package to /opt
echo " * Extracting lonelinux-sclbl-${archurl}${special}.tgz to /opt/sclbl."
echo ""
if tar xfz *sclbl*tgz -C /opt
then
echo " * Extracted lonelinux-sclbl-${archurl}${special}.tgz succesfully."
echo ""
else
echo ""
echo " * Error: Extraction of lonelinux-sclbl-${archurl}${special}.tgz failed." >&2
echo ""
exit 1
fi
# delete the tgz
rm *sclbl*tgz
echo " * Creating settings file if not exists."
false | cp -i /opt/sclbl/etc/defaults.json /opt/sclbl/etc/settings.json 2>/dev/null
echo " * Add updated defaults."
/opt/sclbl/bin/jq '. * input' /opt/sclbl/etc/defaults.json /opt/sclbl/etc/settings.json > \
/opt/sclbl/etc/settings.json.tmp && mv /opt/sclbl/etc/settings.json.tmp /opt/sclbl/etc/settings.json
if [[ "$0" == *"installer"* ]]; then
echo " * Local install skip inserting settings"
else
if [[ "$0" -eq "args" ]]; then
echo " * Insert settings."
for ARGUMENT in "$@"
do
KEY=$(echo $ARGUMENT | cut -f1 -d=)
KEY_LENGTH=${#KEY}
VALUE="${ARGUMENT:$KEY_LENGTH+1}"
# export "$KEY"="$VALUE"
echo " * $KEY=$VALUE"
/opt/sclbl/bin/jq ".settings.$KEY |= \"$VALUE\"" /opt/sclbl/etc/settings.json > /opt/sclbl/etc/settings.json.tmp && mv /opt/sclbl/etc/settings
done
fi
fi
echo " * Creating cache directory."
mkdir -p /var/cache/sclbl
echo " * Update hosts file."
sed -i "/admin.sclbl.net/d" /etc/hosts
echo '116.202.181.244 admin.sclbl.net' >> /etc/hosts
sed -i "/cdn.sclbl.net/d" /etc/hosts
echo '116.202.181.244 cdn.sclbl.net' >> /etc/hosts
sed -i "/usermanager.sclbl.net/d" /etc/hosts
echo '116.202.181.244 usermanager.sclbl.net' >> /etc/hosts
sed -i "/rest.sclbl.net/d" /etc/hosts
echo '78.47.205.187 rest.sclbl.net' >> /etc/hosts
echo " * Initializing settings file."
/opt/sclbl/bin/uiprovider serial >/dev/null 2>&1
echo " * Starting UI server."
echo ""
echo "==========================================================================="
echo "= The Scailable AI manager has been installed in /opt/sclbl ="
echo "==========================================================================="
echo ""
# start the ui server on http port 8081 https 8443
# and the outputdistributor on localhost port 8012
cd /opt/sclbl/etc
chmod 775 init
./init startui
echo ""
echo "==========================================================================="
echo "= The Scailable AI manager has been started ="
echo "==========================================================================="
echo ""
if type "crontab" >/dev/null 2>&1; then
if grep "sclbl" /etc/crontab >/dev/null 2>&1; then
echo " * The Scailable Edge AI Manager has been set to autostart on boot.";
else
echo -n " * Would you like to enable autostart on boot through /etc/crontab? (y/n)? "
read answer
finish="-1"
while [ "$finish" = '-1' ]; do
finish="1"
if [ "$answer" = '' ]; then
answer=""
else
case $answer in
y | Y | yes | YES) answer="y" ;;
n | N | no | NO) answer="n" ;;
*)
finish="-1"
echo -n ' * Invalid response -- please reenter:'
read answer
;;
esac
fi
done
if [ "$answer" = 'y' ]; then
echo '@reboot root /opt/sclbl/etc/init startui' >> /etc/crontab
echo " * The Scailable Edge AI Manager will now autostart on boot.";
fi
fi
fi
echo ""
echo "==========================================================================="
echo "= Go to http://localhost:8081 or ="
echo "= https://localhost:8443 to access the Scailable Edge AI Manager ="
echo "==========================================================================="
echo ""
if type "ip" >/dev/null 2>&1; then
echo "Autodetected alternative URLs:"
echo ""
arr=$(ip addr | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p')
for address in $arr; do echo " * http://${address}:8081"; done
for address in $arr; do echo " * https://${address}:8443"; done
echo ""
elif type "ifconfig" >/dev/null 2>&1; then
echo "Autodetected alternative URLs:"
echo ""
arr=$(ifconfig | grep -v inet6 | grep -v 127.0.0.1 | awk -v i=$i '/inet6?/{print i "" $2}')
for address in $arr; do echo " * http://${address}:8081"; done
for address in $arr; do echo " * https://${address}:8443"; done
echo ""
fi
echo "Start and stop the Scailable Edge AI Manager with respectively:"
echo ""
echo " $ sudo /opt/sclbl/etc/init startui"
echo " $ sudo /opt/sclbl/etc/init stopui"
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment