From 4b81e4de6bc0004442caebf0a107dfc133cdb272 Mon Sep 17 00:00:00 2001 From: Ruixi Zhou Date: Sun, 1 Dec 2024 16:55:37 +0800 Subject: [PATCH] Using gs-applyconf.sh to check and apply configuration in gs.conf Signed-off-by: Ruixi Zhou --- README.md | 4 +- gs/gs-applyconf.sh | 168 +++++++++++++++++++++++++++++++++++++++++++ gs/gs-init.sh | 8 +-- gs/gs.sh | 175 +++------------------------------------------ gs/install.sh | 15 +--- 5 files changed, 185 insertions(+), 185 deletions(-) create mode 100755 gs/gs-applyconf.sh diff --git a/README.md b/README.md index 8a81217..5a3fc3b 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,7 @@ GS Directory Tree │   ├── channel-scan.sh │   ├── fan.sh │   ├── gs-init.sh + │   ├── gs-applyconf.sh │   ├── gs.sh │   ├── rk3566-dwc3-otg-role-switch.dts │   ├── rk3566-hdmi-max-resolution-4k.dts @@ -156,13 +157,10 @@ Configuration [ gs.conf for details ] TODO ---- -* Check remaining space before recording * Automatically select the video storage location according to the priority of external storage > TF card > emmc -* [wfb-ng](https://github.com/svpcom/wfb-ng) cluster mode support * [Adaptive-Link](https://github.com/sickgreg/OpenIPC-Adaptive-Link) support * [improver](https://github.com/OpenIPC/improver) support * Change the built-in LED to a normal GPIO LED -* USB WiFi tx power Configuration * Screenshots * Record video playback * Unify variable names diff --git a/gs/gs-applyconf.sh b/gs/gs-applyconf.sh new file mode 100755 index 0000000..bcf364a --- /dev/null +++ b/gs/gs-applyconf.sh @@ -0,0 +1,168 @@ +#!/bin/bash + +set -e +set -x + +need_u_boot_update=0 +need_reboot=0 +need_restart_services="" + +## kernel cmdline configuration +[ -f /etc/kernel/cmdline.bak ] || cp /etc/kernel/cmdline /etc/kernel/cmdline.bak +kernel_cmdline_now=$(< /etc/kernel/cmdline) +kernel_cmdline_base=$(< /etc/kernel/cmdline.bak) +kernel_cmdline_config=$kernel_cmdline_base +# append kernel cmdline +[ -n "$append_kernel_cmdline" ] && kernel_cmdline_config="$kernel_cmdline_config $append_kernel_cmdline" +# system wide screen mode +if [ "$system_wide_screen_mode" == "yes" ]; then + [ -n "$screen_mode" ] && kernel_cmdline_config="$kernel_cmdline_config video=HDMI-A-1:${screen_mode}" +fi +# update kernel cmdline +if [ "$kernel_cmdline_config" != "$kernel_cmdline_now" ]; then + echo "$kernel_cmdline_config" > /etc/kernel/cmdline + need_u_boot_update=1 + need_reboot=1 +fi + +## dtbo configuration +# set max resolution to 4k +if [[ "$max_resolution_4k" == "yes" && -f /boot/dtbo/rk3566-hdmi-max-resolution-4k.dtbo.disabled ]]; then + mv /boot/dtbo/rk3566-hdmi-max-resolution-4k.dtbo.disabled /boot/dtbo/rk3566-hdmi-max-resolution-4k.dtbo + need_u_boot_update=1 + need_reboot=1 +elif [[ "$max_resolution_4k" == "no" && -f /boot/dtbo/rk3566-hdmi-max-resolution-4k.dtbo ]]; then + mv /boot/dtbo/rk3566-hdmi-max-resolution-4k.dtbo /boot/dtbo/rk3566-hdmi-max-resolution-4k.dtbo.disabled + need_u_boot_update=1 + need_reboot=1 +fi +# disable integrated wifi of radxa zero 3W +if [[ "$disable_integrated_wifi" == "yes" && -f /boot/dtbo/radxa-zero3-disabled-wireless.dtbo.disabled ]]; then + mv /boot/dtbo/radxa-zero3-disabled-wireless.dtbo.disabled /boot/dtbo/radxa-zero3-disabled-wireless.dtbo + need_u_boot_update=1 + need_reboot=1 +elif [[ "$disable_integrated_wifi" == "no" && -f /boot/dtbo/radxa-zero3-disabled-wireless.dtbo ]]; then + mv /boot/dtbo/radxa-zero3-disabled-wireless.dtbo /boot/dtbo/radxa-zero3-disabled-wireless.dtbo.disabled + need_u_boot_update=1 + need_reboot=1 + +fi +# enable external antenna of radxa zero 3W +if [[ "$enable_external_antenna" == "yes" && -f /boot/dtbo/radxa-zero3-external-antenna.dtbo.disabled && -d /sys/class/net/wlan0 ]]; then + mv /boot/dtbo/radxa-zero3-external-antenna.dtbo.disabled /boot/dtbo/radxa-zero3-external-antenna.dtbo + need_u_boot_update=1 + need_reboot=1 +elif [[ "$enable_external_antenna" == "no" && -f /boot/dtbo/radxa-zero3-external-antenna.dtbo && -d /sys/class/net/wlan0 ]] ; then + mv /boot/dtbo/radxa-zero3-external-antenna.dtbo /boot/dtbo/radxa-zero3-external-antenna.dtbo.disabled + need_u_boot_update=1 + need_reboot=1 +fi +# dtbo enable or disable +dtbo_enable_array=$(echo $dtbo_enable_list | tr -s ' ' | tr ' ' '\n' | sort) +dtbo_enabled_array=$(ls /boot/dtbo/rk3568-*.dtbo 2>/dev/null | sed -e "s^/boot/dtbo/rk3568-^^g" -e "s/.dtbo//g" | sort) +dtbo_need_enable=$(comm -23 <(echo "$dtbo_enable_array") <(echo "$dtbo_enabled_array")) +dtbo_need_disable=$(comm -13 <(echo "$dtbo_enable_array") <(echo "$dtbo_enabled_array")) +# enable dtbo +if [ -n "$dtbo_need_enable" ]; then + for dtboe in $dtbo_need_enable; do + if [ -f /boot/dtbo/rk3568-${dtboe}.dtbo.disabled ]; then + mv /boot/dtbo/rk3568-${dtboe}.dtbo.disabled /boot/dtbo/rk3568-${dtboe}.dtbo + need_u_boot_update=1 + need_reboot=1 + fi + done +fi +# disable dtbo +if [ -n "$dtbo_need_disable" ]; then + for dtbod in $dtbo_need_disable; do + mv /boot/dtbo/rk3568-${dtbod}.dtbo /boot/dtbo/rk3568-${dtbod}.dtbo.disabled + done + need_u_boot_update=1 + need_reboot=1 +fi + +## Update REC_Dir in fstab +[ -d $REC_Dir ] || mkdir -p $REC_Dir +if [ "${REC_Dir}" != "$(grep -oP '(?<=^/dev/mmcblk1p4\t).*?(?=\t)' /etc/fstab)" ]; then + sed -i "s#^\(/dev/mmcblk1p4\t\)[^\t]*#\1${REC_Dir}#" /etc/fstab + need_reboot=1 +fi + +## GPS configuration +if [[ $(grep -q "stty -F /dev/${gps_uart} ${gps_uart_baudrate}" /etc/default/gpsd) && $(grep -q "DEVICES=\"/dev/${gps_uart}\"" /etc/default/gpsd) ]]; then + echo "GPS configuration not changed!" +else + cat > /etc/default/gpsd << EOF +stty -F /dev/${gps_uart} ${gps_uart_baudrate} +START_DAEMON="true" +DEVICES="/dev/${gps_uart}" +GPSD_OPTIONS="-n -b -G -r" +USBAUTO="true" +EOF +fi + +## Network configuration +# br0 configuration +if [[ -f /etc/systemd/network/br0.network && -n "$br0_fixed_ip" && -n "$br0_fixed_ip2" ]]; then + br0_fixed_ip_OS=$(grep -m 1 -oP '(?<=Address=).*' /etc/systemd/network/br0.network) + br0_fixed_ip_OS2=$(tac /etc/systemd/network/br0.network | grep -m 1 -oP '(?<=Address=).*') + [ "${br0_fixed_ip_OS}" == "${br0_fixed_ip}" ] || sed -i "s^${br0_fixed_ip_OS}^${br0_fixed_ip}^" /etc/systemd/network/br0.network + [ "${br0_fixed_ip_OS2}" == "${br0_fixed_ip2}" ] || sed -i "s^${br0_fixed_ip_OS2}^${br0_fixed_ip2}^" /etc/systemd/network/br0.network + need_restart_services="$need_restart_services systemd-networkd" +fi +echo "br0 configure done" + +# wlan0 configuration +if [ -z "$wfb_integrated_wnic" ]; then + # managed wlan0 by NetworkManager + [ -f /etc/network/interfaces.d/wfb-wlan0 ] && rm /etc/network/interfaces.d/wfb-wlan0 + nmcli device | grep -q "^wlan0.*unmanaged.*" && nmcli device set wlan0 managed yes + + # wlan0 station mode configuration + echo "start configure wlan0 station mode" + # If no connection named radxa, create one to automatically connect to the unencrypted WiFi named OpenIPC. + [ -f /etc/NetworkManager/system-connections/wlan0.nmconnection ] || nmcli con add type wifi ifname wlan0 con-name wlan0 ssid OpenIPC + # If the WiFi configuration in gs.conf is not empty and changes, modify the WiFi connection information according to the configuration file + if [[ -f /etc/NetworkManager/system-connections/wlan0.nmconnection && -n $WIFI_SSID && -n $WIFI_Encryption && -n $WIFI_Password ]]; then + WIFI_SSID_OS=$(nmcli -g 802-11-wireless.ssid connection show wlan0) + WIFI_Encryption_OS=$(nmcli -g 802-11-wireless-security.key-mgmt connection show wlan0) + WIFI_Password_OS=$(nmcli -s -g 802-11-wireless-security.psk connection show wlan0) + [[ "$WIFI_SSID_OS" == "$WIFI_SSID" && "$WIFI_Encryption_OS" == "$WIFI_Encryption" && "$WIFI_Password_OS" == "$WIFI_Password" ]] || nmcli con modify wlan0 ssid ${WIFI_SSID} wifi-sec.key-mgmt ${WIFI_Encryption} wifi-sec.psk ${WIFI_Password} + nmcli con down wlan0 && nmcli con up wlan0 + fi + echo "wlan0 station mode configure done" + + # wlan0 hotspot mode configuration + echo "start configure wlan0 hotspot mode" + if [[ -f /etc/NetworkManager/system-connections/hotspot.nmconnection && -n $Hotspot_SSID && -n $Hotspot_Password && -n $Hotspot_ip ]];then + Hotspot_SSID_OS=$(nmcli -g 802-11-wireless.ssid connection show hotspot) + Hotspot_Password_OS=$(nmcli -s -g 802-11-wireless-security.psk connection show hotspot) + Hotspot_ip_OS=$(nmcli -g ipv4.addresses con show hotspot) + [[ "$Hotspot_SSID_OS" == "$Hotspot_SSID" && "$Hotspot_Password_OS" == "$Hotspot_Password" ]] || nmcli connection modify hotspot ssid $Hotspot_SSID wifi-sec.psk $Hotspot_Password + [[ "$Hotspot_ip_OS" == $Hotspot_ip ]] || nmcli connection modify hotspot ipv4.method shared ipv4.addresses $Hotspot_ip + elif [[ -d /sys/class/net/wlan0 && -n $Hotspot_SSID && -n $Hotspot_Password && -n $Hotspot_ip ]]; then + nmcli dev wifi hotspot con-name hotspot ifname wlan0 ssid $Hotspot_SSID password $Hotspot_Password + nmcli connection modify hotspot ipv4.method shared ipv4.addresses $Hotspot_ip autoconnect no + else + echo "no wlan0 or hotspot setting is blank" + fi + [[ -d /sys/class/net/wlan0 && "$WIFI_mode" == "hotspot" ]] && ( sleep 15; nmcli connection up hotspot ) & + echo "wlan0 hotspot mode configure done" +fi + +# radxa0 dnsmasq configuration +if [[ -f /etc/network/interfaces.d/radxa0 && -n "$gadget_net_fixed_ip" ]]; then + # Check whether the configuration in gs.conf is consistent with radxa0. If not, update it. + radxa0_fixed_ip_OS=$(grep -oP "(?<=address\s).*" /etc/network/interfaces.d/radxa0) + [ "$radxa0_fixed_ip_OS" == "${gadget_net_fixed_ip}" ] || sed -i "s^${radxa0_fixed_ip_OS}^${gadget_net_fixed_ip}^" /etc/network/interfaces.d/radxa0 + grep -q "${gadget_net_fixed_ip_addr}" /etc/network/interfaces.d/radxa0 || sed -i "s/--listen-address=.*,12h/--listen-address=${gadget_net_fixed_ip_addr} --dhcp-range=${gadget_net_fixed_ip_sub}.11,${gadget_net_fixed_ip_sub}.20,12h/" /etc/network/interfaces.d/radxa0 +fi +echo "radxa0 usb gadget network configure done" + +# Update REC_Dir in smb.conf +grep -q "$REC_Dir" /etc/samba/smb.conf || ( sed -i "/\[Videos\]/{n;s|.*| ${REC_Dir}|;}" /etc/samba/smb.conf && need_restart_services="$need_restart_services smbd nmbd") + +# some configuration need reboot to take effect +[ "$need_u_boot_update" == "1" ] && u-boot-update +[ "$need_reboot" == "1" ] && reboot +[ -n "$need_restart_services" ] && systemctl restart $need_restart_services diff --git a/gs/gs-init.sh b/gs/gs-init.sh index dc3e738..8a5cb38 100755 --- a/gs/gs-init.sh +++ b/gs/gs-init.sh @@ -45,11 +45,6 @@ fi dtc -I dts -O dtb -o /boot/dtbo/rk3566-hdmi-max-resolution-4k.dtbo.disabled /home/radxa/gs/rk3566-hdmi-max-resolution-4k.dts # enbale USB OTG role switch dtc -I dts -O dtb -o /boot/dtbo/rk3566-dwc3-otg-role-switch.dtbo /home/radxa/gs/rk3566-dwc3-otg-role-switch.dts -dtbo_enable_array=($dtbo_enable_list) -for dtbo in "${dtbo_enable_array[@]}"; do - mv /boot/dtbo/rk3568-${dtbo}.dtbo.disabled /boot/dtbo/rk3568-${dtbo}.dtbo -done -u-boot-update # Add br0 network configuration [ -f /etc/systemd/network/br0.netdev ] || cat > /etc/systemd/network/br0.netdev << EOF @@ -171,6 +166,9 @@ EOF systemctl disable gs-init.service +# check and apply configuration in gs.conf +source /home/radxa/gs/gs-applyconf.sh + while [ -f /config/before.txt ]; do sleep 2; done sync reboot diff --git a/gs/gs.sh b/gs/gs.sh index fa614b1..7b22290 100755 --- a/gs/gs.sh +++ b/gs/gs.sh @@ -5,97 +5,11 @@ set -x # load config source /config/gs.conf -need_u_boot_update=0 -need_reboot=0 -# kernel cmdline configuration -[ -f /etc/kernel/cmdline.bak ] || cp /etc/kernel/cmdline /etc/kernel/cmdline.bak -kernel_cmdline_now=$(< /etc/kernel/cmdline) -kernel_cmdline_base=$(< /etc/kernel/cmdline.bak) -kernel_cmdline_config=$kernel_cmdline_base +# check and apply configuration in gs.conf +source /home/radxa/gs/gs-applyconf.sh -# append kernel cmdline -[ -n "$append_kernel_cmdline" ] && kernel_cmdline_config="$kernel_cmdline_config $append_kernel_cmdline" - -# system wide screen mode -if [ "$system_wide_screen_mode" == "yes" ]; then - [ -n "$screen_mode" ] && kernel_cmdline_config="$kernel_cmdline_config video=HDMI-A-1:${screen_mode}" -fi - -if [ "$kernel_cmdline_config" != "$kernel_cmdline_now" ]; then - echo "$kernel_cmdline_config" > /etc/kernel/cmdline - need_u_boot_update=1 - need_reboot=1 -fi - -## dtbo configuration -# set max resolution to 4k -if [[ "$max_resolution_4k" == "yes" && -f /boot/dtbo/rk3566-hdmi-max-resolution-4k.dtbo.disabled ]]; then - mv /boot/dtbo/rk3566-hdmi-max-resolution-4k.dtbo.disabled /boot/dtbo/rk3566-hdmi-max-resolution-4k.dtbo - need_u_boot_update=1 - need_reboot=1 -elif [[ "$max_resolution_4k" == "no" && -f /boot/dtbo/rk3566-hdmi-max-resolution-4k.dtbo ]]; then - mv /boot/dtbo/rk3566-hdmi-max-resolution-4k.dtbo /boot/dtbo//boot/dtbo/rk3566-hdmi-max-resolution-4k.dtbo.disabled - need_u_boot_update=1 - need_reboot=1 -fi -# disable integrated wifi of radxa zero 3W -if [[ "$disable_integrated_wifi" == "yes" && -f /boot/dtbo/radxa-zero3-disabled-wireless.dtbo.disabled ]]; then - mv /boot/dtbo/radxa-zero3-disabled-wireless.dtbo.disabled /boot/dtbo/radxa-zero3-disabled-wireless.dtbo - need_u_boot_update=1 - need_reboot=1 -elif [[ "$disable_integrated_wifi" == "no" && -f /boot/dtbo/radxa-zero3-disabled-wireless.dtbo ]]; then - mv /boot/dtbo/radxa-zero3-disabled-wireless.dtbo /boot/dtbo/radxa-zero3-disabled-wireless.dtbo.disabled - need_u_boot_update=1 - need_reboot=1 - -fi -# enable external antenna of radxa zero 3W -if [[ "$enable_external_antenna" == "yes" && -f /boot/dtbo/radxa-zero3-external-antenna.dtbo.disabled && -d /sys/class/net/wlan0 ]]; then - mv /boot/dtbo/radxa-zero3-external-antenna.dtbo.disabled /boot/dtbo/radxa-zero3-external-antenna.dtbo - need_u_boot_update=1 - need_reboot=1 -elif [[ "$enable_external_antenna" == "no" && -f /boot/dtbo/radxa-zero3-external-antenna.dtbo && -d /sys/class/net/wlan0 ]] ; then - mv /boot/dtbo/radxa-zero3-external-antenna.dtbo /boot/dtbo/radxa-zero3-external-antenna.dtbo.disabled - need_u_boot_update=1 - need_reboot=1 -fi -# check if need enable or disable dtbo -dtbo_enable_array=$(echo $dtbo_enable_list | tr -s ' ' | tr ' ' '\n' | sort) -dtbo_enabled_array=$(ls /boot/dtbo/rk3568-*.dtbo 2>/dev/null | sed -e "s^/boot/dtbo/rk3568-^^g" -e "s/.dtbo//g" | sort) -dtbo_need_enable=$(comm -23 <(echo "$dtbo_enable_array") <(echo "$dtbo_enabled_array")) -dtbo_need_disable=$(comm -13 <(echo "$dtbo_enable_array") <(echo "$dtbo_enabled_array")) -# enable dtbo -if [ -n "$dtbo_need_enable" ]; then - for dtboe in $dtbo_need_enable; do - if [ -f /boot/dtbo/rk3568-${dtboe}.dtbo.disabled ]; then - mv /boot/dtbo/rk3568-${dtboe}.dtbo.disabled /boot/dtbo/rk3568-${dtboe}.dtbo - need_u_boot_update=1 - need_reboot=1 - fi - done -fi -# disable dtbo -if [ -n "$dtbo_need_disable" ]; then - for dtbod in $dtbo_need_disable; do - mv /boot/dtbo/rk3568-${dtbod}.dtbo /boot/dtbo/rk3568-${dtbod}.dtbo.disabled - done - need_u_boot_update=1 - need_reboot=1 -fi - -# Update REC_Dir in fstab -[ -d $REC_Dir ] || mkdir -p $REC_Dir -if [ "${REC_Dir}" != "$(grep -oP '(?<=^/dev/mmcblk1p4\t).*?(?=\t)' /etc/fstab)" ]; then - sed -i "s#^\(/dev/mmcblk1p4\t\)[^\t]*#\1${REC_Dir}#" /etc/fstab - need_reboot=1 -fi - -# some configuration need reboot to take effect -[ "$need_u_boot_update" == "1" ] && u-boot-update -[ "$need_reboot" == "1" ] && reboot - -# RTC configuration +# RTC if [ "$use_external_rtc" == "yes" ]; then if [ -c /dev/i2c-4 ]; then modprobe i2c-dev @@ -104,90 +18,23 @@ if [ "$use_external_rtc" == "yes" ]; then else echo "i2c-4 is not enabled" fi - -fi - -# GPS configuration -if [ "$use_gps" == "yes" ]; then - if [[ $(grep -q "stty -F /dev/${gps_uart} ${gps_uart_baudrate}" /etc/default/gpsd) && $(grep -q "DEVICES=\"/dev/${gps_uart}\"" /etc/default/gpsd) ]]; then - systemctl start chrony gpsd - else - cat > /etc/default/gpsd << EOF -stty -F /dev/${gps_uart} ${gps_uart_baudrate} -START_DAEMON="true" -DEVICES="/dev/${gps_uart}" -GPSD_OPTIONS="-n -b -G -r" -USBAUTO="true" -EOF - systemctl start chrony gpsd - fi -fi - -# Update br0 configuration -if [[ -f /etc/systemd/network/br0.network && -n "$br0_fixed_ip" && -n "$br0_fixed_ip2" ]]; then - br0_fixed_ip_OS=$(grep -m 1 -oP '(?<=Address=).*' /etc/systemd/network/br0.network) - br0_fixed_ip_OS2=$(tac /etc/systemd/network/br0.network | grep -m 1 -oP '(?<=Address=).*') - [ "${br0_fixed_ip_OS}" == "${br0_fixed_ip}" ] || sed -i "s^${br0_fixed_ip_OS}^${br0_fixed_ip}^" /etc/systemd/network/br0.network - [ "${br0_fixed_ip_OS2}" == "${br0_fixed_ip2}" ] || sed -i "s^${br0_fixed_ip_OS2}^${br0_fixed_ip2}^" /etc/systemd/network/br0.network - systemctl restart systemd-networkd fi -echo "br0 configure done" -# wlan0 configuration -if [ -z "$wfb_integrated_wnic" ]; then - # managed wlan0 by NetworkManager - [ -f /etc/network/interfaces.d/wfb-wlan0 ] && rm /etc/network/interfaces.d/wfb-wlan0 - nmcli device | grep -q "^wlan0.*unmanaged.*" && nmcli device set wlan0 managed yes +# GPS +[ "$use_gps" == "yes" ] && systemctl start chrony gpsd & - # wlan0 station mode configuration - echo "start configure wlan0 station mode" - # If no connection named radxa, create one to automatically connect to the unencrypted WiFi named OpenIPC. - [ -f /etc/NetworkManager/system-connections/wlan0.nmconnection ] || nmcli con add type wifi ifname wlan0 con-name wlan0 ssid OpenIPC - # If the WiFi configuration in gs.conf is not empty and changes, modify the WiFi connection information according to the configuration file - if [[ -f /etc/NetworkManager/system-connections/wlan0.nmconnection && -n $WIFI_SSID && -n $WIFI_Encryption && -n $WIFI_Password ]]; then - WIFI_SSID_OS=$(nmcli -g 802-11-wireless.ssid connection show wlan0) - WIFI_Encryption_OS=$(nmcli -g 802-11-wireless-security.key-mgmt connection show wlan0) - WIFI_Password_OS=$(nmcli -s -g 802-11-wireless-security.psk connection show wlan0) - [[ "$WIFI_SSID_OS" == "$WIFI_SSID" && "$WIFI_Encryption_OS" == "$WIFI_Encryption" && "$WIFI_Password_OS" == "$WIFI_Password" ]] || nmcli con modify wlan0 ssid ${WIFI_SSID} wifi-sec.key-mgmt ${WIFI_Encryption} wifi-sec.psk ${WIFI_Password} +# WiFi +if [ -d /sys/class/net/wlan0 ]; then + if [ "$WIFI_mode" == "hotspot" ]; then + ( sleep 15; nmcli connection up hotspot ) & + elif [ "$WIFI_mode" == "station" ]; then + ( sleep 5; nmcli connection up wlan0 ) & fi - echo "wlan0 station mode configure done" - - # wlan0 hotspot mode configuration - echo "start configure wlan0 hotspot mode" - if [[ -f /etc/NetworkManager/system-connections/hotspot.nmconnection && -n $Hotspot_SSID && -n $Hotspot_Password && -n $Hotspot_ip ]];then - Hotspot_SSID_OS=$(nmcli -g 802-11-wireless.ssid connection show hotspot) - Hotspot_Password_OS=$(nmcli -s -g 802-11-wireless-security.psk connection show hotspot) - Hotspot_ip_OS=$(nmcli -g ipv4.addresses con show hotspot) - [[ "$Hotspot_SSID_OS" == "$Hotspot_SSID" && "$Hotspot_Password_OS" == "$Hotspot_Password" ]] || nmcli connection modify hotspot ssid $Hotspot_SSID wifi-sec.psk $Hotspot_Password - [[ "$Hotspot_ip_OS" == $Hotspot_ip ]] || nmcli connection modify hotspot ipv4.method shared ipv4.addresses $Hotspot_ip - elif [[ -d /sys/class/net/wlan0 && -n $Hotspot_SSID && -n $Hotspot_Password && -n $Hotspot_ip ]]; then - nmcli dev wifi hotspot con-name hotspot ifname wlan0 ssid $Hotspot_SSID password $Hotspot_Password - nmcli connection modify hotspot ipv4.method shared ipv4.addresses $Hotspot_ip autoconnect no - else - echo "no wlan0 or hotspot setting is blank" - fi - [[ -d /sys/class/net/wlan0 && "$WIFI_mode" == "hotspot" ]] && ( sleep 15; nmcli connection up hotspot ) & - echo "wlan0 hotspot mode configure done" -fi - -# Update radxa0 dnsmasq configuration -if [[ -f /etc/network/interfaces.d/radxa0 && -n "$gadget_net_fixed_ip" ]]; then - # Check whether the configuration in gs.conf is consistent with radxa0. If not, update it. - radxa0_fixed_ip_OS=$(grep -oP "(?<=address\s).*" /etc/network/interfaces.d/radxa0) - [ "$radxa0_fixed_ip_OS" == "${gadget_net_fixed_ip}" ] || sed -i "s^${radxa0_fixed_ip_OS}^${gadget_net_fixed_ip}^" /etc/network/interfaces.d/radxa0 - grep -q "${gadget_net_fixed_ip_addr}" /etc/network/interfaces.d/radxa0 || sed -i "s/--listen-address=.*,12h/--listen-address=${gadget_net_fixed_ip_addr} --dhcp-range=${gadget_net_fixed_ip_sub}.11,${gadget_net_fixed_ip_sub}.20,12h/" /etc/network/interfaces.d/radxa0 fi -echo "radxa0 usb gadget network configure done" - -# Update REC_Dir in smb.conf -grep -q "$REC_Dir" /etc/samba/smb.conf || ( sed -i "/\[Videos\]/{n;s|.*| ${REC_Dir}|;}" /etc/samba/smb.conf && systemctl restart smbd nmbd ) - -# [ TODO ] Check and Update /etc/wifibroadcast.conf # pwm fan service [ "$fan_service_enable" == "yes" ] && ( echo "start fan service"; systemd-run --unit=fan /home/radxa/gs/fan.sh ) - # add route to 224.0.0.1 ip ro add 224.0.0.0/4 dev br0 # Start wfb diff --git a/gs/install.sh b/gs/install.sh index 0ef1efe..721e8da 100755 --- a/gs/install.sh +++ b/gs/install.sh @@ -1,6 +1,7 @@ #!/bin/bash set -ex +echo -e "\033[31mStart install gs\033[0m" install_dir='/home/radxa/gs' script_dir=$(dirname $(readlink -f $0)) @@ -13,34 +14,22 @@ fi [ -d ${install_dir}/udev-rules-bak ] || mkdir -p ${install_dir}/udev-rules-bak -echo -e "\033[31mRemove /etc/NetworkManager/system-connections/*\033[0m" [ "$(ls -A /etc/NetworkManager/system-connections/)" ] && rm /etc/NetworkManager/system-connections/* -echo -e "\033[31mDisable wifibroadcast.service wifibroadcast@gs.service\033[0m" systemctl disable wifibroadcast.service wifibroadcast@gs.service chmod +x gs.sh wfb.sh stream.sh fan.sh button.sh gs-init.sh channel-scan.sh -cp gs.sh wfb.sh stream.sh fan.sh button.sh gs-init.sh channel-scan.sh rk3566-dwc3-otg-role-switch.dts rk3566-hdmi-max-resolution-4k.dts ${install_dir}/ +cp gs.sh wfb.sh stream.sh fan.sh button.sh gs-applyconf.sh gs-init.sh channel-scan.sh rk3566-dwc3-otg-role-switch.dts rk3566-hdmi-max-resolution-4k.dts ${install_dir}/ cp gs.conf custom-sample.conf pixelpilot_osd.json pixelpilot_osd_simple.json /config/ -echo -e "\033[31mcopy gs.service gs-init.service to /etc/systemd/system/\033[0m" cp gs.service gs-init.service /etc/systemd/system/ -echo -e "\033[31mBackup exist udev rules to ${install_dir}/udev-rules-bak/\033[0m" [ -f /etc/udev/rules.d/98-custom-wifi.rules ] && mv /etc/udev/rules.d/98-custom-wifi.rules ${install_dir}/udev-rules-bak/ [ -f /etc/udev/rules.d/99-custom-wifi.rules ] && mv /etc/udev/rules.d/99-custom-wifi.rules ${install_dir}/udev-rules-bak/ -echo -e "\033[31mcopy 99-wfb.rules 98-gadget.rules to /etc/udev/rules.d/\033[0m" cp 99-wfb.rules 98-gadget.rules /etc/udev/rules.d/ -echo "cpoy ../pics/OpenIPC.png ${install_dir}/wallpaper.png" cp ../pics/OpenIPC.png ${install_dir}/wallpaper.png -echo -e "\033[31msystemctl enable gs-init.service \033[0m" systemctl enable gs-init.service systemctl enable gs.service -echo -e "\033[31mCopy FPVue.key to /config/gs.key and linked to /etc/gs.key\033[0m" cp FPVue.key /config/gs.key [ $(readlink -f /etc/gs.key) == "/config/gs.key" ] || ( [ -f /etc/gs.key ] && rm /etc/gs.key; ln -s /config/gs.key /etc/gs.key ) -echo -e "\033[31mLinked /config/gs.conf to /etc/gs.conf\033[0m" [ $(readlink -f /etc/gs.conf) == "/config/gs.conf" ] || ( [ -f /etc/gs.conf ] && rm /etc/gs.conf; ln -s /config/gs.conf /etc/gs.conf ) echo -e "\033[31mInstallation Complete, Configuration file is /config/gs.conf\033[0m" sync echo -e "\033[31mRestart required to take effect!\033[0m" - - -