Skip to content

Instantly share code, notes, and snippets.

@robinvanemden
Last active October 2, 2022 16:01
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 robinvanemden/c1ba9ab0c0073ffb072eb924d3e530e3 to your computer and use it in GitHub Desktop.
Save robinvanemden/c1ba9ab0c0073ffb072eb924d3e530e3 to your computer and use it in GitHub Desktop.
#!/bin/bash
# run as:
#
# sudo bash -c "$(wget -q -O - https://bit.ly/3UYetgs)"
if [ "$(id -u)" -ne 0 ]; then
echo 'Please run as root.' >&2
exit 1
fi
echo ""
echo "==========================================================================="
echo "= Install PTPD as master and make sure it starts on boot ="
echo "==========================================================================="
echo ""
# install ptpd
REQUIRED_PKG="ptpd"
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $REQUIRED_PKG|grep "install ok installed")
echo Checking for $REQUIRED_PKG: $PKG_OK
if [ "" = "$PKG_OK" ]; then
echo "No $REQUIRED_PKG. Setting up $REQUIRED_PKG."
sudo apt-get --yes install $REQUIRED_PKG
fi
# make sure correct settings ptpd server
cat > /etc/default/ptpd << EOF
# /etc/default/ptpd
# Set to "yes" to actually start ptpd automatically
START_DAEMON=yes
# Add command line options for ptpd
PTPD_OPTS="-M -V -i eth0"
EOF
# set timezone
timedatectl set-timezone Europe/Amsterdam
#(re)start ptpd
/etc/init.d/ptpd start
echo ""
echo "==========================================================================="
echo "= Check some basic settings ="
echo "==========================================================================="
echo ""
if ! type "killall" >/dev/null 2>&1; then
echo 'Error: The POSIX "killall" command cannot be found. Please install and try again.' >&2
exit 1
fi
echo ""
# 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 ""
echo "==========================================================================="
echo "= Welcome to the BBLeap | Scailable Edge AI Manager installer ="
echo "==========================================================================="
echo ""
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
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="-bbleap"
if [ "$archurl" == "arm64" ]; then
if uname -a | grep -q "tegra" || grep -s -q "CUDA" /usr/local/cuda/version.txt; then
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="-bbleap-cuda"
fi
fi
fi
echo ""
echo " * Start downloading package."
echo ""
echo "----------------------------------------------------------------------------"
echo ""
# if /opt doesn't exist, create it
mkdir -p /opt
# get sclbl package
wget --help | grep -q '\--show-progress' >/dev/null 2>&1 &&
_PROGRESS_OPT="-q --show-progress --inet4-only --no-check-certificate " || _PROGRESS_OPT="-q"
wget $_PROGRESS_OPT https://github.com/scailable/sclbl-tutorials/blob/master/downloads/files/lonelinux-sclbl-${archurl}${special}.tgz?raw=true -O sclbl.tgz | sed 's/^/ \* /'
echo ""
echo "----------------------------------------------------------------------------"
file=sclbl.tgz
minimumsize=1000000 # 1mb
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."
echo ""
exit 1
fi
# extract the sclbl standalone package to /opt
echo " * Extracting lonelinux-sclbl-${archurl}${special}.tgz to /opt/sclbl."
echo ""
tar xfz *sclbl*tgz -C /opt
# delete the tgz
rm *sclbl*tgz
echo " * Creating settings file if not exists."
cp -n /opt/sclbl/etc/defaults /opt/sclbl/etc/settings
echo " * Creating cache directory."
mkdir -p /var/cache/sclbl
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 '@reboot root /opt/sclbl/etc/init startui' >> /etc/crontab
echo " * The Scailable Edge AI Manager will now autostart on boot.";
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