deploy-busunit-interactive 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. #!/bin/bash
  2. #
  3. # Copyright (c) 2019 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. GITURL="https://tree.clementinecomputing.com/clementinecomputing/popufare"
  21. echo ""
  22. echo ' _____ __ '
  23. echo ' | __ \ / _| '
  24. echo ' | |__) |__ _ __ _ _| |_ __ _ _ __ ___ '
  25. echo ' | ___/ _ \| '"'"'_ \| | | | _/ _` | '"'"'__/ _ \'
  26. echo ' | | | (_) | |_) | |_| | || (_| | | | __/'
  27. echo ' |_| \___/| .__/ \__,_|_| \__,_|_| \___|'
  28. echo ' | | '
  29. echo ' |_| '
  30. echo ""
  31. echo "This script attempts to setup a default installation of Popufare on a busunit (a Raspberry Pi, say)"
  32. echo "by setting up and configuring the system."
  33. echo ""
  34. echo "THIS SCRIPT CHANGES SYSTEM WIDE PARAMETERS AND COULD HAVE SERIOUS CONSEQUENCES TO THE MACHINE IT'S RUN"
  35. echo "ON."
  36. echo ""
  37. echo "As such, this scripts needs root access (via sudo)."
  38. echo "This script is meant to be a 'helper' script and isn't meant to be all encompassing. Among other things,"
  39. echo "this script will:"
  40. echo ""
  41. echo " * setup a 'bus' user and group"
  42. echo " * add the 'pi' user to the 'bus' group"
  43. echo " * clone the Popufare repo, build it's binaries and install them in the '/home/bus' user directory"
  44. echo " * copy over appropriate config files to the appropriate locations in the '/hom/ebus' user directory"
  45. echo " * setup ssh keys and credentials"
  46. echo " * setup the PPP config files"
  47. echo " * alter /boot/config.txt and /etc/modules to enable serial and sound setup"
  48. echo " * setup a 'kiosk' service for the front end DIU"
  49. echo " * setup 'rc.local' to start and monitor bus Popufare services on startup"
  50. echo " * setup legacy data directories in '/mnt/data2'"
  51. echo ""
  52. echo "Most parameters have options to prompt the user for installation."
  53. echo ""
  54. echo "This script should be used with caution and as a helper for an installation rather than a 'turn key' soluation."
  55. echo "For example, the ssh keys default to the UNSECURE 'snakeoil' default keys provided the repo for easy setup and"
  56. echo "MUST BE CHANGED for a production installation."
  57. echo ""
  58. echo "In addition, the host and other config file options should be set on a per installation basis, as should the custom"
  59. echo "DIU interface, rules, drivers.txt entries, etc."
  60. echo ""
  61. echo "This script should help in getting a Raspberry Pi ready for use with Popufare but should be thought of also as a"
  62. echo "record of what relevant files there are to change and where to look."
  63. echo ""
  64. echo "As Popufare matures, this installation script or something similar can accomodate a more seamless installation but"
  65. echo "this is what is provided now."
  66. echo ""
  67. echo "Popufare is free software so please feel free to contribute at:"
  68. echo ""
  69. echo " https://tree.clementinecomputing.com/clementinecomputing/popufare"
  70. echo ""
  71. echo -n "Hit return to continue [ok]: "
  72. read hitreturn
  73. DATESTR=`date '+%Y%m%d%H%M%S'`
  74. ###### basic sanity checks to make sure we're installing on a Raspberry Pi
  75. ######
  76. if [[ ! -e /etc/os-release ]] ; then
  77. echo -n "Are you sure you want to install? '/etc/os-release' does not exist and this system might not be a Raspberry Pi. Continue? [y/N]: "
  78. read fnfok
  79. if [[ ! "$fnfok" =~ ^[yY]$ ]] ; then
  80. echo "cancelling installalation"
  81. echo ""
  82. exit
  83. else
  84. echo "ok, continuing installation..."
  85. fi
  86. else
  87. grep -P '^PRETTY_NAME="Raspbian' /etc/os-release 2>&1 > /dev/null
  88. r=$?
  89. if [[ $r != 0 ]] ; then
  90. echo -n "Raspbian not detected in '/etc/os-release'. This might not be Raspberry Pi. Continue with installation? [y/N]: "
  91. read okcontinue
  92. if [[ ! "$okcontinue" =~ ^[yY]$ ]] ; then
  93. echo "cancelling installation"
  94. echo ""
  95. exit
  96. else
  97. echo "ok, continuing installation..."
  98. fi
  99. fi
  100. fi
  101. echo ""
  102. ######
  103. ######
  104. echo -n "Install package dependencies? [Y/n]: "
  105. read adddeps
  106. if [[ "$adddeps" =~ ^[yY]?$ ]]; then
  107. deps="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 "
  108. echo ""
  109. echo " Installing: $deps"
  110. sudo apt-get update
  111. sudo apt-get install -y $deps
  112. echo ""
  113. echo -n " Remove unused packages (free up space)? [Y/n]: "
  114. read remunused
  115. if [[ "$remunused" =~ ^[yY]?$ ]]; then
  116. remdeps="libreoffice libreoffice-base-core libreoffice-common \
  117. libreoffice-core libreoffice-help-common libreoffice-help-en-gb \
  118. libreoffice-help-en-us libreoffice-l10n-en-gb \
  119. libreoffice-style-colibre libreoffice-style-tango \
  120. wolfram-engine scratch scratch2"
  121. echo ""
  122. echo " Removing: $remdeps"
  123. #sudo apt-get remove -y $remdeps
  124. #sudo apt-get autoremove -y --purge
  125. apt-get purge -y $remdeps
  126. echo ""
  127. fi
  128. fi
  129. echo ""
  130. ######
  131. ######
  132. echo -n "Create 'bus' user? [Y/n]: "
  133. read createbususer
  134. if [[ "$createbususer" =~ ^[yY]?$ ]]; then
  135. echo "... creating 'bus' user and group"
  136. sudo adduser bus
  137. sudo usermod -a -G dialout bus
  138. fi
  139. echo ""
  140. echo -n "Add 'pi' to 'bus' group? [Y/n]: "
  141. read addpibus
  142. if [[ "$addpibus" =~ ^[yY]$ ]]; then
  143. echo "... add 'pi' to 'bus' group"
  144. sudo usermod -a -G bus pi
  145. fi
  146. echo ""
  147. echo "Creating /home/bus/(bin|database|config) with group write permissions"
  148. sudo mkdir -p /home/bus/bin
  149. sudo mkdir -p /home/bus/database
  150. sudo mkdir -p /home/bus/config
  151. sudo chown -R bus:bus /home/bus/bin
  152. sudo chown -R bus:bus /home/bus/database
  153. sudo chown -R bus:bus /home/bus/config
  154. sudo chmod -R g+w /home/bus/bin
  155. sudo chmod -R g+w /home/bus/database
  156. sudo chmod -R g+w /home/bus/config
  157. echo ""
  158. echo -n "Repo path (hit return to automatically clone the repo and use that) []: "
  159. read repolocation
  160. tmpdir=""
  161. if [[ "$repolocation" == "" ]] ; then
  162. tmpdir=`mktemp -d`
  163. repolocation="$tmpdir/popufare"
  164. pushd $tmpdir
  165. git clone "$GITURL"
  166. popd
  167. fi
  168. echo "Setting up binaries..."
  169. bd=/home/bus/popufare/busunit
  170. d=/home/bus/popufare/busunit/bin/native
  171. diudir=/home/bus/popufare/busunit/DIUv2
  172. tc=/home/bus/popufare/busunit/testing/config
  173. sudo cp -R $repolocation /home/bus
  174. sudo chown -R bus:bus /home/bus/popufare
  175. sudo bash -c " su - bus -c ' cd /home/bus/popufare/busunit ; ./build_all.sh native ; ' "
  176. sudo bash -c " cd /home/bus/bin ; cp -fRL $d/avls . ; cp -fRL $d/billdb . ; cp -fRL $d/client_supervisor . ; cp -fRL $d/debug_client . ; cp -fRL $d/diu_minder . ; cp -fRL $d/ipc_server . "
  177. sudo bash -c " cd /home/bus/bin ; cp -fRL $d/paddlemgr . ; cp -fRL $d/passdb . ; cp -fRL $d/piu_minder . ; cp -fRL $d/send_billing_record . ; cp -fRL $d/send_magstripe . "
  178. sudo bash -c " cd /home/bus/bin ; cp -fRL $d/gps_minder . "
  179. sudo bash -c " cd /home/bus/bin ; cp -fRL $bd/DIUv2/diu_kiosk . "
  180. sudo bash -c " cd /home/bus/bin ; cp -fRL $bd/scripts/init_bus.sh . ; cp -fRL $bd/scripts/update_loop.sh . ; cp -fRL $bd/scripts/setup-serial.py . ; cp -fRL $bd/scripts/get_net_ids.sh . "
  181. sudo bash -c " cd /home/bus/bin ; cp -fRL $bd/scripts/connection_tether.sh . ; cp -fRL $bd/scripts/reset-gps.py ./reset-gps "
  182. sudo bash -c " cd /home/bus/bin ; cp -fRL $bd/scripts/apply_update.sh . ; cp -fRL $bd/scripts/apply_update_legacy.sh . ; cp -fRL $bd/scripts/apply_update_popufare.sh . "
  183. sudo bash -c " cd /home/bus/bin ; cp -fRL $bd/scripts/fix_pkg_perm.sh . "
  184. sudo bash -c " cd /home/bus/bin ; cp -fRL $bd/scripts/unpack_server_data.sh . "
  185. sudo bash -c " cd /home/bus/bin ; cp -fRL $bd/scripts/say . "
  186. sudo bash -c " cd /home/bus/bin ; cp -fRL $bd/scripts/volumeset . "
  187. sudo bash -c " cd /home/bus/bin ; cp -fRL $bd/scripts/start-kiosk.sh . "
  188. sudo bash -c " cd /home/bus/config ; cp -fRL $diudir/html . ; "
  189. sudo bash -c " cd /home/bus/config ; cp $bd/passdb/init.scm . ; cp $bd/passdb/rfid_patterns.txt . ; cp $bd/avls/avls_freq.txt . "
  190. sudo bash -c " cd /home/bus/config ; cp $bd/passdb/init.scm . ; cp $bd/passdb/rfid_patterns.txt . ; cp $bd/avls/avls_freq.txt . "
  191. sudo bash -c " cd /home/bus/config ; cp $tc/equipnum.txt . ; cp $tc/serial.txt serial_num "
  192. sudo bash -c " rm -f /home/bus/bin/common_values.sh ; cp $bd/scripts/common_values.sh /home/bus/bin "
  193. ## server endpoint config files
  194. ##
  195. ## sync_server_desc, sync_target, server_list, syn_port
  196. sudo cp /home/bus/popufare/busunit/testing/config/config.tgz.checksum /home/bus/config/config.tgz.checksum
  197. sudo cp /home/bus/popufare/busunit/testing/config/config.tgz.version /home/bus/config/config.tgz.version
  198. sudo cp /home/bus/popufare/busunit/testing/config/firmware.tgz.checksum /home/bus/config/firmware.tgz.checksum
  199. sudo cp /home/bus/popufare/busunit/testing/config/firmware.tgz.version /home/bus/config/firmware.tgz.version
  200. sudo cp /home/bus/popufare/busunit/testing/config/package.tgz.checksum /home/bus/config/package.tgz.checksum
  201. sudo cp /home/bus/popufare/busunit/testing/config/package.tgz.version /home/bus/config/package.tgz.version
  202. sudo mkdir -p /home/bus/config/server
  203. echo ""
  204. ##### i2c serial passthrough setup
  205. #####
  206. echo -n "Setup i2c-serial passthrough? [Y/n]: "
  207. read i2cpass
  208. if [[ "$i2cpass" =~ ^[yY]?$ ]] ; then
  209. echo " compiling and installing ichthyic-passthrough"
  210. sudo bash -c " cd /home/bus/popufare/busunit/PIU/shim ; ./cmp.sh ; cp ./ichthyic-passthrough /home/bus/bin"
  211. echo " installing popufare_monitor script"
  212. sudo bash -c " cp -f /home/bus/popufare/busunit/scripts/popufare_monitor /home/bus/bin/popufare_monitor"
  213. echo " enabling ichthyic (touch /home/bus/config/popufare.ichthyic)"
  214. sudo bash -c " touch /home/bus/config/popufare.ichthyic ; chown bus:bus /home/bus/config/popufare.ichthyic"
  215. echo " setting root crontab to call popufare_monitor (using $repolocation/busunit/scripts/crontab.root)"
  216. sudo bash -c " crontab $repolocation/busunit/scripts/crontab.root "
  217. fi
  218. ##### paddle setup
  219. #####
  220. echo -n "Setup paddles? [Y/n]: "
  221. read setuppaddles
  222. if [[ "$setuppaddles" =~ ^[yY]?$ ]] ; then
  223. echo -n "Paddle location? (blank for default testing paddles) []: "
  224. read paddlocation
  225. if [[ "$paddlelocation" == "" ]] ; then
  226. paddlelocation=$bd/busunit/testing
  227. fi
  228. echo "Using '$paddlelocation/*.paddle'..."
  229. sudo bash -c " cd /home/bus/config ; cp $bd/testing/*.paddle . "
  230. fi
  231. echo ""
  232. ##### rules setup
  233. #####
  234. echo -n "Setup rules? [Y/n]: "
  235. read setuprules
  236. if [[ "$setuprules" =~ ^[yY]?$ ]] ; then
  237. echo -n "Rule file? (blank for default testing rules) []: "
  238. read rulelocation
  239. if [[ "$rulelocation" == "" ]] ; then
  240. rulelocation=$bd/testing/rules-ORG.scm
  241. fi
  242. echo "Setting up rules from '$rulelocation'..."
  243. sudo bash -c " cd /home/bus/config ; cp $rulelocation rules.scm "
  244. fi
  245. echo ""
  246. ##### equipment number setup
  247. #####
  248. echo -n "Equipment number? [9999]: "
  249. read equipnum
  250. if [[ "$equipnum" == "" ]] ; then
  251. equipnum=9999
  252. fi
  253. echo "Setting equipment number to '$equipnum'..."
  254. sudo bash -c " echo $equipnum > /home/bus/config/equipnum.txt "
  255. echo ""
  256. ##### key setup
  257. #####
  258. echo -n "Setup secure communcation setup? [Y/n]: "
  259. read tunnelsetup
  260. if [[ "$tunnelsetup" =~ ^[yY]?$ ]] ; then
  261. echo -n " 'id_rsa' private key location? (default to snakeoil) []: "
  262. read keylocation
  263. if [[ "$keylocation" == "" ]] ; then
  264. keylocation=/home/bus/popufare/server/docker/snakeoil_id_rsa
  265. fi
  266. echo " Using '$keylocation' for private key..."
  267. sudo mkdir -p /home/bus/.ssh
  268. sudo chown -R bus:bus /home/bus/.ssh
  269. sudo cp $keylocation /home/bus/.ssh/id_rsa_bus
  270. sudo chown bus:bus /home/bus/.ssh/id_rsa_bus
  271. sudo chmod 400 /home/bus/.ssh/id_rsa_bus
  272. echo ""
  273. echo -n " Tunnel port? [6055]: "
  274. read tunnelport
  275. if [[ "$tunnelport" == "" ]] ; then
  276. tunnelport=6055
  277. fi
  278. echo ""
  279. echo -n " Tunnel user and host? [bus@example.com]: "
  280. read tunnelhost
  281. if [[ "$tunnelhost" == "" ]] ; then
  282. tunnelhost='bus@example.com'
  283. fi
  284. echo ""
  285. echo -n " Adding values to '/home/bus/bin/common_values.sh'..."
  286. sed -i 's;^SSH_DEFAULT_TARGET=;#SSH_DEFAULT_TARGET=;g' /home/bus/bin/common_values.sh
  287. sed -i 's;^SSH_DEFAULT_PORT=;#SSH_DEFAULT_PORT=;g' /home/bus/bin/common_values.sh
  288. sed -i 's;^SSH_DEFAULT_IDENTITY=;#SSH_DEFAULT_IDENTITY=;g' /home/bus/bin/common_values.sh
  289. sed -i 's;^SSH_TARGET=;#SSH_TARGET=;g' /home/bus/bin/common_values.sh
  290. sed -i 's;^SSH_PORT=;#SSH_PORT=;g' /home/bus/bin/common_values.sh
  291. sed -i 's;^SSH_IDENTITY=;#SSH_IDENTITY=;g' /home/bus/bin/common_values.sh
  292. echo 'SSH_DEFAULT_TARGET="'"$tunnelhost"'"' >> /home/bus/bin/common_values.sh
  293. echo 'SSH_DEFAULT_PORT="'"$tunnelport"'"' >> /home/bus/bin/common_values.sh
  294. echo 'SSH_DEFAULT_IDENTITY="/home/bus/.ssh/id_rsa_bus"' >> /home/bus/bin/common_values.sh
  295. echo '' >> /home/bus/bin/common_values.sh
  296. echo 'SSH_TARGET="$SSH_DEFAULT_TARGET"' >> /home/bus/bin/common_values.sh
  297. echo 'SSH_PORT="$SSH_DEFAULT_PORT"' >> /home/bus/bin/common_values.sh
  298. echo 'SSH_IDENTITY="$SSH_DEFAULT_IDENTITY"' >> /home/bus/bin/common_values.sh
  299. echo ""
  300. fi
  301. echo ""
  302. ##### drivers setup
  303. #####
  304. echo -n "'drivers.txt' location? (default to test) []: "
  305. read driverlocation
  306. if [[ "$driverlocation" == "" ]] ; then
  307. driverlocation=/home/bus/popufare/busunit/DIUv2/drivers.txt
  308. fi
  309. echo "Using '$driverlocation' for drivers.txt ..."
  310. sudo cp $driverlocation /home/bus/config
  311. echo ""
  312. ##### setup fona ppp
  313. #####
  314. echo -n "Setup FONA ppp files? [Y/n]: "
  315. read setupfona
  316. if [[ "$setupfona" =~ ^[yY]?$ ]] ; then
  317. echo " Creating /etc/ppp/peers/ and /etc/chatscripts/"
  318. sudo mkdir -p /etc/ppp/peers/
  319. sudo mkdir -p /etc/chatscripts/
  320. echo " /home/bus/popufare/busunit/ppp-dialer/etc/ppp/peers/fona -> /etc/ppp/peers/gprs"
  321. echo " /home/bus/popufare/busunit/ppp-dialer/etc/chatscripts/gprs -> /etc/chatscripts/gprs"
  322. sudo cp /home/bus/popufare/busunit/ppp-dialer/etc/ppp/peers/fona /etc/ppp/peers/gprs
  323. sudo cp /home/bus/popufare/busunit/ppp-dialer/etc/chatscripts/gprs /etc/chatscripts/gprs
  324. echo " /home/bus/popufare/busunit/ppp-dialer/etc/ppp/ip-up -> /etc/ppp/ip-up"
  325. echo " /home/bus/popufare/busunit/ppp-dialer/etc/ppp/ip-down -> /etc/ppp/ip-down"
  326. sudo cp /home/bus/popufare/busunit/ppp-dialer/etc/ppp/ip-up /etc/ppp/ip-up
  327. sudo cp /home/bus/popufare/busunit/ppp-dialer/etc/ppp/ip-down /etc/ppp/ip-down
  328. echo ""
  329. fi
  330. ##### setup ppp connection_tether.sh script
  331. #####
  332. echo -n "Setup connection_tether.sh PPP script? [Y/n]: "
  333. read setupctsh
  334. if [[ "$setupctsh" =~ ^[yY]?$ ]] ; then
  335. echo " $bd/scripts/connection_tether-ppp.sh -> /home/bus/bin/connection_tether.sh "
  336. sudo bash -c " cd /home/bus/bin ; cp -fRL $bd/scripts/connection_tether-ppp.sh ./connection_tether.sh "
  337. echo ""
  338. fi
  339. ##### disable serial-getty@ttyAMA0
  340. #####
  341. echo -n "Disable serial-getty@ttyAMA0 service (this can interfere with the GPRS modem)? [Y/n]: "
  342. read disablegettyama
  343. if [[ "$disablegettyama" =~ ^[yY]?$ ]] ; then
  344. echo " Disabling serial-getty@ttyAMA0 service..."
  345. echo " systemctl mask serial-getty@ttyAMA0.service"
  346. systemctl mask serial-getty@ttyAMA0.service
  347. echo ""
  348. fi
  349. #echo -n "Setup FONA to connect at startup? [Y/n]: "
  350. #read fonanetwork
  351. #
  352. #if [[ "$fonanetwork" =~ ^[yY]?$ ]] ; then
  353. # echo " Creating '/etc/network/interfaces.d/fona'..."
  354. # sudo echo 'auto fona' > /etc/network/interfaces.d/fona
  355. # sudo echo 'iface fona inet ppp' >> /etc/network/interfaces.d/fona
  356. # sudo echo ' provider fona' >> /etc/network/interfaces.d/fona
  357. #fi
  358. ##### Setup config.txt
  359. #####
  360. echo -n "Setup '/boot/config.txt'? (Note this could have serious consequences, use with caution) [y/N]: "
  361. read setupconfig
  362. if [[ "$setupconfig" =~ ^[yY]$ ]] ; then
  363. tmpfn=`mktemp`
  364. bfn=`basename $tmpfn`
  365. echo " Saving 'config.txt' to /root/$bfn"
  366. sudo cp /boot/config.txt $tmpfn
  367. sudo mv $tmpfn /root/$bfn
  368. echo " adding> enable_uart=1"
  369. sudo sed -i 's;^enable_uart=;#enable_uart=;g' /boot/config.txt
  370. sudo bash -c 'echo "enable_uart=1" >> /boot/config.txt'
  371. echo " adding> dtoverlay=pi3-disable-bt"
  372. sudo sed -i 's;^dtoverlay=pi3-disable-bt;#dtoverlay=pi3-disable-bt;g' /boot/config.txt
  373. sudo bash -c 'echo "dtoverlay=pi3-disable-bt" >> /boot/config.txt'
  374. echo " adding> dtoverlay=pi3-disable-wifi"
  375. sudo sed -i 's;^dtoverlay=pi3-disable-wifi;#dtoverlay=pi3-disable-wifi;g' /boot/config.txt
  376. sudo bash -c 'echo "dtoverlay=pi3-disable-wifi" >> /boot/config.txt'
  377. echo " adding> dtoverlay=disable-bt"
  378. sudo sed -i 's;^dtoverlay=disable-bt;#dtoverlay=disable-bt;g' /boot/config.txt
  379. sudo bash -c 'echo "dtoverlay=disable-bt" >> /boot/config.txt'
  380. echo " adding> dtoverlay=disable-wifi"
  381. sudo sed -i 's;^dtoverlay=disable-wifi;#dtoverlay=disable-wifi;g' /boot/config.txt
  382. sudo bash -c 'echo "dtoverlay=disable-wifi" >> /boot/config.txt'
  383. fi
  384. echo ""
  385. ##### Disable wwan0
  386. #####
  387. ## see https://community.sixfab.com/t/how-to-remove-interface-wwan0/262
  388. ## https://www.freedesktop.org/wiki/Software/libqmi/
  389. echo -n "Try to disable wwan0? [y/N]: "
  390. read disablewwan0
  391. if [[ "$disablewwan0" =~ ^[yY]$ ]] ; then
  392. tmpfn=`mktemp`
  393. bfn=`basename $tmpfn`
  394. echo " Saving '/etc/modprobe.d/raspi-blacklist.conf.txt' to /root/$bfn"
  395. sudo cp /etc/modprobe.d/raspi-blacklist.conf $tmpfn
  396. sudo mv $tmpfn /root/$bfn
  397. echo " adding> blacklist qmi_wwan"
  398. sudo bash -c 'echo "blacklist qmi_wwan" >> /etc/modprobe.d/raspi-blacklist.conf'
  399. echo " adding> blacklist cdc_wdm"
  400. sudo bash -c 'echo "blacklist cdc_wdm" >> /etc/modprobe.d/raspi-blacklist.conf'
  401. fi
  402. echo ""
  403. ##### Setup sound in modules file
  404. #####
  405. echo -n "Setup sound (alter '/etc/modules')? [y/N]: "
  406. read setupsound
  407. if [[ "$setupsound" =~ ^[yY]$ ]] ; then
  408. tmpfn=`mktemp`
  409. bfn=`basename $tmpfn`
  410. echo " Saving 'modules' to /root/$bfn"
  411. sudo cp /etc/modules $tmpfn
  412. sudo mv $tmpfn /root/$bfn
  413. sudo sed -i 's;^snd-bcm2835;#snd-bcm2835;g' /etc/modules
  414. echo ' adding> snd-bcm2835'
  415. sudo bash -c 'echo "snd-bcm2835" >> /etc/modules'
  416. # disabled for now. Force audio to go through 3.5mm jack from 'raspi-config'.
  417. #
  418. # ...
  419. # trying to mitigate the 'first two seconds cutoff of audio' problem
  420. # https://github.com/alexa-pi/AlexaPi/wiki/Devices#raspberry-pi
  421. #
  422. #tfn=`mktemp`
  423. #echo '@reboot vcgencmd force_audio hdmi 1' > $tfn
  424. #echo "adding `cat $tfn`"
  425. #sudo crontab $tfn
  426. #rm $tfn
  427. fi
  428. ##### Change hostname
  429. #####
  430. echo -n "Change hostname? [y/N]: "
  431. read changehostname
  432. if [[ "$changehostname" =~ ^[yY]$ ]] ; then
  433. echo -n " New hostname [popufaredev]: "
  434. read newhostname
  435. if [[ "$newhostname" == "" ]] ; then
  436. newhostname=popufaredev
  437. fi
  438. echo " Saving /etc/hostname to /root/hostname.$DATESTR"
  439. sudo cp /etc/hostname /root/hostname.$DATESTR
  440. sudo bash -c "echo '$newhostname' > /etc/hostname"
  441. tfn=`mktemp`
  442. echo -e '127.0.0.1\tlocalhost' > $tfn
  443. echo -e '::1\t\tlocalhost ip6-localhost ip6-loopback' >> $tfn
  444. echo -e 'ff02::1\t\tip6-allnodes' >> $tfn
  445. echo -e 'ff02::2\t\tip6-allrouters' >> $tfn
  446. echo '' >> $tfn
  447. echo -e '127.0.1.1\t'"$newhostname" >> $tfn
  448. echo " Saving /etc/hosts to /root/hosts.$DATESTR"
  449. sudo cp /etc/hosts /root/hosts.$DATESTR
  450. echo " Creating new /etc/hosts file"
  451. sudo mv $tfn /etc/hosts
  452. sudo chmod 644 /etc/hosts
  453. echo " Removing stale Xauth cookie"
  454. sudo xauth remove popufaredev/unix:0
  455. echo " Removing stale Singletone for Chromium"
  456. sudo rm -f /root/.config/[cC]hromium/[Ss]ingleton*
  457. sudo rm -f /home/pi/.config/[cC]hromium/[Ss]ingleton*
  458. sudo rm -f /home/bus/.config/[cC]hromium/[Ss]ingleton*
  459. fi
  460. ##### Setup kiosk
  461. #####
  462. # kiosk now run through startx in the rc.local
  463. #
  464. #echo -n "Setup kiosk service? [Y/n]: "
  465. #read setupkiosk
  466. #
  467. #if [[ "$setupkiosk" =~ ^[yY]?$ ]] ; then
  468. #
  469. # echo " /home/bus/popufare/busunit/rootfs/etc/systemd/system/kiosk.service -> /lib/systemd/system/kiosk.service"
  470. # sudo cp /home/bus/popufare/busunit/rootfs/etc/systemd/system/kiosk.service /lib/systemd/system/kiosk.service
  471. #
  472. # echo " enabling kiosk.service ('systemctl enable kiosk.service')"
  473. # sudo systemctl enable kiosk.service
  474. #
  475. # ## Changing hostname will screw up chromium if it's already been run under a different
  476. # ## hostname. Remove the files that cause the problems so Chromium can run without
  477. # ## issue.
  478. # ##
  479. # echo " removing chromium 'Singleton*' files"
  480. # sudo rm -rf /home/bus/.config/chromium/Singleton*
  481. #fi
  482. #
  483. #echo ""
  484. ##### Setup startup
  485. #####
  486. echo -n "Setup startup 'rc.local'? [Y/n]: "
  487. read setupstartup
  488. if [[ "$setupstartup" =~ ^[yY]?$ ]] ; then
  489. tmpfn=`mktemp`
  490. bfn=`basename $tmpfn`
  491. echo " saving /etc/rc.local to /root/$bfn"
  492. sudo cp /etc/rc.local $tmpfn
  493. sudo mv $tmpfn /root/$bfn
  494. echo " /home/bus/popufare/busunit/rootfs/etc/rc.local -> /etc/rc.local"
  495. sudo cp /home/bus/popufare/busunit/rootfs/etc/rc.local /etc/rc.local
  496. echo " setting up splash screen: /home/bus/popufare/busunit/rootfs/usr/share/plymouth/themes/pix/splash.png -> /usr/share/plymouth/themes/pix/splash.png"
  497. sudo cp -f /home/bus/popufare/busunit/rootfs/usr/share/plymouth/themes/pix/splash.png /usr/share/plymouth/themes/pix/splash.png
  498. fi
  499. echo ""
  500. ##### setup pi user welcome
  501. #####
  502. echo -n "Setup pi ser 'welcome' text splash screen? [Y/n]: "
  503. read textsplash
  504. if [[ "$textsplash" =~ ^[yY]?$ ]] ; then
  505. sudo mkdir -p /home/pi/bin
  506. sudo cp /home/bus/popufare/busunit/scripts/welcome_to_popufare.sh /home/pi/bin/welcome_to_popufare.sh
  507. sudo chown -R pi:pi /home/pi/bin
  508. sudo echo "/home/pi/bin/welcome_to_popufare.sh" >> /home/pi/.bashrc
  509. fi
  510. ##### setup legacy data directories
  511. #####
  512. echo -n "Setup legacy data directories? [y/N]: "
  513. read setuplegacy
  514. if [[ "$setuplegacy" =~ ^[yY]$ ]] ; then
  515. sudo mkdir -p /mnt/data
  516. sudo mkdir -p /mnt/data2
  517. sudo chown -R bus:bus /mnt/data
  518. sudo chown -R bus:bus /mnt/data2
  519. fi
  520. #####
  521. #####
  522. ##### final permissions setup
  523. #####
  524. echo "Setting up final permission for /home/bus/(bin|database|config)"
  525. sudo chown -R bus:bus /home/bus/bin
  526. sudo chown -R bus:bus /home/bus/database
  527. sudo chown -R bus:bus /home/bus/config
  528. echo ""
  529. if [[ "$tmpdir" != '' ]] ; then
  530. echo "... should remove $tmpdir"
  531. #rm -rf $tmdpri
  532. fi
  533. echo "done"