#!/bin/bash # # Copyright (c) 2020 Clementine Computing LLC. # # This file is part of PopuFare. # # PopuFare is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # PopuFare is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with PopuFare. If not, see . # # This script is meant to be run from a USB stick, say, to deploy # this site specific files on a DIU. # # This includes # # * The private SSH key # * The `common_values.sh` file # * The `diu_ui_site_specific.js` admin interface file # * Any paddles that might need transfer # # This will look for a local `data` directory with all the appropriate files # BASEDIR="data" SSH_FILE=$BASEDIR/id_rsa COM_VAL=$BASEDIR/common_values.sh SRV_LST=$BASEDIR/server_list SYNC_PORT=$BASEDIR/sync_port SYNC_SRV_DESC=$BASEDIR/sync_server_desc SYNC_TARGET=$BASEDIR/sync_target DRIVER_FN=$BASEDIR/drivers.txt EQUIP_FN=$BASEDIR/equipnum.txt RULE_FN=$BASEDIR/rules.scm DIU_UI=$BASEDIR/diu_ui_site_specific.js DO_CLEANUP_INSTALL=1 if [[ "$DO_CLEANUP_INSTALL" != "" ]] ; then echo "doing 'cleanup install'" bd="../popufare" mkdir -p .tmp btd=`mktemp -d` btd=`basename $btd` mv /tmp/$btd .tmp/$btd td=".tmp/$btd" echo " Making temporary diectory for original copies ($td)" apt-get update 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 apt-get autoremove -y ### ## See https://community.sixfab.com/t/how-to-remove-interface-wwan0/262 echo "attempting to disable wwan0 interface (adding blacklist for 'qmi_wwan', 'cd_wmd' to /etc/modprobe.d/raspi-blacklist.conf)" mkdir -p /etc/modprobe.d echo "blacklist qmi_wwan" >> /etc/modprobe.d/raspi-blacklist.conf echo "blacklist cdc_wdm" >> /etc/modprobe.d/raspi-blacklist.conf chmod 644 /etc/modprobe.d/raspi-blacklist.conf ### systemctl stop serial-getty@ttyAMA0.service systemctl mask serial-getty@ttyAMA0.service cp /etc/ppp/ip-up $td/ip-up cp /etc/ppp/ip-down $td/ip-down cp $bd/busunit/ppp-dialer/etc/ppp/ip-up /etc/ppp/ip-up cp $bd/busunit/ppp-dialer/etc/ppp/ip-down /etc/ppp/ip-down cp $bd/busunit/scripts/custom /home/bus/bin/custom cp $bd/busunit/scripts/connection_tether-ppp.sh /home/bus/bin/connection_tether.sh echo " Saving /boot/cmdline.txt to $td/cmdline.txt" cp /boot/cmdline.txt $td/cmdline.txt sed -i 's/console=serial0,115200 //' /boot/cmdline.txt ### mkdir -p /home/pi/bin cp $bd/busunit/scripts/welcome_to_popufare.sh /home/pi/bin/welcome_to_popufare.sh chown -R pi:pi /home/pi/bin echo "/home/pi/bin/welcome_to_popufare.sh" >> /home/pi/.bashrc ### echo " compiling and installing ichthyic-passthrough" bash -c " cd $bd/busunit/PIU/shim ; ./cmp.sh ; cp ./ichthyic-passthrough /home/bus/bin" echo " installing popufare_monitor script" bash -c " cp -f $bd/busunit/scripts/popufare_monitor /home/bus/bin/popufare_monitor" echo " enabling ichthyic (touch /home/bus/config/popufare.ichthyic)" bash -c " touch /home/bus/config/popufare.ichthyic ; chown bus:bus /home/bus/config/popufare.ichthyic" echo " setting root crontab to call popufare_monitor (using $bd/busunit/scripts/crontab.root)" bash -c " crontab $bd/busunit/scripts/crontab.root " newhostname=popufare-`pwgen 8 1` echo " Using hostname $newhostname" echo " Saving /etc/hostname and /etc/hosts to $td" cp /etc/hostname $td/hostname cp /etc/hosts $td/hosts echo "$newhostname" > /etc/hostname tfn=`mktemp` echo -e '127.0.0.1\tlocalhost' > $tfn echo -e '::1\t\tlocalhost ip6-localhost ip6-loopback' >> $tfn echo -e 'ff02::1\t\tip6-allnodes' >> $tfn echo -e 'ff02::2\t\tip6-allrouters' >> $tfn echo '' >> $tfn echo -e '127.0.1.1\t'"$newhostname" >> $tfn echo " Creating new /etc/hosts file" mv $tfn /etc/hosts chmod 644 /etc/hosts echo " Removing stale Xauth cookie" xauth remove popufaredev/unix:0 echo " Removing stale Singletone for Chromium" rm -f /root/.config/[cC]hromium/[Ss]ingleton* rm -f /home/pi/.config/[cC]hromium/[Ss]ingleton* rm -f /home/bus/.config/[cC]hromium/[Ss]ingleton* echo " REMEMBER TO SET THE LOGIN AND I2C FROM raspi-config!!!!" echo " ....." echo " PRESS ANY KEY TO ENTER raspi-config" echo " ....." read raspi-config fi if [[ -e "$SSH_FILE" ]] ; then echo "# deploying SSH file $SSH_FILE to /home/bus/.ssh" cp -L -f "$SSH_FILE" /home/bus/.ssh/id_rsa cp -L -f "$SSH_FILE" /etc/ppp/id_rsa_bus chown bus:bus /home/bus/.ssh/id_rsa chmod a-rwx /home/bus/.ssh/id_rsa chmod u+r /home/bus/.ssh/id_rsa chmod a-rwx /etc/ppp/id_rsa_bus chmod u+r /etc/ppp/id_rsa_bus else echo "# FILE NOT FOUND (SSH id_rsa): $SSH_FILE" fi if [[ -e "$COM_VAL" ]] ; then echo "# deploying common_values.sh file $COM_VAL to /home/bus/config/common_values.sh" cp -L -f "$COM_VAL" /home/bus/bin/common_values.sh else echo "# FILE NOT FOUND (COMMON VALUES): $COM_VAL" fi ### if [[ -e "$SRV_LST" ]] ; then echo "# deploying server list file: $SRV_LST -> /home/bus/config/server/server_list" cp -L -f "$SRV_LST" /home/bus/config/server/server_list else echo "# FILE NOT FOUND (SERVER LIST): $SRV_LST" fi if [[ -e "$SYNC_PORT" ]] ; then echo "# deploying sync port file: $SRV_PORT -> /home/bus/config/server/sync_port" cp -L -f "$SYNC_PORT" /home/bus/config/server/sync_port else echo "# FILE NOT FOUND (SYNC PORT): $SYNC_PORT" fi if [[ -e "$SYNC_SRV_DESC" ]] ; then echo "# deploying server list file: $SRV_SRV_DESC -> /home/bus/config/server/sync_server_desc" cp -L -f "$SYNC_SRV_DESC" /home/bus/config/server/sync_server_desc else echo "# FILE NOT FOUND (SYNC DESC): $SYNC_SRV_DESC" fi if [[ -e "$SYNC_TARGET" ]] ; then echo "# deploying server list file: $SRV_TARGET -> /home/bus/config/server/sync_target" cp -L -f "$SYNC_TARGET" /home/bus/config/server/sync_target else echo "# FILE NOT FOUND (SYNC TARGET): $SYNC_TARGET" fi ### if [[ -e "$DRIVER_FN" ]] ; then echo "# deploying drivers.txt file $DRIVER_FN to /home/bus/config/drivers.txt" cp -L -f "$DRIVER_FN" /home/bus/config/drivers.txt else echo "# FILE NOT FOUND (DRIVERS): $DRIVER_FN" fi if [[ -e "$EQUIP_FN" ]] ; then echo "# deploying equipnum.txt file $EQUIP_FN to /home/bus/config/equipnum.txt" cp -L -f "$EQUIP_FN" /home/bus/bin/equipnum.txt else echo "# FILE NOT FOUND (EQUIPNUM): $EQUIP_FN" fi if [[ -e "$RULE_FN" ]] ; then echo "# deploying rules.scm file $RULE_FN to /home/bus/config/rules.scm" cp -L -f "$RULE_FN" /home/bus/config/rules.scm else echo "# FILE NOT FOUND (RULES): $RULE_FN" fi ### if [[ -e "$DIU_UI" ]] ; then echo "# deploying diu_site_specific file: $DIU_UI -> /home/bus/config/html/js/diu_site_sepcific.js" cp -L -f "$DIU_UI" /home/bus/config/html/js/diu_ui_site_specific.js else echo "# FILE NOT FOUND (DIU SITE SPECIFIC): $DIU_UI" fi for pfn in `find data -name '*.paddle' -type f` ; do bpfn=`basename $pfn` echo "# deploying paddle file: $pfn -> /home/bus/config/$bpfn" cp -L -f "$pfn" /home/bus/config/$bpfn done echo "# done"