Facebook
From 300x, 5 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 136
  1. root@Bticino_Classe_300_X:~# cat /etc/init.d/bt_daemon-apps.sh
  2. #!/bin/bash
  3. #
  4. # Copyright © 2018 Bticino s.p.a.
  5. # Author: Angelo Aresi <[email protected]>
  6. #
  7. # This script is free software: you can redistribute it and/or modify it under
  8. # the terms of the GNU Lesser General Public License as published by the
  9. # Free Software Foundation, either version 3 of the License, or (at your
  10. # option) any later version.
  11.  
  12. set -o errexit
  13. set -o pipefail
  14. set -o nounset
  15.  
  16. USBKEY_BASEDIR=/home/bticino/cfg/extra
  17. DIR_USBKEY=${USBKEY_BASEDIR}/usbkey_dir
  18. FILE_USBKEY=${USBKEY_BASEDIR}/usbkey
  19. USER_LIBDIR=${DIR_USBKEY}/lib
  20. SIP_USER_DIR=/home/bticino/cfg/extra/90/flexisip/users/
  21. ASWM_CFG_FILE=/home/bticino/cfg/extra/47/aswm_settings.ini
  22. FW_VER_FILE=$USBKEY_BASEDIR/.license_ver
  23.  
  24. if [ "${1+z}" != "" ]; then
  25.         [ "$1" == "stop" ] && ACT=$1"ping" || ACT=${1}"ing"
  26.         echo "Bticino APPS "${ACT}
  27. fi
  28.  
  29. function setup_usbkey() {
  30.         FW_V=$(awk -F'[<>]' '/<ver_webserver>/ { print $3}' /home/bticino/sp/dbfiles_ws.xml) || true
  31.         OLD_FW_V=$(cat $FW_VER_FILE) || true
  32.         if [ "$FW_V" != "$OLD_FW_V" ]; then
  33.                 rm -rf $DIR_USBKEY || true
  34.         fi
  35.  
  36.         if [ -d "$DIR_USBKEY" ]; then
  37.                 # if lib dir is empty run full apps, otherwise run minimal ops
  38.                 losetup /dev/loop2 $FILE_USBKEY || true
  39.                 mount -o sync /dev/loop2 $DIR_USBKEY || true
  40.                 if [ "$(ls -A $USER_LIBDIR)" ]; then
  41.                         echo "Take action $USER_LIBDIR is not Empty: reduced ops"
  42.                         rm /var/tmp/stack_open.xml || true
  43.                         ln -s /home/bticino/cfg/stack_open_reduced.xml /var/tmp/stack_open.xml || true
  44.                         rm -rf ${SIP_USER_DIR}/* || true
  45.                         sed -i '/SipUsers/d' $ASWM_CFG_FILE
  46.                 fi
  47.         fi
  48.         if [ ! -d "$DIR_USBKEY" ] || [ ! -d "$DIR_USBKEY/common-licenses" ]; then
  49.                 # executed only one time in runlevel 5 to export licenses
  50.                 dd if=/dev/zero of=$FILE_USBKEY bs=1M count=50 || true
  51.                 mkfs.vfat $FILE_USBKEY || true
  52.                 fatlabel $FILE_USBKEY C300X || true
  53.                 losetup /dev/loop2 $FILE_USBKEY || true
  54.                 mkdir ${DIR_USBKEY} >/dev/null 2>&1 || true
  55.                 mount -o sync /dev/loop2 $DIR_USBKEY || true
  56.                 mkdir ${DIR_USBKEY}/common-licenses >/dev/null 2>&1 || true
  57.                 cd /usr/share/common-licenses >/dev/null 2>&1 || true
  58.                 tar -czf ${DIR_USBKEY}/common-licenses/common-licenses.tar.gz * >/dev/null 2>&1 || true
  59.                 echo "$FW_V" > $FW_VER_FILE
  60.                 chmod -w -R $DIR_USBKEY/common-licenses >/dev/null 2>&1 || true
  61.                 cp /home/bticino/cfg/README $DIR_USBKEY/README >/dev/null 2>&1 || true
  62.                 cp /home/bticino/cfg/ReadMe_OSS_C300X.tar.gz $DIR_USBKEY/ReadMe_OSS_C300X.tar.gz >/dev/null 2>&1 || true
  63.                 sync >/dev/null 2>&1 || true
  64.         fi
  65. }
  66.  
  67. function wait_extra() {
  68.         S=$(( SECONDS + 10 ))
  69.         while [ $SECONDS -lt $S ]; do
  70.                 FOUND=1
  71.                 mount | grep extra -q || FOUND=0
  72.                 if [ "$FOUND" == "1" ]; then
  73.                         break
  74.                 fi
  75.                 echo "waiting extra partition to be mounted"
  76.         done
  77.         if [ "$FOUND" == "0" ]; then
  78.                 echo "===> extra partition NOT MOUNTED: giving-up"
  79.         fi
  80. }
  81.  
  82. start() {
  83.         export LD_LIBRARY_PATH=${USER_LIBDIR}:/home/bticino/lib:/home/bticino/libcoso
  84.         /bin/bt_hosts.sh add localhost 127.0.0.1
  85.         /bin/bt_hosts.sh add openserver 127.0.0.1
  86.         /bin/bt_hosts.sh add
  87.  192.168.1.150
  88.         cd /home/bticino
  89.         bin/bt_daemon &
  90. }
  91.  
  92. stop() {
  93.         APP=$(ls /home/bticino/bin/ | grep -v openserver)
  94.         for ap in $APP; do
  95.                 P="$(/bin/pidof "$ap")" || true
  96.                 if [ -z "$P" ]; then
  97.                         continue
  98.                 fi
  99.                 for pid in $P; do
  100.                         PATH="/proc/"$pid"/maps"
  101.                         /bin/grep -q acca $PATH
  102.                         if [ $? == 0 ]; then
  103.                                 kill $pid
  104.                         fi
  105.                 done
  106.         done
  107. }
  108.  
  109. case "$1" in
  110.         start)
  111.                 wait_extra
  112.                 setup_usbkey
  113.                 start &
  114.         ;;
  115.         stop)
  116.                 stop
  117.         ;;
  118.         *)
  119.                 wait_extra
  120.         echo $"Usage: $0 {start|stop} ${1+x}"
  121.         exit 1
  122. esac
  123. exit 0
  124.