root@Bticino_Classe_300_X:~# cat /etc/init.d/bt_daemon-apps.sh #!/bin/bash # # Copyright © 2018 Bticino s.p.a. # Author: Angelo Aresi # # This script is free software: you can redistribute it and/or modify it under # the terms of the GNU Lesser General Public License as published by the # Free Software Foundation, either version 3 of the License, or (at your # option) any later version. set -o errexit set -o pipefail set -o nounset USBKEY_BASEDIR=/home/bticino/cfg/extra DIR_USBKEY=${USBKEY_BASEDIR}/usbkey_dir FILE_USBKEY=${USBKEY_BASEDIR}/usbkey USER_LIBDIR=${DIR_USBKEY}/lib SIP_USER_DIR=/home/bticino/cfg/extra/90/flexisip/users/ ASWM_CFG_FILE=/home/bticino/cfg/extra/47/aswm_settings.ini FW_VER_FILE=$USBKEY_BASEDIR/.license_ver if [ "${1+z}" != "" ]; then [ "$1" == "stop" ] && ACT=$1"ping" || ACT=${1}"ing" echo "Bticino APPS "${ACT} fi function setup_usbkey() { FW_V=$(awk -F'[<>]' '// { print $3}' /home/bticino/sp/dbfiles_ws.xml) || true OLD_FW_V=$(cat $FW_VER_FILE) || true if [ "$FW_V" != "$OLD_FW_V" ]; then rm -rf $DIR_USBKEY || true fi if [ -d "$DIR_USBKEY" ]; then # if lib dir is empty run full apps, otherwise run minimal ops losetup /dev/loop2 $FILE_USBKEY || true mount -o sync /dev/loop2 $DIR_USBKEY || true if [ "$(ls -A $USER_LIBDIR)" ]; then echo "Take action $USER_LIBDIR is not Empty: reduced ops" rm /var/tmp/stack_open.xml || true ln -s /home/bticino/cfg/stack_open_reduced.xml /var/tmp/stack_open.xml || true rm -rf ${SIP_USER_DIR}/* || true sed -i '/SipUsers/d' $ASWM_CFG_FILE fi fi if [ ! -d "$DIR_USBKEY" ] || [ ! -d "$DIR_USBKEY/common-licenses" ]; then # executed only one time in runlevel 5 to export licenses dd if=/dev/zero of=$FILE_USBKEY bs=1M count=50 || true mkfs.vfat $FILE_USBKEY || true fatlabel $FILE_USBKEY C300X || true losetup /dev/loop2 $FILE_USBKEY || true mkdir ${DIR_USBKEY} >/dev/null 2>&1 || true mount -o sync /dev/loop2 $DIR_USBKEY || true mkdir ${DIR_USBKEY}/common-licenses >/dev/null 2>&1 || true cd /usr/share/common-licenses >/dev/null 2>&1 || true tar -czf ${DIR_USBKEY}/common-licenses/common-licenses.tar.gz * >/dev/null 2>&1 || true echo "$FW_V" > $FW_VER_FILE chmod -w -R $DIR_USBKEY/common-licenses >/dev/null 2>&1 || true cp /home/bticino/cfg/README $DIR_USBKEY/README >/dev/null 2>&1 || true cp /home/bticino/cfg/ReadMe_OSS_C300X.tar.gz $DIR_USBKEY/ReadMe_OSS_C300X.tar.gz >/dev/null 2>&1 || true sync >/dev/null 2>&1 || true fi } function wait_extra() { S=$(( SECONDS + 10 )) while [ $SECONDS -lt $S ]; do FOUND=1 mount | grep extra -q || FOUND=0 if [ "$FOUND" == "1" ]; then break fi echo "waiting extra partition to be mounted" done if [ "$FOUND" == "0" ]; then echo "===> extra partition NOT MOUNTED: giving-up" fi } start() { export LD_LIBRARY_PATH=${USER_LIBDIR}:/home/bticino/lib:/home/bticino/libcoso /bin/bt_hosts.sh add localhost 127.0.0.1 /bin/bt_hosts.sh add openserver 127.0.0.1 /bin/bt_hosts.sh add 192.168.1.150 cd /home/bticino bin/bt_daemon & } stop() { APP=$(ls /home/bticino/bin/ | grep -v openserver) for ap in $APP; do P="$(/bin/pidof "$ap")" || true if [ -z "$P" ]; then continue fi for pid in $P; do PATH="/proc/"$pid"/maps" /bin/grep -q acca $PATH if [ $? == 0 ]; then kill $pid fi done done } case "$1" in start) wait_extra setup_usbkey start & ;; stop) stop ;; *) wait_extra echo $"Usage: $0 {start|stop} ${1+x}" exit 1 esac exit 0