From c2fbfd2b8635b53ee92650d9d9eb8e7209ab410b Mon Sep 17 00:00:00 2001 From: Patrick McGuire Date: Thu, 28 Oct 2021 12:52:42 -0400 Subject: [PATCH] testing new installer --- Birders_Guide_Installer.sh | 54 +------------------------- scripts/birdnet-pi-config | 78 ++++++++++++++++++++++++++++++++++---- 2 files changed, 72 insertions(+), 60 deletions(-) diff --git a/Birders_Guide_Installer.sh b/Birders_Guide_Installer.sh index c2c88b1..ea1f6ea 100755 --- a/Birders_Guide_Installer.sh +++ b/Birders_Guide_Installer.sh @@ -15,39 +15,6 @@ information" exit 1 fi -install_zram_swap() { - echo - echo "Configuring zram.service" - sudo touch /etc/modules-load.d/zram.conf - echo 'zram' | sudo tee /etc/modules-load.d/zram.conf - sudo touch /etc/modprobe.d/zram.conf - echo 'options zram num_devices=1' | sudo tee /etc/modprobe.d/zram.conf - sudo touch /etc/udev/rules.d/99-zram.rules - echo 'KERNEL=="zram0", ATTR{disksize}="4G",TAG+="systemd"' \ - | sudo tee /etc/udev/rules.d/99-zram.rules - sudo touch /etc/systemd/system/zram.service - echo "Installing zram.service" - cat << EOF | sudo tee /etc/systemd/system/zram.service &> /dev/null -[Unit] -Description=Swap with zram -After=multi-user.target - -[Service] -Type=oneshot -RemainAfterExit=true -ExecStartPre=/sbin/mkswap /dev/zram0 -ExecStart=/sbin/swapon /dev/zram0 -ExecStop=/sbin/swapoff /dev/zram0 - -[Install] -WantedBy=multi-user.target -EOF - sudo systemctl enable zram - echo "Rebooting the system in 5 seconds" - sleep 5 - sudo reboot -} - stage_1() { echo echo "Beginning Stage 1" @@ -61,16 +28,8 @@ stage_1() { echo "Installing git" sudo apt install -qqy git fi - ZRAM="$(swapon --show=SIZE,NAME | awk -FG '!/SIZE/ && /zram/ {print $1}')" - [ ! -z ${ZRAM} ] || ZRAM=0 - if [ ${ZRAM} -lt 4 ];then - install_zram_swap - else - touch ${HOME}/stage_1_complete - echo "Stage 1 complete" - stage_2 - exit - fi + touch ${HOME}/stage_1_complete + echo "Stage 1 complete" } stage_2() { @@ -102,7 +61,6 @@ and then close the Mouse Pad editing window to continue." else EDITOR=nano fi - set -x $EDITOR ${my_dir}/Birders_Guide_Installer_Configuration.txt while pgrep $EDITOR &> /dev/null;do sleep 1 @@ -133,14 +91,6 @@ Good luck!" exit 1 fi echo "Installing the BirdNET-Pi configuration file." - [ -f ${my_dir}/soundcard_params.txt ] || touch ${my_dir}/soundcard_params.txt - SOUND_PARAMS="${HOME}/BirdNET-Pi/soundcard_params.txt" - SOUND_CARD="$(sudo -u pi aplay -L \ - | grep -e '^hw' \ - | cut -d, -f1 \ - | grep -ve 'vc4' -e 'Head' -e 'PCH' \ - | uniq)" - script -c "arecord -D ${SOUND_CARD} --dump-hw-params" -a ${SOUND_PARAMS} &> /dev/null install_birdnet_config || exit 1 echo "Installing BirdNET-Lite" if ${my_dir}/scripts/install_birdnet.sh << EOF ; then diff --git a/scripts/birdnet-pi-config b/scripts/birdnet-pi-config index d31310d..4c18b10 100755 --- a/scripts/birdnet-pi-config +++ b/scripts/birdnet-pi-config @@ -1,9 +1,10 @@ -#!/bin/sh +#!/usr/bin/env bash # Altered from raspi-config tool below # https://github.com/RPi-Distro/birdnetpi-config # # See LICENSE file for copyright and license details # Copyright (c) 2012 Alex Bradbury +set -x birdnetpi_dir=/home/pi/BirdNET-Pi branch=newinstaller INTERACTIVE=True @@ -365,6 +366,65 @@ get_vnc() { fi } +do_config_zram() { + if [ -e /etc/udev/rules.d/99-zram.rules ]; then + ## get current swap allocation from /etc/udev/rules.d/99-zram.rules + size="$(awk -F\" '{print $4}' /etc/udev/rules.d/99-zram.rules)" + else + size="4G" + fi + new_size=$(whiptail --inputbox "How much memory (G) should the zRAM swap partition have? Choose 1G, 2G, or 4G - 4G recommended" \ + 19 70 -- "$size" 3>&1 1>&2 2>&3) + ASK_TO_REBOOT=1 +} + +do_install_zram() { + echo "Configuring zram.service" + touch /etc/modules-load.d/zram.conf + echo 'zram' > /etc/modules-load.d/zram.conf + touch /etc/modprobe.d/zram.conf + echo 'options zram num_devices=1' > /etc/modprobe.d/zram.conf + touch /etc/udev/rules.d/99-zram.rules + echo "KERNEL==\"zram0\", ATTR{disksize}=\"${new_size}\",TAG+=\"systemd\"" \ + > /etc/udev/rules.d/99-zram.rules + touch /etc/systemd/system/zram.service + echo "Installing zram.service" + cat << EOF > /etc/systemd/system/zram.service +[Unit] +Description=Swap with zram +After=multi-user.target + +[Service] +Type=oneshot +RemainAfterExit=true +ExecStartPre=/sbin/mkswap /dev/zram0 +ExecStart=/sbin/swapon /dev/zram0 +ExecStop=/sbin/swapoff /dev/zram0 + +[Install] +WantedBy=multi-user.target +EOF + systemctl enable zram +} + +do_zram_menu() { + whiptail --yesno "Would like to enable the zram swapping kernel module?" --defaultno 20 60 2 + RET=$? + if [ $RET -eq 0 ]; then + do_config_zram + do_install_zram + STATUS=enabled + elif [ $RET -eq 1 ]; then + if [ -e /etc/udev/rules.d/99-zram.rules ];then + systemctl disable --now zram + fi + STATUS=disabled + else + return $RET + fi + whiptail --msgbox "ZRAM swapping is $STATUS" 20 60 1 +} + do_vnc() { DEFAULT=--defaultno if [ $(get_vnc) -eq 0 ]; then @@ -593,7 +653,7 @@ do_wifi_ssid_passphrase() { return $RET } -do_update() { +do_update_os() { apt update && apt -y full-upgrade ASK_TO_REBOOT=1 } @@ -631,6 +691,9 @@ do_system_menu() { "Password" "Change password for the '$USER' user" \ "Audio" "Select audio device you'd like BirdNET-Pi to use" \ "Wireless LAN" "Enter SSID and passphrase" \ + "Update the OS" "Update the underlying operating system" \ + "Interface Options" "Enable/Disable SSH and VNC" \ + "Configure zRAM" "Enable/Disable zRAM" \ 3>&1 1>&2 2>&3) else exit @@ -643,6 +706,9 @@ do_system_menu() { Password*) do_change_pass ;; Audio*) do_audio ;; Wireless*) do_wifi_ssid_passphrase ;; + Update*) do_update_os ;; + Interface*) do_interface_menu ;; + Configure*) do_zram_menu ;; *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;; esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1 fi @@ -703,11 +769,9 @@ if [ "$INTERACTIVE" = True ]; then while true; do if is_pi ; then FUN=$(whiptail --title "BirdNET-Pi Software Configuration Tool (birdnetpi-config)" --backtitle "$(cat /proc/device-tree/model)" --menu "Setup Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Finish --ok-button Select \ - "System Options" "Configure system settings" \ - "Interface Options" "Configure connections to peripherals" \ "Localisation Options" "Configure language and regional settings" \ - "Update the OS" "Update the underlying operating system" \ "Install BirdNET-PI" "Install BirdNET-Pi" \ + "System Options" "Configure system settings" \ 3>&1 1>&2 2>&3) else exit @@ -717,11 +781,9 @@ if [ "$INTERACTIVE" = True ]; then do_finish elif [ $RET -eq 0 ]; then case "$FUN" in - System*) do_system_menu ;; - Interface*) do_interface_menu ;; Localisation*) do_internationalisation_menu ;; - Update*) do_update;; Install*) do_install_birdnet;; + System*) do_system_menu ;; *) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;; esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1 else