diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml new file mode 100644 index 0000000..c6be2b3 --- /dev/null +++ b/.github/workflows/shellcheck.yml @@ -0,0 +1,17 @@ +on: + - push + - pull_request + +name: "Shellcheck" +permissions: {} + +jobs: + shellcheck: + name: Shellcheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Run ShellCheck + uses: ludeeus/action-shellcheck@master + with: + severity: warning diff --git a/.github/workflows/shfmt.yml b/.github/workflows/shfmt.yml new file mode 100644 index 0000000..59ca713 --- /dev/null +++ b/.github/workflows/shfmt.yml @@ -0,0 +1,16 @@ +name: shfmt +on: + - pull_request + - push +jobs: + sh-checker: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Run the sh-checker + uses: luizm/action-sh-checker@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + sh_checker_shellcheck_disable: true + sh_checker_comment: true diff --git a/Blink.ino b/Blink.ino deleted file mode 100644 index 13b0271..0000000 --- a/Blink.ino +++ /dev/null @@ -1,33 +0,0 @@ -/* Mirte by default has the following pin connections: - * - * B3, A15 - PWM pins for motor A - * B14, B15 - PWM pins for motor B - * A0 - analog input intensity sensor left - * A1 - analog input intensity sensor right - * A9 - trigger for ultrasonic sensor front - * B8 - echo for ultrasonic sensor front - * A10 - trigger for ultrasnoic sensor side - * B9 - echo for ultrasonic sensor side - * B12 - left encoder - * B13 - right encoder - * - * Mirte does not use LEDs by default. For CSE2425 we connected - * the leds to the following pins: - * - * B10 - left LED - * B11 - right LED - */ - -// This is a standard blink setup (NOTE: you need to add P to the pin number) -int led = PB10; - -void setup() { - pinMode(led, OUTPUT); -} - -void loop() { - digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) - delay(1000); // wait for a second - digitalWrite(led, LOW); // turn the LED off by making the voltage LOW - delay(1000); // wait for a second -} diff --git a/README.md b/README.md new file mode 100644 index 0000000..a7c1e50 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# Mirte Install Scripts +Scripts that are ran during creation of the image and on the Mirte itself. + +## Stylecheck +- [shfmt](https://github.com/mvdan/sh): styling (whitespace) of all shell scripts +- [ShellCheck](https://github.com/koalaman/shellcheck): static analysis to find (possible) bugs. Only errors and warnings are enabled + +Check & format using their command line tools or vscode plugins. Or check the GitHub workflows with (act)[https://github.com/nektos/act]. \ No newline at end of file diff --git a/blink.sh b/blink.sh index 5b1cb9d..e287d8e 100755 --- a/blink.sh +++ b/blink.sh @@ -7,103 +7,102 @@ OPI2=$(grep "Orange Pi Zero 2" /proc/device-tree/model) RPI=$(grep -a "Raspberry" /proc/device-tree/model) if [ "$RPI" ]; then - echo none > /sys/class/leds/ACT/trigger - echo none > /sys/class/leds/PWR/trigger + echo none >/sys/class/leds/ACT/trigger + echo none >/sys/class/leds/PWR/trigger fi red_on() { - if [ "$OPI" ]; then - echo 'default-on' > /sys/class/leds/orangepi\:red\:status/trigger - elif [ "$OPI2" ]; then - echo '255' > /sys/class/leds/orangepi\:red\:power/brightness - elif [ "$RPI" ]; then - echo 1 > /sys/class/leds/PWR/brightness - fi + if [ "$OPI" ]; then + echo 'default-on' >/sys/class/leds/orangepi\:red\:status/trigger + elif [ "$OPI2" ]; then + echo '255' >/sys/class/leds/orangepi\:red\:power/brightness + elif [ "$RPI" ]; then + echo 1 >/sys/class/leds/PWR/brightness + fi } red_off() { - if [ "$OPI" ]; then - echo 'none' > /sys/class/leds/orangepi\:red\:status/trigger - elif [ "$OPI2" ]; then - echo '0' > /sys/class/leds/orangepi\:red\:power/brightness - elif [ "$RPI" ]; then - echo '0' > /sys/class/leds/PWR/brightness - fi + if [ "$OPI" ]; then + echo 'none' >/sys/class/leds/orangepi\:red\:status/trigger + elif [ "$OPI2" ]; then + echo '0' >/sys/class/leds/orangepi\:red\:power/brightness + elif [ "$RPI" ]; then + echo '0' >/sys/class/leds/PWR/brightness + fi } green_on() { - if [ "$OPI" ]; then - echo 'default-on' > /sys/class/leds/orangepi\:green\:pwr/trigger - elif [ "$OPI2" ]; then - echo '255' > /sys/class/leds/orangepi\:green\:status/brightness - elif [ "$RPI" ]; then - echo 1 > /sys/class/leds/ACT/brightness - fi + if [ "$OPI" ]; then + echo 'default-on' >/sys/class/leds/orangepi\:green\:pwr/trigger + elif [ "$OPI2" ]; then + echo '255' >/sys/class/leds/orangepi\:green\:status/brightness + elif [ "$RPI" ]; then + echo 1 >/sys/class/leds/ACT/brightness + fi } green_off() { - if [ "$OPI" ]; then - echo 'none' > /sys/class/leds/orangepi\:green\:pwr/trigger - elif [ "$OPI2" ]; then - echo '0' > /sys/class/leds/orangepi\:green\:status/brightness - elif [ "$RPI" ]; then - echo 0 > /sys/class/leds/ACT/brightness - fi + if [ "$OPI" ]; then + echo 'none' >/sys/class/leds/orangepi\:green\:pwr/trigger + elif [ "$OPI2" ]; then + echo '0' >/sys/class/leds/orangepi\:green\:status/brightness + elif [ "$RPI" ]; then + echo 0 >/sys/class/leds/ACT/brightness + fi } if ! [ "$OPI" ]; then - echo "Blinking" - echo "$VALUE" + echo "Blinking" + echo "$VALUE" - for (( repeat=0; repeat<5; repeat++ )); do - # Start sequence with fast blinking both - for (( i=0; i<10; i++ )); do - FAST=$(echo "scale=2; $BLINK_SPEED/20" | bc) - green_on - red_on - sleep "$FAST" - green_off - red_off - sleep "$FAST" - done - sleep $BLINK_SPEED + for ((repeat = 0; repeat < 5; repeat++)); do + # Start sequence with fast blinking both + for ((i = 0; i < 10; i++)); do + FAST=$(echo "scale=2; $BLINK_SPEED/20" | bc) + green_on + red_on + sleep "$FAST" + green_off + red_off + sleep "$FAST" + done + sleep $BLINK_SPEED - for (( i=0; i<${#VALUE}; i++ )); do - # Next character - green_on - sleep $BLINK_SPEED - green_off - sleep $BLINK_SPEED + for ((i = 0; i < ${#VALUE}; i++)); do + # Next character + green_on + sleep $BLINK_SPEED + green_off + sleep $BLINK_SPEED + if [ "${VALUE:i:1}" == "." ]; then + green_on + red_on + sleep $BLINK_SPEED + green_off + red_off + sleep $BLINK_SPEED + else + if [ "${VALUE:i:1}" == "0" ]; then + TWICE=$(echo "scale=2; $BLINK_SPEED*2" | bc) + sleep "$TWICE" + else + # Convert hex to decimal number + DEC_VAL=$(echo "obase=10; ibase=16; ${VALUE:i:1}" | bc) - if [ "${VALUE:$i:1}" == "." ]; then - green_on - red_on - sleep $BLINK_SPEED - green_off - red_off - sleep $BLINK_SPEED - else - if [ "${VALUE:$i:1}" == "0" ]; then - TWICE=$(echo "scale=2; $BLINK_SPEED*2" | bc) - sleep "$TWICE" - else - # Convert hex to decimal number - DEC_VAL=$(echo "obase=10; ibase=16; ${VALUE:$i:1}" | bc) + # Blink decimal number + for ((j = 0; j < DEC_VAL; j++)); do + red_on + sleep $BLINK_SPEED + red_off + sleep $BLINK_SPEED + done + fi + fi + done + done - # Blink decimal number - for (( j=0; j<${DEC_VAL}; j++ )); do - red_on - sleep $BLINK_SPEED - red_off - sleep $BLINK_SPEED - done - fi - fi - done - done - - # Reset to defaults - green_on - red_off + # Reset to defaults + green_on + red_off fi diff --git a/download_repos.sh b/download_repos.sh index 302a7cb..7be575d 100755 --- a/download_repos.sh +++ b/download_repos.sh @@ -7,6 +7,6 @@ sudo apt-get update sudo apt-get install -y python3-vcstool # Download all Mirte repositories -vcs import < repos.yaml --workers 1 #TODO: get yaml file as parameter +vcs import --workers 1 > /home/mirte/.bashrc +grep -qxF "source /opt/ros/noetic/setup.bash" /home/mirte/.bashrc || echo "source /opt/ros/noetic/setup.bash" >>/home/mirte/.bashrc source /opt/ros/noetic/setup.bash sudo rosdep init rosdep update @@ -37,12 +37,12 @@ sudo pip3 install pyzbar # Install Mirte ROS package mkdir -p /home/mirte/mirte_ws/src -cd /home/mirte/mirte_ws/src +cd /home/mirte/mirte_ws/src || exit ln -s $MIRTE_SRC_DIR/mirte-ros-packages . cd .. rosdep install -y --from-paths src/ --ignore-src --rosdistro noetic catkin build -grep -qxF "source /home/mirte/mirte_ws/devel/setup.bash" /home/mirte/.bashrc || echo "source /home/mirte/mirte_ws/devel/setup.bash" >> /home/mirte/.bashrc +grep -qxF "source /home/mirte/mirte_ws/devel/setup.bash" /home/mirte/.bashrc || echo "source /home/mirte/mirte_ws/devel/setup.bash" >>/home/mirte/.bashrc source /home/mirte/mirte_ws/devel/setup.bash # install missing python dependencies rosbridge @@ -68,7 +68,7 @@ sudo pip3 install pillow adafruit-circuitpython-ssd1306==2.12.1 # Install aio dependencies sudo pip3 install janus async-generator nest-asyncio git clone https://github.com/locusrobotics/aiorospy.git -cd aiorospy/aiorospy +cd aiorospy/aiorospy || exit sudo pip3 install . cd ../.. rm -rf aiorospy diff --git a/install_arduino.sh b/install_arduino.sh index 7deba3d..3ace341 100755 --- a/install_arduino.sh +++ b/install_arduino.sh @@ -50,7 +50,7 @@ sudo adduser mirte dialout # By default, armbian has ssh login for root enabled with password 1234. # The password need to be set to mirte_mirte so users can use the -# Arduino IDE remotely. +# Arduino IDE remotely. # TODO: when the Arduino IDE also supports ssh for non-root-users # this has to be changed echo -e "mirte_mirte\nmirte_mirte" | sudo passwd root diff --git a/install_fake_bt.sh b/install_fake_bt.sh index 7ec7b9e..2c012ee 100755 --- a/install_fake_bt.sh +++ b/install_fake_bt.sh @@ -29,7 +29,7 @@ sudo dpkg -i linux-headers*.deb wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.10.21.tar.xz xz -d -v linux-5.10.21.tar.xz tar xvf linux-5.10.21.tar linux-5.10.21/net/bluetooth -cd linux-5.10.21/net/bluetooth +cd linux-5.10.21/net/bluetooth || exit # Apply 'fix' sed -i 's/flt_type = HCI_FLT_CLEAR_ALL;/\/\/flt_type = HCI_FLT_CLEAR_ALL;/g' hci_core.c diff --git a/install_jupyter_ros.sh b/install_jupyter_ros.sh index 657c868..d5b04a8 100755 --- a/install_jupyter_ros.sh +++ b/install_jupyter_ros.sh @@ -8,7 +8,7 @@ sudo apt install -y python3 python3-venv python3-dev git libffi-dev # create and activate virtualenv # Due to a build error on numpy we need to install numpy and # padnas globally and us it in the virtual environment -cd /home/mirte +cd /home/mirte || exit sudo apt install -y python3-numpy python3-pandas python3 -m venv jupyter --system-site-packages source /home/mirte/jupyter/bin/activate diff --git a/install_mirte.sh b/install_mirte.sh index e1ee3c0..0f314f9 100755 --- a/install_mirte.sh +++ b/install_mirte.sh @@ -62,8 +62,8 @@ pip3 install numpy sudo apt install -y bluez joystick if [ "$(uname -a | grep sunxi)" != "" ]; then - # currently only supporting cheap USB dongles on OrangePi - ./install_fake_bt.sh + # currently only supporting cheap USB dongles on OrangePi + ./install_fake_bt.sh fi # Install Mirte documentation @@ -71,7 +71,7 @@ cd $MIRTE_SRC_DIR/mirte-documentation sudo apt install -y python3.8-venv libenchant-dev python3 -m venv docs-env source docs-env/bin/activate -pip install docutils==0.16.0 sphinx-tabs==3.2.0 #TODO: use files to freeze versions +pip install docutils==0.16.0 sphinx-tabs==3.2.0 #TODO: use files to freeze versions pip install wheel sphinx sphinx-prompt sphinx-rtd-theme sphinxcontrib-spelling sphinxcontrib-napoleon mkdir -p _modules/catkin_ws/src cd _modules diff --git a/install_web.sh b/install_web.sh index 56bdff6..57174e3 100755 --- a/install_web.sh +++ b/install_web.sh @@ -16,12 +16,12 @@ nodeenv --node=16.2.0 $MIRTE_SRC_DIR/mirte-web-interface/node_env . $MIRTE_SRC_DIR/mirte-web-interface/node_env/bin/activate # Install frontend -cd $MIRTE_SRC_DIR/mirte-web-interface/vue-frontend +cd $MIRTE_SRC_DIR/mirte-web-interface/vue-frontend || exit npm install . npm run build # Install backend -cd $MIRTE_SRC_DIR/mirte-web-interface/nodejs-backend +cd $MIRTE_SRC_DIR/mirte-web-interface/nodejs-backend || exit npm install . # Install wetty diff --git a/network_install.sh b/network_install.sh index e8b5f1d..1791f46 100755 --- a/network_install.sh +++ b/network_install.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash MIRTE_SRC_DIR=/usr/local/src/mirte @@ -22,8 +22,8 @@ sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf' # Install wifi-connect MY_ARCH=$(arch) -if [[ "$MY_ARCH" == "armv7l" ]]; then MY_ARCH="rpi"; fi -wget https://github.com/balena-os/wifi-connect/releases/download/v4.4.6/wifi-connect-v4.4.6-linux-$(echo "$MY_ARCH").tar.gz +if [[ $MY_ARCH == "armv7l" ]]; then MY_ARCH="rpi"; fi +wget https://github.com/balena-os/wifi-connect/releases/download/v4.4.6/wifi-connect-v4.4.6-linux-"$(echo "$MY_ARCH")".tar.gz tar -xf wifi-connect* sudo mv wifi-connect /usr/local/sbin rm wifi-connect* @@ -68,7 +68,7 @@ sudo bash -c 'echo "libcomposite" >> /etc/modules' # Generate wifi password (TODO: generate random password and put on NTFS) if [ ! -f /home/mirte/.wifi_pwd ]; then - bash -c 'echo mirte_mirte > /home/mirte/.wifi_pwd' + bash -c 'echo mirte_mirte > /home/mirte/.wifi_pwd' fi # Allow wifi_pwd to be modified using the web interface diff --git a/network_setup.sh b/network_setup.sh index 1fd722b..51bfef7 100755 --- a/network_setup.sh +++ b/network_setup.sh @@ -1,109 +1,105 @@ #!/bin/bash function start_avahi { - # Restart avahi-daemon, to clear all previous addresses and hosts - service avahi-daemon restart && sleep 1 - - # Publish avahi (not using daemon since we publish two addresses) - avahi-publish-address -R mirte.local $(hostname -I | awk '{print $1}') & - avahi-set-host-name `cat /etc/hostname` - avahi-publish-service `cat /etc/hostname` _mirte._tcp 80 & - avahi-publish-service `cat /etc/hostname` _arduino._tcp 80 & + # Restart avahi-daemon, to clear all previous addresses and hosts + service avahi-daemon restart && sleep 1 + + # Publish avahi (not using daemon since we publish two addresses) + avahi-publish-address -R mirte.local "$(hostname -I | awk '{print $1}')" & + avahi-set-host-name "$(cat /etc/hostname)" + avahi-publish-service "$(cat /etc/hostname)" _mirte._tcp 80 & + avahi-publish-service "$(cat /etc/hostname)" _arduino._tcp 80 & } - # This function basically just starts wifi-connect # only taking some limitations into account function start_acces_point { - # remove own connection from nm and killall - rm -rf /etc/NetworkManager/system-connections/`cat /etc/hostname`* - sudo killall -9 wifi-connect || /bin/true - sudo killall -9 blink.sh || /bin/true - echo "Killed all previous instances" - - # It takes some time for NetworkManager to find all - # networks. - nmcli con down `cat /etc/hostname` - iw dev wlan0 scan | grep SSID - nmcli device wifi list - echo "Rescanned networks" - - # Start wifi-connect (this starts the AP, and uses dnsmasq - # as DHCP server - wifi-connect -o 8080 -p `cat /home/mirte/.wifi_pwd` -s `cat /etc/hostname` & - - # Wait until the AP is up - until [ -f /etc/NetworkManager/system-connections/`cat /etc/hostname`.nmconnection ] - do - sleep .1 - echo " waiting for network" - done - - # And modify the network in a way that avahi mdns packages will - # get through - nmcli con modify `cat /etc/hostname` 802-11-wireless-security.proto wpa -# nmcli con modify `cat /etc/hostname` 802-11-wireless-security.group ccmp -# nmcli con modify `cat /etc/hostname` 802-11-wireless-security.pairwise ccmp - nmcli con down `cat /etc/hostname` - sleep 10 - nmcli con up `cat /etc/hostname` - - # Start all avahi addresses and services - start_avahi - - # Blink ssid-ID - UNIQUE_ID=$(cat /etc/hostname | cut -c7-12) - $MIRTE_SRC_DIR/mirte-install-scripts/blink.sh $UNIQUE_ID & + # remove own connection from nm and killall + rm -rf /etc/NetworkManager/system-connections/"$(cat /etc/hostname)"* + sudo killall -9 wifi-connect || /bin/true + sudo killall -9 blink.sh || /bin/true + echo "Killed all previous instances" + + # It takes some time for NetworkManager to find all + # networks. + nmcli con down "$(cat /etc/hostname)" + iw dev wlan0 scan | grep SSID + nmcli device wifi list + echo "Rescanned networks" + + # Start wifi-connect (this starts the AP, and uses dnsmasq + # as DHCP server + wifi-connect -o 8080 -p "$(cat /home/mirte/.wifi_pwd)" -s "$(cat /etc/hostname)" & + + # Wait until the AP is up + until [ -f /etc/NetworkManager/system-connections/"$(cat /etc/hostname)".nmconnection ]; do + sleep .1 + echo " waiting for network" + done + + # And modify the network in a way that avahi mdns packages will + # get through + nmcli con modify "$(cat /etc/hostname)" 802-11-wireless-security.proto wpa + # nmcli con modify `cat /etc/hostname` 802-11-wireless-security.group ccmp + # nmcli con modify `cat /etc/hostname` 802-11-wireless-security.pairwise ccmp + nmcli con down "$(cat /etc/hostname)" + sleep 10 + nmcli con up "$(cat /etc/hostname)" + + # Start all avahi addresses and services + start_avahi + + # Blink ssid-ID + UNIQUE_ID=$(cat /etc/hostname | cut -c7-12) + $MIRTE_SRC_DIR/mirte-install-scripts/blink.sh $UNIQUE_ID & } function check_connection { - # Remove my own networks - sudo rm /etc/NetworkManager/system-connections/`cat /etc/hostname`.* - - - # Only look for networks if you already connected to one - nr=`ls /etc/NetworkManager/system-connections/ | wc -l` - if [ "$nr" -gt 0 ]; then - # Wait for a connection with a known ssid (timeout 10 seconds) - nmcli device set wlan0 autoconnect yes - TIMEOUT=25; - NEXT_WAIT_TIME=0; - until [ $NEXT_WAIT_TIME -eq $TIMEOUT ] || sudo nmcli con show --active | grep wlan0 ; do - echo "waiting for connection" - sleep 1 - let "NEXT_WAIT_TIME=NEXT_WAIT_TIME+1" - done - fi - - # Get wifi connection if connected - if sudo nmcli con show --active | grep wlan0 ; then - # Bugfix (see network_install.sh) - sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf - - printf 'Connected to wifi connection:' - nmcli con show --active | grep wlan0 - $MIRTE_SRC_DIR/mirte-install-scripts/blink.sh $(hostname -I) & - start_avahi - else - printf 'No connection found, starting AP with wifi connect\n' - start_acces_point - - # Restart the whole network process when connection did not take place - while inotifywait -e modify /etc/NetworkManager/system-connections/`cat /etc/hostname`.nmconnection; do echo "hoi" ; done -# TODO: check: mybe this can be enabled again (currently this does not make thesaved wifi peristent -# printf "Networkmanager settings changed, restarting wifi-connect\n" -# sleep 5 # Give wifi-connect the possibility to change the settings -# sudo killall -9 wifi-connect || /bin/true -# nmcli con down `cat /etc/hostname` -# iw dev wlan0 scan | grep SSID -# nmcli device wifi list -# echo "Rescanned networks" -# printf "And doing the next thing\n" -# check_connection - fi + # Remove my own networks + sudo rm /etc/NetworkManager/system-connections/"$(cat /etc/hostname)".* + + # Only look for networks if you already connected to one + nr=$(ls /etc/NetworkManager/system-connections/ | wc -l) + if [ "$nr" -gt 0 ]; then + # Wait for a connection with a known ssid (timeout 10 seconds) + nmcli device set wlan0 autoconnect yes + TIMEOUT=25 + NEXT_WAIT_TIME=0 + until [ $NEXT_WAIT_TIME -eq $TIMEOUT ] || sudo nmcli con show --active | grep wlan0; do + echo "waiting for connection" + sleep 1 + let "NEXT_WAIT_TIME=NEXT_WAIT_TIME+1" + done + fi + + # Get wifi connection if connected + if sudo nmcli con show --active | grep wlan0; then + # Bugfix (see network_install.sh) + sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf + + printf 'Connected to wifi connection:' + nmcli con show --active | grep wlan0 + $MIRTE_SRC_DIR/mirte-install-scripts/blink.sh "$(hostname -I)" & + start_avahi + else + printf 'No connection found, starting AP with wifi connect\n' + start_acces_point + + # Restart the whole network process when connection did not take place + while inotifywait -e modify /etc/NetworkManager/system-connections/"$(cat /etc/hostname)".nmconnection; do echo "hoi"; done + # TODO: check: mybe this can be enabled again (currently this does not make thesaved wifi peristent + # printf "Networkmanager settings changed, restarting wifi-connect\n" + # sleep 5 # Give wifi-connect the possibility to change the settings + # sudo killall -9 wifi-connect || /bin/true + # nmcli con down `cat /etc/hostname` + # iw dev wlan0 scan | grep SSID + # nmcli device wifi list + # echo "Rescanned networks" + # printf "And doing the next thing\n" + # check_connection + fi } - MIRTE_SRC_DIR=/usr/local/src/mirte $MIRTE_SRC_DIR/mirte-install-scripts/usb_ethernet.sh @@ -112,16 +108,16 @@ $MIRTE_SRC_DIR/mirte-install-scripts/usb_ethernet.sh # This must be run every time on boot, since it should # be generated on first boot (so not when generating # the image in network_setup.sh) -if [ ! -f /etc/ssid ] || [[ `cat /etc/hostname` == "Mirte-XXXXXX" ]]; then - UNIQUE_ID=$(openssl rand -hex 3) - MIRTE_SSID=Mirte-$(echo ${UNIQUE_ID^^}) - sudo bash -c 'echo '$MIRTE_SSID' > /etc/hostname' - sudo ln -s /etc/hostname /etc/ssid - # And add them to the hosts file - sudo bash -c 'echo 127.0.0.1 '$MIRTE_SSID' >> /etc/hosts' - sudo bash -c 'echo "127.0.0.1 mirte" >> /etc/hosts' - # Not needed anymore once we first generate the SSID and then start the network - sudo bash -c 'echo "127.0.0.1 Mirte-XXXXXX" >> /etc/hosts' +if [ ! -f /etc/ssid ] || [[ $(cat /etc/hostname) == "Mirte-XXXXXX" ]]; then + UNIQUE_ID=$(openssl rand -hex 3) + MIRTE_SSID=Mirte-$(echo ${UNIQUE_ID^^}) + sudo bash -c 'echo '$MIRTE_SSID' > /etc/hostname' + sudo ln -s /etc/hostname /etc/ssid + # And add them to the hosts file + sudo bash -c 'echo 127.0.0.1 '$MIRTE_SSID' >> /etc/hosts' + sudo bash -c 'echo "127.0.0.1 mirte" >> /etc/hosts' + # Not needed anymore once we first generate the SSID and then start the network + sudo bash -c 'echo "127.0.0.1 Mirte-XXXXXX" >> /etc/hosts' fi check_connection diff --git a/run-avrdude b/run-avrdude index 22078d6..bd38927 100755 --- a/run-avrdude +++ b/run-avrdude @@ -2,14 +2,12 @@ #TODO: this now only works for STM, also make nano work #TODO: maybe merge this into run.sh from aruino repo? - # Stop ROS when uploading new code sudo service mirte-ros stop -if test "$1" == "upload" -then - sudo arduino-cli upload -p /dev/ttyACM0 -b STM32:stm32:GenF1:pnum=BLACKPILL_F103C8,upload_method=dfu2Method,xserial=generic,usb=CDCgen,xusb=FS,opt=osstd,rtlib=nano -i /home/mirte/firmware.bin +if test "$1" == "upload"; then + sudo arduino-cli upload -p /dev/ttyACM0 -b STM32:stm32:GenF1:pnum=BLACKPILL_F103C8,upload_method=dfu2Method,xserial=generic,usb=CDCgen,xusb=FS,opt=osstd,rtlib=nano -i /home/mirte/firmware.bin else - objcopy --input-target=ihex --output-target=binary /tmp/sketch.hex /tmp/sketch.bin - runuser -l mirte -c 'sudo arduino-cli upload -p /dev/ttyACM0 -b STM32:stm32:GenF1:pnum=BLACKPILL_F103C8,upload_method=dfu2Method,xserial=generic,usb=CDCgen,xusb=FS,opt=osstd,rtlib=nano -i /tmp/sketch.bin' + objcopy --input-target=ihex --output-target=binary /tmp/sketch.hex /tmp/sketch.bin + runuser -l mirte -c 'sudo arduino-cli upload -p /dev/ttyACM0 -b STM32:stm32:GenF1:pnum=BLACKPILL_F103C8,upload_method=dfu2Method,xserial=generic,usb=CDCgen,xusb=FS,opt=osstd,rtlib=nano -i /tmp/sketch.bin' fi diff --git a/run_arduino.sh b/run_arduino.sh index 504448c..9093a1f 100755 --- a/run_arduino.sh +++ b/run_arduino.sh @@ -4,59 +4,44 @@ # with mcu_type and arduino_folder optional # Check if ROS is running -ROS_RUNNING=`ps aux | grep [r]osmaster | wc -l` +ROS_RUNNING=$(ps aux | grep -c "[r]osmaster") # Stop ROS when uploading new code -if test "$1" == "upload" && [[ $ROS_RUNNING == "1" ]] -then - echo "STOPPING ROS" - sudo service mirte-ros stop || /bin/true +if test "$1" == "upload" && [[ $ROS_RUNNING == "1" ]]; then + echo "STOPPING ROS" + sudo service mirte-ros stop || /bin/true fi # Different build scripts -if test "$1" == "build" -then - arduino-cli -v compile --fqbn STM32:stm32:GenF1:pnum=BLUEPILL_F103C8,upload_method=dfu2Method,xserial=generic,usb=CDCgen,xusb=FS,opt=osstd,rtlib=nano /home/mirte/arduino_project/$2 +if test "$1" == "build"; then + arduino-cli -v compile --fqbn STM32:stm32:GenF1:pnum=BLUEPILL_F103C8,upload_method=dfu2Method,xserial=generic,usb=CDCgen,xusb=FS,opt=osstd,rtlib=nano /home/mirte/arduino_project/$2 fi -if test "$1" == "build_nano" -then - arduino-cli -v compile --fqbn arduino:avr:nano:cpu=atmega328 /home/mirte/arduino_project/$2 +if test "$1" == "build_nano"; then + arduino-cli -v compile --fqbn arduino:avr:nano:cpu=atmega328 /home/mirte/arduino_project/$2 fi -if test "$1" == "build_nano_old" -then - arduino-cli -v compile --fqbn arduino:avr:nano:cpu=atmega328old /home/mirte/arduino_project/$2 +if test "$1" == "build_nano_old"; then + arduino-cli -v compile --fqbn arduino:avr:nano:cpu=atmega328old /home/mirte/arduino_project/$2 fi -if test "$1" == "build_uno" -then - arduino-cli -v compile --fqbn arduino:avr:uno /home/mirte/arduino_project/$2 +if test "$1" == "build_uno"; then + arduino-cli -v compile --fqbn arduino:avr:uno /home/mirte/arduino_project/$2 fi - - # Different upload scripts -if test "$1" == "upload" || test "$1" == "upload_stm32" -then - arduino-cli -v upload -p /dev/ttyACM0 --fqbn STM32:stm32:GenF1:pnum=BLUEPILL_F103C8,upload_method=dfu2Method,xserial=generic,usb=CDCgen,xusb=FS,opt=osstd,rtlib=nano /home/mirte/arduino_project/$2 +if test "$1" == "upload" || test "$1" == "upload_stm32"; then + arduino-cli -v upload -p /dev/ttyACM0 --fqbn STM32:stm32:GenF1:pnum=BLUEPILL_F103C8,upload_method=dfu2Method,xserial=generic,usb=CDCgen,xusb=FS,opt=osstd,rtlib=nano /home/mirte/arduino_project/$2 fi -if test "$1" == "upload_nano" -then - arduino-cli -v upload -p /dev/ttyUSB0 --fqbn arduino:avr:nano:cpu=atmega328 /home/mirte/arduino_project/$2 +if test "$1" == "upload_nano"; then + arduino-cli -v upload -p /dev/ttyUSB0 --fqbn arduino:avr:nano:cpu=atmega328 /home/mirte/arduino_project/$2 fi -if test "$1" == "upload_nano_old" -then - arduino-cli -v upload -p /dev/ttyUSB0 --fqbn arduino:avr:nano:cpu=atmega328old /home/mirte/arduino_project/$2 +if test "$1" == "upload_nano_old"; then + arduino-cli -v upload -p /dev/ttyUSB0 --fqbn arduino:avr:nano:cpu=atmega328old /home/mirte/arduino_project/$2 fi -if test "$1" == "upload_uno" -then - arduino-cli -v upload -p /dev/ttyACM0 --fqbn arduino:avr:uno /home/mirte/arduino_project/$2 +if test "$1" == "upload_uno"; then + arduino-cli -v upload -p /dev/ttyACM0 --fqbn arduino:avr:uno /home/mirte/arduino_project/$2 fi - - - # Start ROS again -if test "$1" == "upload" && test "$2" == "Telemetrix4Arduino" && [[ $ROS_RUNNING == "1" ]] -then - sudo service mirte-ros start - echo "STARTING ROS" +if test "$1" == "upload" && test "$2" == "Telemetrix4Arduino" && [[ $ROS_RUNNING == "1" ]]; then + sudo service mirte-ros start + echo "STARTING ROS" fi diff --git a/usb_ethernet.sh b/usb_ethernet.sh index 2d74aac..a64b629 100755 --- a/usb_ethernet.sh +++ b/usb_ethernet.sh @@ -7,8 +7,8 @@ MIRTE_SRC_DIR=/usr/local/src/mirte sudo killall -9 dnsmasq -sudo $MIRTE_SRC_DIR/mirte-install-scripts/ev3-usb.sh down `ls /sys/class/udc | tail -n1` -sudo $MIRTE_SRC_DIR/mirte-install-scripts/ev3-usb.sh up `ls /sys/class/udc | tail -n1` +sudo $MIRTE_SRC_DIR/mirte-install-scripts/ev3-usb.sh down "$(ls /sys/class/udc | tail -n1)" +sudo $MIRTE_SRC_DIR/mirte-install-scripts/ev3-usb.sh up "$(ls /sys/class/udc | tail -n1)" # For now, we just create a different IP address for each interface. We need # to change this to private namespaces (see below). In order to getinthernet @@ -35,15 +35,11 @@ sudo iptables -A FORWARD -i usb1 -o wlan0 -j ACCEPT #and forward all traffic to locahost sudo iptables -t nat -A POSTROUTING -i usb1 -d 192.168.43.1 -j DNAT --to-destination 127.0.0.1 - - -# For now we have to start the dhcp server before wificonnect. Not needed +# For now we have to start the dhcp server before wificonnect. Not needed # after we moved to different namespaces # For some reason we neet to set the dns-server manually sudo dnsmasq --address=/#/192.168.43.1 --dhcp-range=192.168.43.10,192.168.43.100 --conf-file --domain-needed --bogus-priv --server=8.8.8.8 --dhcp-option=option:dns-server,8.8.8.8 --interface=usb1 --except-interface=lo --bind-interfaces - - # Since we want both networks to have the same IP address as the wifi AP (192.168.42.1) # we need to have a seperate network namespace for both of them. diff --git a/wifi-watchdog.sh b/wifi-watchdog.sh index 4918e51..1777f88 100755 --- a/wifi-watchdog.sh +++ b/wifi-watchdog.sh @@ -2,15 +2,15 @@ #echo "begin watchdog" > /home/mirte/test.txt -echo "wifi watchdog serviec opnieuw gestart" > /dev/kmsg +# echo "wifi watchdog service restarted" > /dev/kmsg -sub="xradio" +# sub="xradio" dmesg --follow | while read -r line; do - if `echo $line | grep -q "xradio WSM-ERR: CMD timeout!"`; then - echo "CRASH! REBOOT!" > /dev/kmsg - echo $line >> /home/mirte/test.txt -# reboot -f now - echo b > /proc/sysrq-trigger - fi + if echo "$line" | grep -q "xradio WSM-ERR: CMD timeout!"; then + echo "CRASH! REBOOT!" >/dev/kmsg + echo "$line" >>./test.txt + # reboot -f now + echo b >/proc/sysrq-trigger + fi done