DIU-deploy-site-specific 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. #!/bin/bash
  2. #
  3. # Copyright (c) 2020 Clementine Computing LLC.
  4. #
  5. # This file is part of PopuFare.
  6. #
  7. # PopuFare is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # PopuFare is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with PopuFare. If not, see <https://www.gnu.org/licenses/>.
  19. #
  20. # This script is meant to be run from a USB stick, say, to deploy
  21. # this site specific files on a DIU.
  22. #
  23. # This includes
  24. #
  25. # * The private SSH key
  26. # * The `common_values.sh` file
  27. # * The `diu_ui_site_specific.js` admin interface file
  28. # * Any paddles that might need transfer
  29. #
  30. # This will look for a local `data` directory with all the appropriate files
  31. #
  32. BASEDIR="data"
  33. SSH_FILE=$BASEDIR/id_rsa
  34. COM_VAL=$BASEDIR/common_values.sh
  35. SRV_LST=$BASEDIR/server_list
  36. SYNC_PORT=$BASEDIR/sync_port
  37. SYNC_SRV_DESC=$BASEDIR/sync_server_desc
  38. SYNC_TARGET=$BASEDIR/sync_target
  39. DRIVER_FN=$BASEDIR/drivers.txt
  40. EQUIP_FN=$BASEDIR/equipnum.txt
  41. RULE_FN=$BASEDIR/rules.scm
  42. DIU_UI=$BASEDIR/diu_ui_site_specific.js
  43. DO_CLEANUP_INSTALL=1
  44. if [[ "$DO_CLEANUP_INSTALL" != "" ]] ; then
  45. echo "doing 'cleanup install'"
  46. bd="../popufare"
  47. mkdir -p .tmp
  48. btd=`mktemp -d`
  49. btd=`basename $btd`
  50. mv /tmp/$btd .tmp/$btd
  51. td=".tmp/$btd"
  52. echo " Making temporary diectory for original copies ($td)"
  53. apt-get update
  54. apt-get install -y espeak mplayer git ppp ppp-dev sox alsa-utils unclutter fbi xinput-calibrator ffmpeg jq matchbox-window-manager libi2c-dev socat figlet vim pwgen minicom
  55. apt-get autoremove -y
  56. ###
  57. ## See https://community.sixfab.com/t/how-to-remove-interface-wwan0/262
  58. echo "attempting to disable wwan0 interface (adding blacklist for 'qmi_wwan', 'cd_wmd' to /etc/modprobe.d/raspi-blacklist.conf)"
  59. mkdir -p /etc/modprobe.d
  60. echo "blacklist qmi_wwan" >> /etc/modprobe.d/raspi-blacklist.conf
  61. echo "blacklist cdc_wdm" >> /etc/modprobe.d/raspi-blacklist.conf
  62. chmod 644 /etc/modprobe.d/raspi-blacklist.conf
  63. ###
  64. systemctl stop serial-getty@ttyAMA0.service
  65. systemctl mask serial-getty@ttyAMA0.service
  66. cp /etc/ppp/ip-up $td/ip-up
  67. cp /etc/ppp/ip-down $td/ip-down
  68. cp $bd/busunit/ppp-dialer/etc/ppp/ip-up /etc/ppp/ip-up
  69. cp $bd/busunit/ppp-dialer/etc/ppp/ip-down /etc/ppp/ip-down
  70. cp $bd/busunit/scripts/custom /home/bus/bin/custom
  71. cp $bd/busunit/scripts/connection_tether-ppp.sh /home/bus/bin/connection_tether.sh
  72. echo " Saving /boot/cmdline.txt to $td/cmdline.txt"
  73. cp /boot/cmdline.txt $td/cmdline.txt
  74. sed -i 's/console=serial0,115200 //' /boot/cmdline.txt
  75. ###
  76. mkdir -p /home/pi/bin
  77. cp $bd/busunit/scripts/welcome_to_popufare.sh /home/pi/bin/welcome_to_popufare.sh
  78. chown -R pi:pi /home/pi/bin
  79. echo "/home/pi/bin/welcome_to_popufare.sh" >> /home/pi/.bashrc
  80. ###
  81. echo " compiling and installing ichthyic-passthrough"
  82. bash -c " cd $bd/busunit/PIU/shim ; ./cmp.sh ; cp ./ichthyic-passthrough /home/bus/bin"
  83. echo " installing popufare_monitor script"
  84. bash -c " cp -f $bd/busunit/scripts/popufare_monitor /home/bus/bin/popufare_monitor"
  85. echo " enabling ichthyic (touch /home/bus/config/popufare.ichthyic)"
  86. bash -c " touch /home/bus/config/popufare.ichthyic ; chown bus:bus /home/bus/config/popufare.ichthyic"
  87. echo " setting root crontab to call popufare_monitor (using $bd/busunit/scripts/crontab.root)"
  88. bash -c " crontab $bd/busunit/scripts/crontab.root "
  89. newhostname=popufare-`pwgen 8 1`
  90. echo " Using hostname $newhostname"
  91. echo " Saving /etc/hostname and /etc/hosts to $td"
  92. cp /etc/hostname $td/hostname
  93. cp /etc/hosts $td/hosts
  94. echo "$newhostname" > /etc/hostname
  95. tfn=`mktemp`
  96. echo -e '127.0.0.1\tlocalhost' > $tfn
  97. echo -e '::1\t\tlocalhost ip6-localhost ip6-loopback' >> $tfn
  98. echo -e 'ff02::1\t\tip6-allnodes' >> $tfn
  99. echo -e 'ff02::2\t\tip6-allrouters' >> $tfn
  100. echo '' >> $tfn
  101. echo -e '127.0.1.1\t'"$newhostname" >> $tfn
  102. echo " Creating new /etc/hosts file"
  103. mv $tfn /etc/hosts
  104. chmod 644 /etc/hosts
  105. echo " Removing stale Xauth cookie"
  106. xauth remove popufaredev/unix:0
  107. echo " Removing stale Singletone for Chromium"
  108. rm -f /root/.config/[cC]hromium/[Ss]ingleton*
  109. rm -f /home/pi/.config/[cC]hromium/[Ss]ingleton*
  110. rm -f /home/bus/.config/[cC]hromium/[Ss]ingleton*
  111. echo " REMEMBER TO SET THE LOGIN AND I2C FROM raspi-config!!!!"
  112. echo " ....."
  113. echo " PRESS ANY KEY TO ENTER raspi-config"
  114. echo " ....."
  115. read
  116. raspi-config
  117. fi
  118. if [[ -e "$SSH_FILE" ]] ; then
  119. echo "# deploying SSH file $SSH_FILE to /home/bus/.ssh"
  120. cp -L -f "$SSH_FILE" /home/bus/.ssh/id_rsa
  121. cp -L -f "$SSH_FILE" /etc/ppp/id_rsa_bus
  122. chown bus:bus /home/bus/.ssh/id_rsa
  123. chmod a-rwx /home/bus/.ssh/id_rsa
  124. chmod u+r /home/bus/.ssh/id_rsa
  125. chmod a-rwx /etc/ppp/id_rsa_bus
  126. chmod u+r /etc/ppp/id_rsa_bus
  127. else
  128. echo "# FILE NOT FOUND (SSH id_rsa): $SSH_FILE"
  129. fi
  130. if [[ -e "$COM_VAL" ]] ; then
  131. echo "# deploying common_values.sh file $COM_VAL to /home/bus/config/common_values.sh"
  132. cp -L -f "$COM_VAL" /home/bus/bin/common_values.sh
  133. else
  134. echo "# FILE NOT FOUND (COMMON VALUES): $COM_VAL"
  135. fi
  136. ###
  137. if [[ -e "$SRV_LST" ]] ; then
  138. echo "# deploying server list file: $SRV_LST -> /home/bus/config/server/server_list"
  139. cp -L -f "$SRV_LST" /home/bus/config/server/server_list
  140. else
  141. echo "# FILE NOT FOUND (SERVER LIST): $SRV_LST"
  142. fi
  143. if [[ -e "$SYNC_PORT" ]] ; then
  144. echo "# deploying sync port file: $SRV_PORT -> /home/bus/config/server/sync_port"
  145. cp -L -f "$SYNC_PORT" /home/bus/config/server/sync_port
  146. else
  147. echo "# FILE NOT FOUND (SYNC PORT): $SYNC_PORT"
  148. fi
  149. if [[ -e "$SYNC_SRV_DESC" ]] ; then
  150. echo "# deploying server list file: $SRV_SRV_DESC -> /home/bus/config/server/sync_server_desc"
  151. cp -L -f "$SYNC_SRV_DESC" /home/bus/config/server/sync_server_desc
  152. else
  153. echo "# FILE NOT FOUND (SYNC DESC): $SYNC_SRV_DESC"
  154. fi
  155. if [[ -e "$SYNC_TARGET" ]] ; then
  156. echo "# deploying server list file: $SRV_TARGET -> /home/bus/config/server/sync_target"
  157. cp -L -f "$SYNC_TARGET" /home/bus/config/server/sync_target
  158. else
  159. echo "# FILE NOT FOUND (SYNC TARGET): $SYNC_TARGET"
  160. fi
  161. ###
  162. if [[ -e "$DRIVER_FN" ]] ; then
  163. echo "# deploying drivers.txt file $DRIVER_FN to /home/bus/config/drivers.txt"
  164. cp -L -f "$DRIVER_FN" /home/bus/config/drivers.txt
  165. else
  166. echo "# FILE NOT FOUND (DRIVERS): $DRIVER_FN"
  167. fi
  168. if [[ -e "$EQUIP_FN" ]] ; then
  169. echo "# deploying equipnum.txt file $EQUIP_FN to /home/bus/config/equipnum.txt"
  170. cp -L -f "$EQUIP_FN" /home/bus/bin/equipnum.txt
  171. else
  172. echo "# FILE NOT FOUND (EQUIPNUM): $EQUIP_FN"
  173. fi
  174. if [[ -e "$RULE_FN" ]] ; then
  175. echo "# deploying rules.scm file $RULE_FN to /home/bus/config/rules.scm"
  176. cp -L -f "$RULE_FN" /home/bus/config/rules.scm
  177. else
  178. echo "# FILE NOT FOUND (RULES): $RULE_FN"
  179. fi
  180. ###
  181. if [[ -e "$DIU_UI" ]] ; then
  182. echo "# deploying diu_site_specific file: $DIU_UI -> /home/bus/config/html/js/diu_site_sepcific.js"
  183. cp -L -f "$DIU_UI" /home/bus/config/html/js/diu_site_specific.js
  184. else
  185. echo "# FILE NOT FOUND (DIU SITE SPECIFIC): $DIU_UI"
  186. fi
  187. for pfn in `find data -name '*.paddle' -type f` ; do
  188. bpfn=`basename $pfn`
  189. echo "# deploying paddle file: $pfn -> /home/bus/config/$bpfn"
  190. cp -L -f "$pfn" /home/bus/config/$bpfn
  191. done
  192. echo "# done"