#!/bin/bash { #//////////////////////////////////// # DietPi-Config Script # #//////////////////////////////////// # Created by Daniel Knight / daniel.knight@dietpi.com / dietpi.com # #//////////////////////////////////// # # Info: # - filename /DietPi/dietpi/dietpi-config # # Usage: # dietpi-config iMENUINDEX iEXITONBACK # - iMENUINDEX - Launch TARGETMENUID # - iEXITONBACK - 1=Exit DietPi-Config when going back to previous menu (applied to TARGETMENUINDEX 8 only!!) #//////////////////////////////////// # Import DietPi-Globals -------------------------------------------------------------- . /DietPi/dietpi/func/dietpi-globals G_PROGRAM_NAME='DietPi-Config' G_CHECK_ROOT_USER G_CHECK_ROOTFS_RW G_INIT # Import DietPi-Globals -------------------------------------------------------------- # Grab Inputs # - target MENU INDEX (valid interger) disable_error=1 G_CHECK_VALIDINT "$1" && TARGETMENUID=$1 # - Exit DietPi-Config when going back to previous menu? if disable_error=1 G_CHECK_VALIDINT "$2"; then EXITONBACK=$2 TEXT_MENU_BACK='Exit' fi #///////////////////////////////////////////////////////////////////////////////////// # Obtain Hardware Details #///////////////////////////////////////////////////////////////////////////////////// HW_ONBOARD_WIFI=$(sed -n 10p /DietPi/dietpi/.hw_model) FP_CPU_SCALING_GOV='/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors' #///////////////////////////////////////////////////////////////////////////////////// # Obtain Installed software #///////////////////////////////////////////////////////////////////////////////////// Load_Installed_Software(){ [[ -f '/DietPi/dietpi/.installed' ]] && . /DietPi/dietpi/.installed; } #///////////////////////////////////////////////////////////////////////////////////// # Whiltail Info #///////////////////////////////////////////////////////////////////////////////////// Info_HW_OptionNotSupported(){ G_WHIP_MSG "This option is not available for $G_HW_MODEL_DESCRIPTION"; } #///////////////////////////////////////////////////////////////////////////////////// # MENUS #///////////////////////////////////////////////////////////////////////////////////// TARGETMENUID=${TARGETMENUID:-0} EXITONBACK=${EXITONBACK:-0} TEXT_MENU_BACK=${TEXT_MENU_BACK:-Back} WHIP_SELECTION_PREVIOUS='' REBOOT_REQUIRED=0 # Interger min/max value holders MIN_VALUE=0 MAX_VALUE=0 # TARGETMENUID=0 Menu_Main(){ G_WHIP_MENU_ARRAY=('1' ': Display Options') # Hide Audio and Performance Options on VM (( $G_HW_MODEL == 20 )) || G_WHIP_MENU_ARRAY+=( '2' ': Audio Options' '3' ': Performance Options' ) G_WHIP_MENU_ARRAY+=( '4' ': Advanced Options' '5' ': Language/Regional Options' '6' ': Security Options' '7' ': Network Options: Adapters' '8' ': Network Options: Misc' '9' ': AutoStart Options' '10' ': Tools' ) if G_WHIP_MENU "Hardware : $G_HW_MODEL_DESCRIPTION"; then if (( $G_WHIP_RETURNED_VALUE == 1 )); then TARGETMENUID=1 elif (( $G_WHIP_RETURNED_VALUE == 2 )); then TARGETMENUID=14 elif (( $G_WHIP_RETURNED_VALUE == 3 )); then TARGETMENUID=4 elif (( $G_WHIP_RETURNED_VALUE == 4 )); then TARGETMENUID=3 elif (( $G_WHIP_RETURNED_VALUE == 5 )); then TARGETMENUID=7 elif (( $G_WHIP_RETURNED_VALUE == 6 )); then TARGETMENUID=5 elif (( $G_WHIP_RETURNED_VALUE == 7 )); then TARGETMENUID=8 elif (( $G_WHIP_RETURNED_VALUE == 8 )); then TARGETMENUID=16 elif (( $G_WHIP_RETURNED_VALUE == 9 )); then /DietPi/dietpi/dietpi-autostart REBOOT_REQUIRED=1 elif (( $G_WHIP_RETURNED_VALUE == 10 )); then TARGETMENUID=11 else Menu_Exit fi else Menu_Exit fi } Menu_Exit(){ # TARGETMENUID=-1, if we are to exit DietPi-Config G_WHIP_SIZE_X_MAX=50 if G_WHIP_YESNO "Exit $G_PROGRAM_NAME?"; then TARGETMENUID=-1 # Disable reboot when run from dietpi-software pgrep 'dietpi-software' &> /dev/null && REBOOT_REQUIRED=0 # Reboot required (( $REBOOT_REQUIRED )) && G_WHIP_YESNO 'A reboot is required to apply your new settings.\nWould you like to reboot now?' && reboot # Return to DietPi-Config main menu elif (( $EXITONBACK == 0 )); then TARGETMENUID=0 fi } Display_Rotation_Calc_XY_Invert(){ local input=$1 if (( $G_HW_MODEL < 10 )); then local framebuffer_x=$(grep -m1 '^[[:blank:]]*framebuffer_width=' /DietPi/config.txt || vcgencmd get_config framebuffer_width) framebuffer_x=${framebuffer_x#*=}; framebuffer_x=${framebuffer_x:-0} local framebuffer_y=$(grep -m1 '^[[:blank:]]*framebuffer_height=' /DietPi/config.txt || vcgencmd get_config framebuffer_height) framebuffer_y=${framebuffer_y#*=}; framebuffer_y=${framebuffer_y:-0} # 0/180 landscape if (( $input == 0 && $framebuffer_x < $framebuffer_y )); then G_CONFIG_INJECT 'framebuffer_width=' "framebuffer_width=$framebuffer_y" /DietPi/config.txt G_CONFIG_INJECT 'framebuffer_height=' "framebuffer_height=$framebuffer_x" /DietPi/config.txt # 90/270 portrait | flip XY FB values elif (( $input == 1 && $framebuffer_x > $framebuffer_y )); then G_CONFIG_INJECT 'framebuffer_width=' "framebuffer_width=$framebuffer_y" /DietPi/config.txt G_CONFIG_INJECT 'framebuffer_height=' "framebuffer_height=$framebuffer_x" /DietPi/config.txt fi else Info_HW_OptionNotSupported fi } # TARGETMENUID=1 Menu_DisplayOptions(){ TARGETMENUID=0 G_WHIP_MENU_ARRAY=() if (( $G_HW_MODEL == 21 )); then G_WHIP_MENU_ARRAY+=('1' ': Display Driver') else G_WHIP_MENU_ARRAY+=('1' ': Display Resolution') # On VM, only offer resolution option if (( $G_HW_MODEL != 20 )); then G_WHIP_MENU_ARRAY+=('2' ': GPU/RAM Memory Split') local lcdpanel_text=$(grep -m1 '^[[:blank:]]*CONFIG_LCDPANEL=' /DietPi/dietpi.txt | sed 's/^[^=]*=//') G_WHIP_MENU_ARRAY+=('3' ": LCD Panel addon: [${lcdpanel_text:-NONE}]") fi fi # Display brightness G_WHIP_MENU_ARRAY+=('16' ': Display Brightness') local xorg_dpi_current=$(grep -m1 '^[[:blank:]]*SOFTWARE_XORG_DPI=' /DietPi/dietpi.txt | sed 's/^[^=]*=//') G_WHIP_MENU_ARRAY+=('17' ": X.Org DPI: [${xorg_dpi_current:-N/A}]") (( $G_HW_MODEL != 20 )) && G_WHIP_MENU_ARRAY+=('14' ': LED Control') # RPi only if (( $G_HW_MODEL < 10 )); then # HDMI rotation local rotation_hdmi_current=$(grep -m1 '^[[:blank:]]*display_hdmi_rotate=' /DietPi/config.txt | sed 's/^[^=]*=//') G_WHIP_MENU_ARRAY+=('4' ": Rotation (HDMI) : [${rotation_hdmi_current:=0}]") # LCD rotation local rotation_lcd_current=$(grep -m1 '^[[:blank:]]*lcd_rotate=' /DietPi/config.txt | sed 's/^[^=]*=//') G_WHIP_MENU_ARRAY+=('5' ": Rotation (LCD) : [${rotation_lcd_current:=0}]") # Display overscan local overscan_disabled=$(grep -ci -m1 '^[[:blank:]]*disable_overscan=1' /DietPi/config.txt) local overscan_text='[On]' (( $overscan_disabled )) && overscan_text='[Off]' G_WHIP_MENU_ARRAY+=('6' ": Overscan : $overscan_text") # - Overscan sizes if (( ! $overscan_disabled )); then local overscan_options=( 'overscan_left' 'overscan_right' 'overscan_top' 'overscan_bottom' ) local overscan_left=$(grep -m1 '^[[:blank:]]*overscan_left=' /DietPi/config.txt || vcgencmd get_config overscan_left); overscan_left=${overscan_left#*=} local overscan_right=$(grep -m1 '^[[:blank:]]*overscan_right=' /DietPi/config.txt || vcgencmd get_config overscan_right); overscan_right=${overscan_right#*=} local overscan_top=$(grep -m1 '^[[:blank:]]*overscan_top=' /DietPi/config.txt || vcgencmd get_config overscan_top); overscan_top=${overscan_top#*=} local overscan_bottom=$(grep -m1 '^[[:blank:]]*overscan_bottom=' /DietPi/config.txt || vcgencmd get_config overscan_bottom); overscan_bottom=${overscan_bottom#*=} G_WHIP_MENU_ARRAY+=('15' ": Overscan Compensation [L:${overscan_left:=N/A}] [R:${overscan_right:=N/A}] [T:${overscan_top:=N/A}] [B:${overscan_bottom:=N/A}]") fi # HDMI signal boost local hdmi_boost_current=$({ grep -m1 '^[[:blank:]]*config_hdmi_boost=' /DietPi/config.txt || vcgencmd get_config config_hdmi_boost; } | sed 's/^[^=]*=//') G_WHIP_MENU_ARRAY+=('7' ": HDMI Boost : [${hdmi_boost_current:=N/A}]") # RPi camera module local rpi_camera_module_enabled=$(grep -ci -m1 '^[[:blank:]]*start_x=1' /DietPi/config.txt) local rpi_camera_module_text='[Off]' (( $rpi_camera_module_enabled )) && rpi_camera_module_text='[On]' G_WHIP_MENU_ARRAY+=('8' ": RPi Camera : $rpi_camera_module_text") # RPi camera LED local rpi_camera_led_disabled=$(grep -ci -m1 '^[[:blank:]]*disable_camera_led=1' /DietPi/config.txt) local rpi_camera_led_text='[On]' (( $rpi_camera_led_disabled )) && rpi_camera_led_text='[Off]' G_WHIP_MENU_ARRAY+=('9' ": RPI Camera led : $rpi_camera_led_text") # JustBoom IR Remote local justboom_ir_remote_text='[Off]' local justboom_ir_remote_enabled=0 if [[ -f /etc/systemd/system/justboom-ir-mpd.service ]]; then justboom_ir_remote_text='[On]' justboom_ir_remote_enabled=1 fi G_WHIP_MENU_ARRAY+=('11' ": JustBoom IR remote : $justboom_ir_remote_text") # VC1 key local vc1_key_current=$(grep -m1 '^[[:blank:]]*decode_WVC1=' /DietPi/config.txt | sed 's/^[^=]*=//') G_WHIP_MENU_ARRAY+=('12' ": VC1 Key : [${vc1_key_current:=none}]") # MPEG2 key local mpeg2_key_current=$(grep -m1 '^[[:blank:]]*decode_MPG2=' /DietPi/config.txt | sed 's/^[^=]*=//') G_WHIP_MENU_ARRAY+=('13' ": MPEG2 Key : [${mpeg2_key_current:=none}]") fi # Odroid Remote if (( $G_HW_MODEL > 9 && $G_HW_MODEL < 13 )); then local odroid_remote_text='[Off]' local odroid_remote_enabled=0 if [[ -f /etc/systemd/system/odroid-remote.service ]]; then odroid_remote_text='[On]' odroid_remote_enabled=1 fi G_WHIP_MENU_ARRAY+=('10' ": Odroid remote : $odroid_remote_text") fi G_WHIP_DEFAULT_ITEM=$WHIP_SELECTION_PREVIOUS if G_WHIP_MENU 'Please select an option:'; then TARGETMENUID=1 # Return to this menu WHIP_SELECTION_PREVIOUS=$G_WHIP_RETURNED_VALUE if (( $G_WHIP_RETURNED_VALUE == 15 )); then for i in "${overscan_options[@]}" do G_WHIP_DEFAULT_ITEM=${!i} if G_WHIP_INPUTBOX "Please enter a value (pixel count) for $i\n - EG: 16"; then G_CONFIG_INJECT "$i=" "$i=$G_WHIP_RETURNED_VALUE" /DietPi/config.txt REBOOT_REQUIRED=1 else break fi done elif (( $G_WHIP_RETURNED_VALUE == 1 )); then TARGETMENUID=2 elif (( $G_WHIP_RETURNED_VALUE == 3 )); then # RPi and Odroids only if (( $G_HW_MODEL < 20 )); then G_WHIP_MENU_ARRAY=('none' ': Uninstall all panels') G_WHIP_MENU_ARRAY+=('waveshare32' ': 320x240 panel with touch input') if (( $G_HW_MODEL < 10 )); then G_WHIP_MENU_ARRAY+=('esp01215e' ': Elecrow 1024x600 7" IPS HDMI panel with touch input') else G_WHIP_MENU_ARRAY+=('odroid-lcd35' ': 480x320 panel with touch input') (( $G_HW_MODEL == 11 )) && G_WHIP_MENU_ARRAY+=('odroid-cloudshell' ': 320x240 panel') fi G_WHIP_DEFAULT_ITEM=$lcdpanel_text if G_WHIP_MENU 'Please select an option:'; then /DietPi/dietpi/func/dietpi-set_hardware lcdpanel "$G_WHIP_RETURNED_VALUE" REBOOT_REQUIRED=1 fi else Info_HW_OptionNotSupported fi elif (( $G_WHIP_RETURNED_VALUE == 2 )); then if (( $G_HW_MODEL < 10 || $G_HW_MODEL == 12 || ( $G_HW_MODEL == 10 && $G_DISTRO == 3 ) )); then #REMOVE v6.24 G_WHIP_MSG 'GPU/RAM Memory splits are pre-configured and applied during DietPi-Software setup.\n\nThe split value is optimized based on your software installs, however, feel free to tweak them.' TARGETMENUID=6 else Info_HW_OptionNotSupported fi elif (( $G_WHIP_RETURNED_VALUE == 6 )); then # RPi only if (( $G_HW_MODEL < 10 )); then if (( $overscan_disabled )); then G_CONFIG_INJECT 'disable_overscan=' 'disable_overscan=0' /DietPi/config.txt else G_CONFIG_INJECT 'disable_overscan=' 'disable_overscan=1' /DietPi/config.txt for i in "${overscan_options[@]}" do G_CONFIG_INJECT "$i=" "#$i=0" /DietPi/config.txt done fi REBOOT_REQUIRED=1 else Info_HW_OptionNotSupported fi elif (( $G_WHIP_RETURNED_VALUE == 7 )); then # RPi only if (( $G_HW_MODEL < 10 )); then G_WHIP_MENU_ARRAY=( '0' ': Disabled' '2' ': RPi 1 Default' '5' ': RPi 2+ Default' '6' '' '7' ': High (May increase stability)' '8' '' '9' '' '10' '' '11' ': Max (Not recommended)' ) G_WHIP_DEFAULT_ITEM=$hdmi_boost_current G_WHIP_MENU 'Please select a HDMI boost level.\n\nA long (or insufficiently manufactured) cable may required a higher boost setting to achieve correct signal.' if (( $? == 0 )); then G_CONFIG_INJECT 'config_hdmi_boost=' "config_hdmi_boost=$G_WHIP_RETURNED_VALUE" /DietPi/config.txt REBOOT_REQUIRED=1 fi else Info_HW_OptionNotSupported fi elif (( $G_WHIP_RETURNED_VALUE == 8 )); then # RPi only if (( $G_HW_MODEL < 10 )); then if (( $rpi_camera_module_enabled )); then /DietPi/dietpi/func/dietpi-set_hardware rpi-camera disable else /DietPi/dietpi/func/dietpi-set_hardware rpi-camera enable fi REBOOT_REQUIRED=1 else Info_HW_OptionNotSupported fi elif (( $G_WHIP_RETURNED_VALUE == 9 )); then # RPi only if (( $G_HW_MODEL < 10 )); then if (( $rpi_camera_led_disabled )); then G_CONFIG_INJECT 'disable_camera_led=' 'disable_camera_led=0' /DietPi/config.txt else G_CONFIG_INJECT 'disable_camera_led=' 'disable_camera_led=1' /DietPi/config.txt fi REBOOT_REQUIRED=1 else Info_HW_OptionNotSupported fi elif (( $G_WHIP_RETURNED_VALUE == 10 )); then if (( $odroid_remote_enabled )); then /DietPi/dietpi/func/dietpi-set_hardware remoteir none else if G_WHIP_YESNO "This will enable the IR modules, setup Lirc and the Odroid Remote for Odroid C1, C2 and XU4 Cloudshell. \nNB: Other remotes can be configured by running 'irrecord' and applying the codes to '/etc/lirc/lircd.conf'\n\nDo you wish to continue?"; then /DietPi/dietpi/func/dietpi-set_hardware remoteir odroid_remote fi fi REBOOT_REQUIRED=1 elif (( $G_WHIP_RETURNED_VALUE == 11 )); then if (( $justboom_ir_remote_enabled )); then /DietPi/dietpi/func/dietpi-set_hardware remoteir none else if G_WHIP_YESNO 'Got a JustBoom IR Remote? Excellent! \nDietPi will enable the IR modules, setup Lirc and enable support for MPD controls by default:\n\nDo you wish to continue?'; then /DietPi/dietpi/func/dietpi-set_hardware remoteir justboom_ir_remote fi fi REBOOT_REQUIRED=1 elif (( $G_WHIP_RETURNED_VALUE == 12 )); then G_WHIP_DEFAULT_ITEM=$vc1_key_current if G_WHIP_INPUTBOX 'Please enter your key for VC1:\n - EG: 0x00000000'; then G_CONFIG_INJECT 'decode_WVC1=' "decode_WVC1=$G_WHIP_RETURNED_VALUE" /DietPi/config.txt # https://github.com/MichaIng/DietPi/issues/1487 local current_gpu_mem=$(grep -m1 '^[[:blank:]]*gpu_mem_1024' /DietPi/config.txt | sed 's/^[^=]*=//g') (( $current_gpu_mem < 128 )) && /DietPi/dietpi/func/dietpi-set_hardware gpumemsplit 128 REBOOT_REQUIRED=1 fi elif (( $G_WHIP_RETURNED_VALUE == 13 )); then G_WHIP_DEFAULT_ITEM=$mpeg2_key_current if G_WHIP_INPUTBOX 'Please enter your key for MPEG2:\n - EG: 0x00000000'; then G_CONFIG_INJECT 'decode_MPG2=' "decode_MPG2=$G_WHIP_RETURNED_VALUE" /DietPi/config.txt # https://github.com/MichaIng/DietPi/issues/1487 local current_gpu_mem=$(grep -m1 '^[[:blank:]]*gpu_mem_1024' /DietPi/config.txt | sed 's/^[^=]*=//g') (( $current_gpu_mem < 128 )) && /DietPi/dietpi/func/dietpi-set_hardware gpumemsplit 128 REBOOT_REQUIRED=1 fi elif (( $G_WHIP_RETURNED_VALUE == 4 )); then G_WHIP_MENU_ARRAY=( '0' ': Disabled (default)' '1' ': 90 degrees' '2' ': 180 degrees' '3' ': 270 degrees' '0x10000' ': Horizontal flip' '0x20000' ': Vertical flip' ) G_WHIP_DEFAULT_ITEM=$rotation_hdmi_current if G_WHIP_MENU "Please select an option: \nNB: If you have the RPi touchscreen, please set this to 0 and use LCD rotation option."; then G_CONFIG_INJECT 'display_hdmi_rotate=' "display_hdmi_rotate=$G_WHIP_RETURNED_VALUE" /DietPi/config.txt # rotation 90/270 | invert x/y on FB (Y > X) if [[ $G_WHIP_RETURNED_VALUE == '1' || $G_WHIP_RETURNED_VALUE == '3' ]]; then Display_Rotation_Calc_XY_Invert 1 # X > Y else Display_Rotation_Calc_XY_Invert 0 fi REBOOT_REQUIRED=1 fi elif (( $G_WHIP_RETURNED_VALUE == 5 )); then G_WHIP_MENU_ARRAY=( '0' ': Disabled (default)' '2' ': 180 degrees' ) G_WHIP_DEFAULT_ITEM=$rotation_lcd_current if G_WHIP_MENU 'Please select an option:\n\nNB: This option is for RPi touchscreen.'; then G_CONFIG_INJECT 'lcd_rotate=' "lcd_rotate=$G_WHIP_RETURNED_VALUE" /DietPi/config.txt REBOOT_REQUIRED=1 fi elif (( $G_WHIP_RETURNED_VALUE == 14 )); then /DietPi/dietpi/func/dietpi-led_control elif (( $G_WHIP_RETURNED_VALUE == 16 )); then # - Known FP's for setting brightness local afp_current_set_brightness=( '/sys/class/backlight/intel_backlight' '/sys/class/backlight/rpi_backlight' '/sys/class/backlight/lcd0' '/sys/class/backlight/backlight' ) MIN_VALUE=0 MAX_VALUE=255 local fp_brightness='' local current_brightness='' for fp_brightness in "${afp_current_set_brightness[@]}" do if [[ -f $fp_brightness/brightness ]]; then current_brightness=$(<$fp_brightness/brightness) [[ -f $fp_brightness/max_brightness ]] && MAX_VALUE=$(<$fp_brightness/max_brightness) break fi done if disable_error=1 G_CHECK_VALIDINT "$current_brightness"; then G_WHIP_DEFAULT_ITEM=$current_brightness G_WHIP_INPUTBOX "Please enter a brightness value:\n - Min = $MIN_VALUE | Max = $MAX_VALUE" if (( $? == 0 )) && G_CHECK_VALIDINT "$G_WHIP_RETURNED_VALUE" $MIN_VALUE $MAX_VALUE; then # - apply echo $G_WHIP_RETURNED_VALUE > $fp_brightness/brightness fi else Info_HW_OptionNotSupported fi elif (( $G_WHIP_RETURNED_VALUE == 17 )); then G_WHIP_MENU_ARRAY=( '96' ': Default' '120' ": +25% larger" '144' ": +50% larger" '168' ": +75% larger" '192' ": +100% larger" ) G_WHIP_DEFAULT_ITEM=$xorg_dpi_current if G_WHIP_MENU "Please select a DPI value for Xorg: - A higher value will make text and windows larger - Has no effect on local terminal (eg: no desktop installed) \nNB: Setting will only take effect, once system is restarted."; then G_CONFIG_INJECT 'SOFTWARE_XORG_DPI=' "SOFTWARE_XORG_DPI=$G_WHIP_RETURNED_VALUE" /DietPi/dietpi.txt mkdir -p /etc/X11/Xsession.d echo "xrandr --dpi $G_WHIP_RETURNED_VALUE" > /etc/X11/Xsession.d/99-dietpi-dpi REBOOT_REQUIRED=1 fi fi fi } Xorg_Configure(){ if G_WHIP_YESNO "Xorg Configuration:\nNB: This feature will only work if X server is NOT currently running. \nPlease ensure:\n - No current X server (desktop) is running \nIf a desktop is running, please set 'dietpi-autostart' to 'Console', reboot system, then rerun this option. \nWould you like to continue?"; then G_RUN_CMD Xorg -configure mv /root/xorg.conf.new /etc/X11/xorg.conf fi } # TARGETMENUID=2 Menu_DisplayOptions_Driver_Resolution(){ TARGETMENUID=1 # Return to Display Options menu # VM if (( $G_HW_MODEL == 20 )); then local current=$(grep -m1 '^[[:blank:]]*GRUB_GFXMODE=' /etc/default/grub | sed 's/^[^=]*=//') [[ $current ]] || current='System default' G_WHIP_MENU_ARRAY=( '1600x1200' '' '1280x1024' '' '1152x864' '' '1024x768' '' '800x600' '' 'System default' '' ) G_WHIP_DEFAULT_ITEM=$current if G_WHIP_MENU "Please select a display resolution. Current: $current \nNB: This only affects the virtual screen resolution, not the SSH session. You might need to increase the maximum guest screen resolution within your VM software."; then if [[ $G_WHIP_RETURNED_VALUE == 'System default' ]]; then sed -i 's/^[[:blank:]]*GRUB_GFXMODE=/#GRUB_GFXMODE=/' /etc/default/grub sed -i 's/^[[:blank:]]*GRUB_GFXPAYLOAD_LINUX=/#GRUB_GFXPAYLOAD_LINUX=/' /etc/default/grub else G_CONFIG_INJECT 'GRUB_GFXMODE=' "GRUB_GFXMODE=$G_WHIP_RETURNED_VALUE" /etc/default/grub G_CONFIG_INJECT 'GRUB_GFXPAYLOAD_LINUX=' 'GRUB_GFXPAYLOAD_LINUX=keep' /etc/default/grub 'GRUB_GFXMODE=' fi update-grub fi # Native PC elif (( $G_HW_MODEL == 21 )); then local nvidia_installed=0 local nvidia_text='Install GPU driver' if dpkg-query -s nvidia-driver &> /dev/null; then nvidia_installed=1 nvidia_text='Uninstall GPU driver' fi local intel_installed=0 local intel_text='Install GPU driver' if dpkg-query -s xserver-xorg-video-intel &> /dev/null; then intel_installed=1 intel_text='Uninstall GPU driver' fi G_WHIP_MENU_ARRAY=( 'Nvidia' ": $nvidia_text" 'Intel' ": $intel_text" ) if G_WHIP_MENU 'Please select an option:'; then TARGETMENUID=2 if [[ $G_WHIP_RETURNED_VALUE == 'Nvidia' ]]; then if (( $nvidia_installed )); then /DietPi/dietpi/dietpi-software uninstall 151 else /DietPi/dietpi/dietpi-software install 151 fi REBOOT_REQUIRED=1 elif [[ $G_WHIP_RETURNED_VALUE == 'Intel' ]]; then if (( $intel_installed )); then G_AGP i965-va-driver xserver-xorg-video-intel else G_AG_CHECK_INSTALL_PREREQ i965-va-driver xserver-xorg-video-intel libgl1-mesa-dri Xorg_Configure fi fi fi # RPi elif (( $G_HW_MODEL < 10 )); then local framebuffer_x=$(grep -m1 '^[[:blank:]]*framebuffer_width=' /DietPi/config.txt || vcgencmd get_config framebuffer_width) framebuffer_x=${framebuffer_x#*=}; framebuffer_x=${framebuffer_x:-0} local framebuffer_y=$(grep -m1 '^[[:blank:]]*framebuffer_height=' /DietPi/config.txt || vcgencmd get_config framebuffer_height) framebuffer_y=${framebuffer_y#*=}; framebuffer_y=${framebuffer_y:-0} local current_value=$(grep -m1 '^[[:blank:]]*dtoverlay=vc4-' /DietPi/config.txt | sed 's/^[^=]*=//') #OpenGL check 1st #If framebuffer is not set by user then check if hdmi default is detected and being used if [[ "$framebuffer_y" == 0 ]] && [[ "$framebuffer_x" == 0 ]]; then #Get default X,Y resolution local framebuffer_x=$(tvservice -s | cut -d ',' -f2 | cut -d 'x' -f1 | awk '{print $NF}') local framebuffer_y=$(tvservice -s | cut -d ',' -f2 | cut -d 'x' -f2 | awk '{print $1}') fi if [[ ! $current_value ]]; then # - FB current_value="$framebuffer_x X $framebuffer_y" # - check for headless grep -qi 'hdmi_ignore_hotplug=1' /DietPi/config.txt && grep -qi 'hdmi_ignore_composite=1' /DietPi/config.txt && current_value='Headless' fi #Check if hdmi monitor/tv is detected #Monitor? DMT_detected=`(tvservice -m DMT | grep -m1 'Group DMT' | awk '{print $2}')` #TV? CEA_detected=`(tvservice -m CEA | grep -m1 'Group CEA' | awk '{print $2}')` if [[ "$DMT_detected" == 'DMT' ]] || [[ "$CEA_detected" == 'CEA' ]]; then G_WHIP_MENU_ARRAY=() #Add DMT & options to arrays if [[ "$DMT_detected" == 'DMT' ]]; then #Check if perfered resolution exists DMT_prefer=`(tvservice -m DMT | grep -m1 'prefer')` #Grab preferd resolution from this list first, if it exists, and add it to the start of the array if [ -n "$DMT_prefer" ]; then G_WHIP_MENU_ARRAY+=("`tvservice -m DMT | grep -m1 'prefer' | cut -d ':' -f1 | cut -d 'm' -f2 | sed 's/ode/DMT/'`" "`tvservice -m DMT | grep -m1 'prefer' | cut -d ',' -f1 | cut -d ':' -f2- | sed 's/ /: /' | awk '{print $0" *Preferd"}'`") fi #Check if native resolution exists DMT_native=`(tvservice -m DMT | grep -m1 'native')` #Grab preferd resolution from this list first, if it exists, and add it to the start of the array if [ -n "$DMT_native" ]; then G_WHIP_MENU_ARRAY+=("`tvservice -m DMT | grep -m1 'native' | cut -d ':' -f1 | cut -d 'm' -f2 | sed 's/ode/DMT/'`" "`tvservice -m DMT | grep -m1 'native' | cut -d ',' -f1 | cut -d ':' -f2- | sed 's/ /: /' | awk '{print $0" *native"}'`") fi #Add the rest of the detected resolutions to the array #Usable info starts at line 2 DMT_LineNumber=2 DMT_Nullcheck=`(tvservice -m DMT | grep -vwE 'prefer' | grep -vwE 'native' | awk -v LineNumber="$DMT_LineNumber" 'NR==LineNumber')` until [ ! "$DMT_Nullcheck" ] || [ $DMT_LineNumber -gt 100 ] ; do G_WHIP_MENU_ARRAY+=("`tvservice -m DMT | grep -vwE 'prefer' | grep -vwE 'native' | awk -v LineNumber="$DMT_LineNumber" 'NR==LineNumber' | cut -d ':' -f1 | cut -d 'm' -f2 | sed 's/ode/DMT/'`" "`tvservice -m DMT | grep -vwE 'prefer' | grep -vwE 'native' | awk -v LineNumber="$DMT_LineNumber" 'NR==LineNumber' | cut -d ',' -f1 | cut -d ':' -f2- | sed 's/ /: /'`") let DMT_LineNumber=DMT_LineNumber+1 DMT_Nullcheck=`(tvservice -m DMT | grep -vwE 'prefer' | grep -vwE 'native' | awk -v LineNumber="$DMT_LineNumber" 'NR==LineNumber')` done fi #Add CEA & options to arrays if [[ "$CEA_detected" == 'CEA' ]]; then #Check if perfered resolution exists CEA_prefer=`(tvservice -m CEA | grep -m1 'prefer')` #Grab preferd resolution from this list first, if it exists, and add it to the start of the array if [ -n "$CEA_prefer" ]; then G_WHIP_MENU_ARRAY+=("`tvservice -m CEA | grep -m1 'prefer' | cut -d ':' -f1 | cut -d 'm' -f2 | sed 's/ode/CEA/'`" "`tvservice -m CEA | grep -m1 'prefer' | cut -d ',' -f1 | cut -d ':' -f2- | sed 's/ /: /' | awk '{print $0" *Preferd"}'`") fi #Check if native resolution exists CEA_native=`(tvservice -m CEA | grep -m1 'native')` #Grab preferd resolution from this list first, if it exists, and add it to the start of the array if [ -n "$CEA_native" ]; then G_WHIP_MENU_ARRAY+=("`tvservice -m CEA | grep -m1 'native' | cut -d ':' -f1 | cut -d 'm' -f2 | sed 's/ode/CEA/'`" "`tvservice -m CEA | grep -m1 'native' | cut -d ',' -f1 | cut -d ':' -f2- | sed 's/ /: /' | awk '{print $0" *native"}'`") fi #Add the rest of the detected resolutions to the array #Usable info starts at line 2 CEA_LineNumber=2 CEA_Nullcheck=`(tvservice -m CEA | grep -vwE 'prefer' | grep -vwE 'native' | awk -v LineNumber="$CEA_LineNumber" 'NR==LineNumber')` until [ ! "$CEA_Nullcheck" ] || [ $CEA_LineNumber -gt 100 ] ; do G_WHIP_MENU_ARRAY+=("`tvservice -m CEA | grep -vwE 'prefer' | grep -vwE 'native' | awk -v LineNumber="$CEA_LineNumber" 'NR==LineNumber' | cut -d ':' -f1 | cut -d 'm' -f2 | sed 's/ode/CEA/'`" "`tvservice -m CEA | grep -vwE 'prefer' | grep -vwE 'native' | awk -v LineNumber="$CEA_LineNumber" 'NR==LineNumber' | cut -d ',' -f1 | cut -d ':' -f2- | sed 's/ /: /'`") let CEA_LineNumber=CEA_LineNumber+1 CEA_Nullcheck=`(tvservice -m CEA | grep -vwE 'prefer' | grep -vwE 'native' | awk -v LineNumber="$CEA_LineNumber" 'NR==LineNumber')` done fi #add Additional Options G_WHIP_MENU_ARRAY+=( 'vc4-kms-v3d' ': OpenGL | 1920 x 1080' 'vc4-fkms-v3d' ': OpenGL | 1920 x 1080' 'RPi Touchscreen' ': 800 x 480' 'DietPi-Cloudshell' ': 320 x 240' 'Headless' ': Disables HDMI & Composite Output' ) else #Load default menu if hdmi info is not detected G_WHIP_MENU_ARRAY=( 'vc4-kms-v3d' ': OpenGL | 1920 x 1080' 'vc4-fkms-v3d' ': OpenGL | 1920 x 1080' '1080p' ': 1920 x 1080' '720p' ': 1280 x 720' '480p' ': 854 x 480' 'RPi Touchscreen' ': 800 x 480' 'PC1' ': 1024 x 768' 'PC2' ': 800 x 640' 'PC3' ': 640 x 480' 'DietPi-Cloudshell' ': 320 x 240' 'sdtv_mode=0' ': Composite NTSC' 'sdtv_mode=1' ': Composite Japanese NTSC' 'sdtv_mode=2' ': Composite PAL' 'sdtv_mode=3' ': Composite Brazilian PAL' 'Headless' ': Disables HDMI & Composite Output' ) fi G_WHIP_DEFAULT_ITEM=$current_value if G_WHIP_MENU "Hardware: $G_HW_MODEL_DESCRIPTION\nCurrent resolution: $current_value"; then REBOOT_REQUIRED=1 TARGETMENUID=2 # Return to this menu if [[ $G_WHIP_RETURNED_VALUE == 'Headless' ]]; then G_WHIP_YESNO 'Using the Headless option will: - Disable HDMI and composite output - Disable the framebuffer - Lower energy consumption by 0.1+ Watts - Improve RAM performance by 1-5% (VideoCore shares RAM bandwidth) - Lead to some kernel error messages on boot, that can be ignored\n Re-enabling HDMI requires a reboot. If you need emergency HDMI output, comment or remove the following lines within "config.txt" on first partition of the SDcard from external system: - hdmi_ignore_hotplug=1 - hdmi_ignore_composite=1\n More info here: https://www.raspberrypi.org/forums/viewtopic.php?p=105008#p105008 and here: https://github.com/raspberrypi/userland/issues/447#issuecomment-404399670' || { REBOOT_REQUIRED=0; return; } /DietPi/dietpi/func/dietpi-set_hardware headless 1 else /DietPi/dietpi/func/dietpi-set_hardware headless 0 fi # - Always disable composite by default [[ $G_WHIP_RETURNED_VALUE == 'sdtv_mode'* ]] || sed -i '/sdtv_mode=/c\#sdtv_mode=0' /DietPi/config.txt # - Always disable OpenGL by default [[ $G_WHIP_RETURNED_VALUE == 'vc4-'* ]] || /DietPi/dietpi/func/dietpi-set_hardware rpi-opengl disable if [[ $G_WHIP_RETURNED_VALUE == 'vc4-'* ]]; then /DietPi/dietpi/func/dietpi-set_hardware rpi-opengl $G_WHIP_RETURNED_VALUE elif [[ $G_WHIP_RETURNED_VALUE != 'Headless' ]]; then case "$G_WHIP_RETURNED_VALUE" in 'sdtv_mode'*) sed -i "/sdtv_mode=/c\\$G_WHIP_RETURNED_VALUE" /DietPi/config.txt framebuffer_x=720 framebuffer_y=576 ;; 'DietPi-Cloudshell') framebuffer_x=320 framebuffer_y=240 ;; '1080p') framebuffer_x=1920 framebuffer_y=1080 ;; '720p') framebuffer_x=1280 framebuffer_y=720 ;; '480p') framebuffer_x=854 framebuffer_y=480 ;; 'RPi Touchscreen') framebuffer_x=800 framebuffer_y=480 ;; 'PC1') framebuffer_x=1024 framebuffer_y=768 ;; 'PC2') framebuffer_x=800 framebuffer_y=640 ;; 'PC3') framebuffer_x=640 framebuffer_y=480 ;; esac # - Apply x/y G_CONFIG_INJECT 'framebuffer_width=' "framebuffer_width=$framebuffer_x" /DietPi/config.txt G_CONFIG_INJECT 'framebuffer_height=' "framebuffer_height=$framebuffer_y" /DietPi/config.txt G_CONFIG_INJECT 'SOFTWARE_CHROMIUM_RES_X=' "SOFTWARE_CHROMIUM_RES_X=$framebuffer_x" /DietPi/dietpi.txt G_CONFIG_INJECT 'SOFTWARE_CHROMIUM_RES_Y=' "SOFTWARE_CHROMIUM_RES_Y=$framebuffer_y" /DietPi/dietpi.txt fi fi # Odroid C1: REMOVE v6.24 elif (( $G_HW_MODEL == 10 && $G_DISTRO == 3 )); then # Get Current Values local current_resolution=$(mawk -F '"' '/setenv m "/ {print $2;exit}' /DietPi/boot.ini) G_WHIP_MENU_ARRAY=( '1080p' ': 1920 x 1080' '720p' ': 1280 x 720' '480p' ': 720 x 480' 'VU7+' ': 1024 x 600' 'PC1' ': 1024 x 768' ) G_WHIP_DEFAULT_ITEM=$current_resolution if G_WHIP_MENU "Hardware : $G_HW_MODEL_DESCRIPTION\nCurrent: $current_resolution"; then REBOOT_REQUIRED=1 TARGETMENUID=2 # Return to this menu # - Always reset to HDMI sed -i '/setenv vout_mode /c\setenv vout_mode "hdmi"' /DietPi/boot.ini case "$G_WHIP_RETURNED_VALUE" in '1080p') sed -i '/setenv m /c\setenv m "1080p"' /DietPi/boot.ini ;; '720p') sed -i '/setenv m /c\setenv m "720p"' /DietPi/boot.ini ;; '480p') sed -i '/setenv m /c\setenv m "480p"' /DietPi/boot.ini ;; 'PC1') sed -i '/setenv m /c\setenv m "1024x768"' /DietPi/boot.ini ;; 'VU7+') sed -i '/setenv m /c\setenv m "1024x600"' /DietPi/boot.ini sed -i '/setenv vout_mode /c\setenv vout_mode "dvi"' /DietPi/boot.ini ;; esac fi # Odroid XU3/4 elif (( $G_HW_MODEL == 11 )); then # Get Current Values local current_resolution=$(grep -m1 'setenv videoconfig \"' /DietPi/boot.ini) if [[ $current_resolution == *'1920x1080'* ]]; then current_resolution='1080p' elif [[ $current_resolution == *'1280x720'* ]]; then current_resolution='720p' elif [[ $current_resolution == *'720x480'* ]]; then current_resolution='480p' fi G_WHIP_MENU_ARRAY=( '1920x1080' ': 1080p' '1280x720' ': 720p' '720x480' ': 480p' '1024x600' ': VU7+' ) G_WHIP_DEFAULT_ITEM=$current_resolution if G_WHIP_MENU "Hardware : $G_HW_MODEL_DESCRIPTION \nCurrent: $current_resolution"; then REBOOT_REQUIRED=1 TARGETMENUID=2 # Return to this menu # - Always reset to hdmi sed -i '/setenv vout /c\setenv vout "hdmi"' /DietPi/boot.ini if [[ $G_WHIP_RETURNED_VALUE == '1024x600' ]]; then sed -i '/setenv vout /c\setenv vout "dvi"' /DietPi/boot.ini fi sed -i "/setenv videoconfig /c\setenv videoconfig \"drm_kms_helper.edid_firmware=edid/$G_WHIP_RETURNED_VALUE.bin\"" /DietPi/boot.ini fi # Odroid C2 elif (( $G_HW_MODEL == 12 )); then # Get Current Values local current_resolution=$(mawk -F '"' '/setenv m "/ {print $2;exit}' /DietPi/boot.ini | sed 's/p/p /') # - NB: also added space after xxxp, so its easier to read, and selects default item. G_WHIP_MENU_ARRAY=( '2160p 60hz' ': 4K (Recommended)' '2160p 50hz' ': 4K' '2160p 30hz' ': 4K' '2160p 25hz' ': 4K' '2160p 24hz' ': 4K' '1080p 60hz' ': 1080p (Recommended)' '1080p 50hz' ': 1080p' '1080p 24hz' ': 1080p' '720p 60hz' ': 720p (Recommended)' '720p 50hz' ': 720p' '480p 60hz' ': 480p' '1024x600p 60hz' ': VU7+' '1024x768p 60hz' ': 4:3' '800x600p 60hz' ': 4:3' ) G_WHIP_DEFAULT_ITEM=$current_resolution if G_WHIP_MENU "Hardware : $G_HW_MODEL_DESCRIPTION \nCurrent: $current_resolution"; then [[ $current_resolution != $G_WHIP_RETURNED_VALUE ]] && REBOOT_REQUIRED=1 # Always reset vga/dvi options sed -i '/setenv vout "dvi"/c\# setenv vout "dvi"' /DietPi/boot.ini sed -i '/setenv vout "vga"/c\# setenv vout "vga"' /DietPi/boot.ini # DVI / VU7+ if [[ $G_WHIP_RETURNED_VALUE == '1024x600p 60hz' ]]; then # + DVI mode sed -i '/setenv vout "dvi"/c\setenv vout "dvi"' /DietPi/boot.ini fi # Remove the space from option local temp_string=${G_WHIP_RETURNED_VALUE//[[:blank:]]/} sed -i "/setenv m /c\setenv m \"$temp_string\"" /DietPi/boot.ini TARGETMENUID=2 # Return to this menu fi # Pine A64 elif (( $G_HW_MODEL == 40 )); then # Get Current Values local current_resolution=$(grep -m1 '^[[:blank:]]*hdmi_mode=' /DietPi/uEnv.txt | sed 's/^[^=]*=//') [[ $current_resolution ]] || current_resolution='Not set' G_WHIP_MENU_ARRAY=( '720p50' '' '720p60' ': 720p' '1080i50' '' '1080i60' ': 1080i' '1080p24' '' '1080p50' '' '1080p60' ': 1080p' '2160p24' '' '2160p25' '' '2160p30' ': 4K' ) G_WHIP_DEFAULT_ITEM=$current_resolution if G_WHIP_MENU "Hardware : $G_HW_MODEL_DESCRIPTION \nCurrent: $current_resolution"; then if [[ $current_resolution != $G_WHIP_RETURNED_VALUE ]]; then G_CONFIG_INJECT 'hdmi_mode=' "hdmi_mode=$G_WHIP_RETURNED_VALUE" /DietPi/uEnv.txt REBOOT_REQUIRED=1 fi TARGETMENUID=2 # Return to this menu fi else Info_HW_OptionNotSupported fi } # TARGETMENUID=18 Menu_AdvancedOptions_Serial_UART(){ TARGETMENUID=18 # Return to this menu declare -A aSTATE=() G_WHIP_MENU_ARRAY=() (( $G_HW_MODEL < 10 )) && G_WHIP_MENU_ARRAY+=('' '●─ Toggle console ') for i in /dev/tty{S,AMA,SAC}[0-9] do [[ -e $i ]] || continue i=${i#/dev/} aSTATE[$i]='[Off]' systemctl -q is-active serial-getty@$i && aSTATE[$i]='[On]' G_WHIP_MENU_ARRAY+=("$i console" ": ${aSTATE[$i]}") done # RPi special local rpi_text='' if (( $G_HW_MODEL < 10 )); then local rpi_text='\n\nOn Raspberry Pi you can additionally enable or disable the primary UART device completely (requires reboot).' G_WHIP_MENU_ARRAY+=('' '●─ Toggle device ') # Onboard WiFi/BT: "enable_uart" toggles ttyS0 (mini UART), disabled by default if (( $(sed -n 9p /DietPi/dietpi/.hw_model) )); then local rpi_uart='ttyS0 (mini UART)' local rpi_uart_state='[Off]' grep -q '^[[:blank:]]*enable_uart=1' /DietPi/config.txt && rpi_uart_state='[On]' # Nonboard WiFi/BT: "enable_uart" toggles ttyAMA0 (full UART). enabled by default else local rpi_uart='ttyAMA0 (full UART)' local rpi_uart_state='[On]' grep -q '^[[:blank:]]*enable_uart=0' /DietPi/config.txt && rpi_uart_state='[Off]' fi G_WHIP_MENU_ARRAY+=("$rpi_uart device" ": $rpi_uart_state") fi (( ${#G_WHIP_MENU_ARRAY[@]} > 2 )) || { G_WHIP_MSG 'No serial/UART devices have been found on your system.'; TARGETMENUID=3; return; } G_WHIP_BUTTON_CANCEL_TEXT='Back' if G_WHIP_MENU "Select an available serial/UART device to toggle a login console on it.$rpi_text"; then if [[ $G_WHIP_RETURNED_VALUE == *'device' ]]; then local toggle=1 [[ $rpi_uart_state == '[On]' ]] && toggle=0 && /DietPi/dietpi/func/dietpi-set_hardware serialconsole disable ${G_WHIP_RETURNED_VALUE%% *} G_CONFIG_INJECT 'enable_uart=' "enable_uart=$toggle" /DietPi/config.txt REBOOT_REQUIRED=1 elif [[ $G_WHIP_RETURNED_VALUE == *'console' ]]; then local toggle='enable' [[ ${aSTATE[${G_WHIP_RETURNED_VALUE%% *}]} == '[On]' ]] && toggle='disable' /DietPi/dietpi/func/dietpi-set_hardware serialconsole $toggle ${G_WHIP_RETURNED_VALUE%% *} fi else TARGETMENUID=3 # Return to Advanced Options fi } # TARGETMENUID=3 Menu_AdvancedOptions(){ TARGETMENUID=0 # Swap file local swap_size=$(free -m | mawk '/Swap:/ {print $2;exit}') local swap_location=$(grep -m1 '^[[:blank:]]*AUTO_SETUP_SWAPFILE_LOCATION=' /DietPi/dietpi.txt | sed 's/^[^=]*=//') local swap_size_text="$swap_size MB" (( $swap_size )) || swap_size_text='[Off]' G_WHIP_MENU_ARRAY=('Swapfile' ": [$swap_size_text | $swap_location]") # Time sync local ntpd_mode_current=$(grep -m1 '^[[:blank:]]*CONFIG_NTP_MODE=' /DietPi/dietpi.txt | sed 's/^[^=]*=//') local ntpd_mode_text='' if (( $ntpd_mode_current == 0 )); then ntpd_mode_text='Custom' elif (( $ntpd_mode_current == 1 )); then ntpd_mode_text='Boot Only' elif (( $ntpd_mode_current == 2 )); then ntpd_mode_text='Boot + Daily' elif (( $ntpd_mode_current == 3 )); then ntpd_mode_text='Boot + Hourly' elif (( $ntpd_mode_current == 4 )); then ntpd_mode_text='Daemon + Drift' fi G_WHIP_MENU_ARRAY+=('Time sync mode' ": [$ntpd_mode_text]") # RTC clock local rtc_enabled=1 local rtc_text='Hardware' if command -v fake-hwclock &> /dev/null; then rtc_enabled=0 rtc_text='Emulated' fi G_WHIP_MENU_ARRAY+=('RTC mode' ": [$rtc_text]") # Hide firmware update on RPi. This is done automatically with simple apt upgrade since raspberrypi-kernel it is no meta-package. (( $G_HW_MODEL > 9 )) && G_WHIP_MENU_ARRAY+=('Update firmware' '') # Serial/UART devices G_WHIP_MENU_ARRAY+=('Serial/UART' ': Manage available devices') # Bluetooth: Not for VM if (( $G_HW_MODEL != 20 )); then local bluetooth_state_text='[On]' local bluetooth_state=1 if [[ -f /etc/modprobe.d/disable_bt.conf ]]; then bluetooth_state=0 bluetooth_state_text='[Off]' fi G_WHIP_MENU_ARRAY+=('Bluetooth' ": $bluetooth_state_text") fi # RPi specific if (( $G_HW_MODEL < 10 )); then # I2C state local rpi_i2c_enabled=$(grep -ci -m1 '^[[:blank:]]*dtparam=i2c_arm=on' /DietPi/config.txt) local rpi_i2c_text='[Off]' (( $rpi_i2c_enabled )) && rpi_i2c_text='[On]' G_WHIP_MENU_ARRAY+=('I2C state' ": $rpi_i2c_text") # I2C baudrate local rpi_i2cbaudrate_hz=$(grep -m1 '^[[:blank:]]*i2c_arm_baudrate=' /DietPi/config.txt | sed 's/^[^=]*=//') # - Allow commented/non-existent entry, using default value: https://github.com/raspberrypi/firmware/blob/d69aadedb7c146ba5d3b0b45a661e5669a9141c4/boot/overlays/README#L115-L116 rpi_i2cbaudrate_hz="$(( ${rpi_i2cbaudrate_hz:-100000} / 1000 )) kHz" G_WHIP_MENU_ARRAY+=('I2C frequency' ": [$rpi_i2cbaudrate_hz]") # USB max current local usb_max_current_enabled=$(grep -ci -m1 '^[[:blank:]]*max_usb_current=1' /DietPi/config.txt) local rpi_usbmaxcurrent_text='[Off]' (( $usb_max_current_enabled )) && rpi_usbmaxcurrent_text='[On]' G_WHIP_MENU_ARRAY+=('Max USB current' ": $rpi_usbmaxcurrent_text") # USB boot option: RPi3 only and not required for RPi3+: https://www.raspberrypi.org/documentation/hardware/raspberrypi/bootmodes/msd.md if (( $G_HW_MODEL == 3 )) && [[ $G_HW_MODEL_DESCRIPTION == *'3 Model '[AB]'+' ]]; then local rpi3_usb_boot_bit_enabled=$(vcgencmd otp_dump | grep -m1 '17:' | grep -ci -m1 '3020000a') local rpi3_usb_boot_bit_enabled_text='[Off]' (( $rpi3_usb_boot_bit_enabled )) && rpi3_usb_boot_bit_enabled_text='[On]' G_WHIP_MENU_ARRAY+=('USB boot support' ": $rpi3_usb_boot_bit_enabled_text") fi fi if G_WHIP_MENU 'Please select an option:'; then TARGETMENUID=3 # Return to this menu if [[ $G_WHIP_RETURNED_VALUE == 'Swapfile' ]]; then if G_WHIP_YESNO 'Swapfile control has been moved to DietPi-Drive_Manager, would you like to run the application now? \nOnce finished, exit to resume DietPi-Config'; then /DietPi/dietpi/dietpi-drive_manager fi elif [[ $G_WHIP_RETURNED_VALUE == 'RTC mode' ]]; then if (( ! $rtc_enabled )); then G_AGP fake-hwclock else G_AGI fake-hwclock systemctl stop fake-hwclock # - Allow times in the past G_CONFIG_INJECT 'FORCE=' 'FORCE=force' /etc/default/fake-hwclock systemctl restart fake-hwclock fi elif [[ $G_WHIP_RETURNED_VALUE == 'Time sync mode' ]]; then G_WHIP_MENU_ARRAY=( '0' ': Custom' '1' ': Boot Only' '2' ': Boot + Daily (Recommended)' '3' ': Boot + Hourly' '4' ': Daemon + Drift' ) G_WHIP_DEFAULT_ITEM=$ntpd_mode_current G_WHIP_MENU 'Here you can adjust the frequency of network time syncs.\n - Modes 1-3:\nDietPi will launch systemd-timesyncd as a program, rather than a daemon. Once the time has been updated on your system, timesyncd will exit to reduce resource usage.\n - Mode 4:\nsystemd-timesyncd will run as a background daemon/service. Differences in time will be gradually adjusted over time, rather than instantly.\n - Mode 0:\nIf you use a custom time sync method, e.g. the NTP package for high precision demand, select custom mode to avoid systemd-timesyncd interference.' if (( $? == 0 )); then /DietPi/dietpi/func/dietpi-set_software ntpd-mode $G_WHIP_RETURNED_VALUE /DietPi/dietpi/func/run_ntpd 1 fi elif [[ $G_WHIP_RETURNED_VALUE == 'Update firmware' ]]; then local old_firmware=$(ls /lib/modules/) # Pine A64: Non-ARMbian only if [[ $G_HW_MODEL == 40 && -f '/usr/local/sbin/pine64_update_uboot.sh' && -f '/usr/local/sbin/pine64_update_kernel.sh' ]]; then if G_WHIP_YESNO "Would you like to update the firmware/kernel for $G_HW_MODEL_DESCRIPTION? - This will run longsleep's update scripts to update the U-Boot and kernel."; then /usr/local/sbin/pine64_update_uboot.sh /usr/local/sbin/pine64_update_kernel.sh fi # G_AGDUG based (not all devices support this) elif G_WHIP_YESNO "Would you like to update the firmware/kernel for $G_HW_MODEL_DESCRIPTION? - This will run G_AGDUG, a wrapper for 'apt-get dist-upgrade'\n - Most (but not all) devices allow APT based firmware updates \nNB: If requested to overwrite the current kernel, press TAB and then ENTER (to confirm)."; then G_AGUP G_AGDUG fi # Reboot required only, if firmware got actually updated [[ $old_firmware != $(ls /lib/modules/) ]] && REBOOT_REQUIRED=1 elif [[ $G_WHIP_RETURNED_VALUE == 'Max USB current' ]]; then # Enabled if (( $usb_max_current_enabled == 1 )); then if G_WHIP_YESNO "Current setting: $rpi_usbmaxcurrent_text (1.2AMP)\nWould you like to disable this setting? \nOnce Disabled:\n - Max USB current will be limited to 0.6AMP.\n - Shared by all USB ports."; then sed -i '/max_usb_current=/c\max_usb_current=0' /DietPi/config.txt REBOOT_REQUIRED=1 fi # Disabled elif (( $usb_max_current_enabled == 0 )); then if G_WHIP_YESNO "Current setting: $rpi_usbmaxcurrent_text (0.6AMP)\nWould you like to enable this setting? \nOnce Enabled:\n - Max USB current will be set to 1.2AMP.\n - Shared by all USB ports."; then sed -i '/max_usb_current=/c\max_usb_current=1' /DietPi/config.txt REBOOT_REQUIRED=1 fi fi elif [[ $G_WHIP_RETURNED_VALUE == 'I2C state' ]]; then if (( $rpi_i2c_enabled )); then /DietPi/dietpi/func/dietpi-set_hardware i2c disable else /DietPi/dietpi/func/dietpi-set_hardware i2c enable fi REBOOT_REQUIRED=1 elif [[ $G_WHIP_RETURNED_VALUE == 'I2C frequency' ]]; then # Remove kHz from current G_WHIP_DEFAULT_ITEM=${rpi_i2cbaudrate_hz% kHz} if G_WHIP_INPUTBOX 'Please enter the required I2C baudrate frequency (kHz).'; then # Check valid int if G_CHECK_VALIDINT "$G_WHIP_RETURNED_VALUE"; then /DietPi/dietpi/func/dietpi-set_hardware i2c "$G_WHIP_RETURNED_VALUE" REBOOT_REQUIRED=1 fi fi elif [[ $G_WHIP_RETURNED_VALUE == 'Serial/UART' ]]; then TARGETMENUID=18 elif [[ $G_WHIP_RETURNED_VALUE == 'Bluetooth' ]]; then if (( $bluetooth_state )); then /DietPi/dietpi/func/dietpi-set_hardware bluetooth disable else /DietPi/dietpi/func/dietpi-set_hardware bluetooth enable fi elif [[ $G_WHIP_RETURNED_VALUE == 'USB boot support' ]]; then if (( ! $rpi3_usb_boot_bit_enabled )); then if G_WHIP_YESNO 'The following will enable the RPi 3 to boot from USB mass storage devices. A hardware bit "17:3020000a", specific to the device is set to enable the feature. \nNB:\n - Not all USB mass storage devices are supported\n - The HW bit which enables this setting is non-reversible \nDo you wish to enable USB mass storage boot support?'; then /DietPi/dietpi/func/dietpi-set_hardware rpi3_usb_boot enable REBOOT_REQUIRED=1 # Reboot now? G_WHIP_YESNO 'A reboot is required to apply this setting.\n\nPlease reboot this system once, the HW bit which allows USB boot support will then be set. After which, USB mass storage devices can be used for booting.\n\nWould you like to reboot the system now?' (( $? )) || reboot fi fi fi fi } # TARGETMENUID=4 Menu_PerformanceOptions(){ TARGETMENUID=0 # All devices local current_cpu_governor=$(grep -m1 '^[[:blank:]]*CONFIG_CPU_GOVERNOR=' /DietPi/dietpi.txt | sed 's/^[^=]*=//') local frequency_min_cpu_governor=1 local fp_frequency_min_cpu_governor='/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq' [[ -f $fp_frequency_min_cpu_governor ]] && frequency_min_cpu_governor=$(( $(<$fp_frequency_min_cpu_governor) / 1000 )) local frequency_max_cpu_governor=2 local fp_frequency_max_cpu_governor='/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq' [[ -f $fp_frequency_max_cpu_governor ]] && frequency_max_cpu_governor=$(( $(<$fp_frequency_max_cpu_governor) / 1000 )) local cpu_temp=$(G_OBTAIN_CPU_TEMP) local cpu_temp_f='Unknown' if disable_error=1 G_CHECK_VALIDINT "$cpu_temp"; then cpu_temp_f="$(( $cpu_temp * 9/5 + 32 ))'f" cpu_temp+="'c" fi local memory_total=$(( $(mawk '/MemTotal:/ {print $2;exit}' /proc/meminfo) / 1000 )) local memory_free=$(( $(mawk '/MemFree:/ {print $2;exit}' /proc/meminfo) / 1000 )) local memory_usage=$(( $memory_total - $memory_free )) # Create Menu List for Whiptail # - this will list the menu options available for each device. G_WHIP_MENU_ARRAY=() # RPi: Overclocking (( $G_HW_MODEL < 10 )) && G_WHIP_MENU_ARRAY+=('Overclocking' ': Set Profile') # CPU GOV G_WHIP_MENU_ARRAY+=('CPU Governor' ": [$current_cpu_governor]") # Ondemand/Interactive Throttle up menu if [[ $current_cpu_governor == 'ondemand' || $current_cpu_governor == 'conservative' || $current_cpu_governor == 'interactive' ]]; then local current_cpu_throttle_up=$(grep -m1 '^[[:blank:]]*CONFIG_CPU_USAGE_THROTTLE_UP=' /DietPi/dietpi.txt | sed 's/^[^=]*=//') G_WHIP_MENU_ARRAY+=('CPU Throttle Up' ": [${current_cpu_throttle_up}%]") fi # Ondemand extras if [[ $current_cpu_governor == 'ondemand' ]]; then local current_cpu_sample_rate=$(( $(grep -m1 '^[[:blank:]]*CONFIG_CPU_ONDEMAND_SAMPLE_RATE=' /DietPi/dietpi.txt | sed 's/[^=]*=//') / 1000 )) #convert to ms G_WHIP_MENU_ARRAY+=('Ondemand Sample Rate' ": [${current_cpu_sample_rate}ms]") local current_cpu_down_factor=$(grep -m1 '^[[:blank:]]*CONFIG_CPU_ONDEMAND_SAMPLE_DOWNFACTOR=' /DietPi/dietpi.txt | sed 's/[^=]*=//') local current_cpu_down_factor_ms=$(( $current_cpu_down_factor * $current_cpu_sample_rate )) G_WHIP_MENU_ARRAY+=('Ondemand Down Factor' ": [$current_cpu_down_factor (${current_cpu_down_factor_ms}ms)]") fi # Intel boost option (eg: i5-6200U, disables 2.9GHz mode, limits to 2.3GHz) local intel_boost_disabled=0 local intel_boost_text='Enabled' if grep -qi 'genuineintel' /proc/cpuinfo; then intel_boost_disabled=$(grep -m1 '^[[:blank:]]*CONFIG_CPU_DISABLE_TURBO=' /DietPi/dietpi.txt | sed 's/^[^=]*=//') (( $intel_boost_disabled )) && intel_boost_text='Disabled' G_WHIP_MENU_ARRAY+=('Intel Turbo/Boost' ": [$intel_boost_text]") fi # Define CPU scaling frequency or percent local type_cpu_freq_info='MHz' # - Intel [[ -f /sys/devices/system/cpu/intel_pstate/max_perf_pct ]] && type_cpu_freq_info='%' # - User Scaling Max Freq limit. local user_frequency_max_current=$(grep -m1 '^[[:blank:]]*CONFIG_CPU_MAX_FREQ=' /DietPi/dietpi.txt | sed 's/^[^=]*=//') local user_frequency_max_text="$user_frequency_max_current $type_cpu_freq_info" (( $user_frequency_max_current )) || user_frequency_max_text='Off' # - User Scaling Min Freq limit. local user_frequency_min_current=$(grep -m1 '^[[:blank:]]*CONFIG_CPU_MIN_FREQ=' /DietPi/dietpi.txt | sed 's/^[^=]*=//') local user_frequency_min_text="$user_frequency_min_current $type_cpu_freq_info" (( $user_frequency_min_current )) || user_frequency_min_text='Off' G_WHIP_MENU_ARRAY+=('CPU Frequency Limits' ": Max = [$user_frequency_max_text] | Min = [$user_frequency_min_text]") # RPi extras if (( $G_HW_MODEL < 10 )); then local current_cpu_temp_limit=$(grep -m1 'temp_limit' /DietPi/config.txt | sed 's/^[^=]*=//') G_WHIP_MENU_ARRAY+=('ARM Temp Limit ' ": [${current_cpu_temp_limit}'c]") ##Disabled due to https://github.com/MichaIng/DietPi/issues/73 #G_WHIP_MENU_ARRAY+=("Lower Idle Frequencies" ": $rpi_freq_min_text") # initial_turbo disabled due to: https://github.com/MichaIng/DietPi/issues/1836 #G_WHIP_MENU_ARRAY+=('ARM Initial Turbo' ": $text_current_initial_turbo") fi G_WHIP_MENU "Hardware : $G_HW_MODEL_DESCRIPTION \nCPU Temp: $cpu_temp : $cpu_temp_f\nRAM: $memory_total MB | Used: $memory_usage MB | Free: $memory_free MB" if (( $? == 0 )); then TARGETMENUID=4 # Return to this menu case "$G_WHIP_RETURNED_VALUE" in 'Intel Turbo/Boost'*) (( intel_boost_disabled++ )) (( $intel_boost_disabled > 1 )) && intel_boost_disabled=0 G_CONFIG_INJECT 'CONFIG_CPU_DISABLE_TURBO=' "CONFIG_CPU_DISABLE_TURBO=$intel_boost_disabled" /DietPi/dietpi.txt /DietPi/dietpi/func/dietpi-set_cpu ;; 'Ondemand Down Factor'*) MIN_VALUE=1 MAX_VALUE=200 G_WHIP_DEFAULT_ITEM=$current_cpu_down_factor G_WHIP_INPUTBOX "After Ondemand throttles up, how long before the next sample to check if CPU clocks can be reduced.\n\n - This value * 'Ondemand Sample Rate' = total miliseconds\n - Lower values may help reduce power consumption, however, a 500-1000ms value is recommended to prevent excessive sampling.\n - Valid range: $MIN_VALUE - $MAX_VALUE\n\nIf unsure, set any value, 'Ondemand Down Factor' option on the next screen will list the calculated miliseconds." if (( $? == 0 )); then if G_CHECK_VALIDINT "$G_WHIP_RETURNED_VALUE" $MIN_VALUE $MAX_VALUE; then G_CONFIG_INJECT 'CONFIG_CPU_ONDEMAND_SAMPLE_DOWNFACTOR=' "CONFIG_CPU_ONDEMAND_SAMPLE_DOWNFACTOR=$G_WHIP_RETURNED_VALUE" /DietPi/dietpi.txt /DietPi/dietpi/func/dietpi-set_cpu fi fi ;; 'Ondemand Sample Rate'*) local file='' local afile=( '/sys/devices/system/cpu/cpufreq/ondemand/sampling_rate_min' '/sys/devices/system/cpu/cpufreq/ondemand/min_sampling_rate' '/sys/devices/system/cpu/cpu0/cpufreq/ondemand/sampling_rate_min' '/sys/devices/system/cpu/cpu0/cpufreq/ondemand/min_sampling_rate' ) for i in ${afile[@]} do [[ -f $i ]] && file=$i && break done if [[ $file ]]; then MIN_VALUE=$(( $(<$file) / 1000 )) # - Unable to find min value, hard set it else MIN_VALUE=20 # RPi is min 20ms, however, no way to currently detect min available values... fi MAX_VALUE=300 G_WHIP_DEFAULT_ITEM=$current_cpu_sample_rate G_WHIP_INPUTBOX "Please enter a sample rate in milliseconds, for Ondemand to check if it needs to increase CPU clocks.\nA lower value will make the system more responsive.\n - valid range: $MIN_VALUE - $MAX_VALUE" if (( $? == 0 )); then if G_CHECK_VALIDINT "$G_WHIP_RETURNED_VALUE" $MIN_VALUE $MAX_VALUE; then G_CONFIG_INJECT 'CONFIG_CPU_ONDEMAND_SAMPLE_RATE=' "CONFIG_CPU_ONDEMAND_SAMPLE_RATE=$(( $G_WHIP_RETURNED_VALUE * 1000 ))" /DietPi/dietpi.txt /DietPi/dietpi/func/dietpi-set_cpu fi fi ;; 'CPU Frequency Limits'*) /DietPi/dietpi/dietpi-cpuinfo 2 if [[ ! -f /tmp/dietpi-available_cpu_freqs ]]; then G_WHIP_MSG 'The processor and/or kernel, does not support this feature.\n\n(Info): Scaling_available_frequencies does not exist.' else local available_frequency_array=() readarray available_frequency_array < /tmp/dietpi-available_cpu_freqs local division_factor=1000 #display MHz for user menu # - Intel (disable conversion) [[ -f /sys/devices/system/cpu/intel_pstate/max_perf_pct ]] && division_factor=1 local index=0 # 0=max | 1=min while (( $index < 2 )) do G_WHIP_MENU_ARRAY=() for ((i=0; i<${#available_frequency_array[@]}; i++)) do G_WHIP_MENU_ARRAY+=($(( ${available_frequency_array[$i]} / $division_factor )) "$type_cpu_freq_info") done G_WHIP_MENU_ARRAY+=('Disabled' ': Returns clocks to default') # - MAX if (( $index == 0 )); then G_WHIP_DEFAULT_ITEM=$user_frequency_max_current G_WHIP_MENU "Limit the maximum frequency that your processor can reach.\nThis can be useful for lowering temperature and saving power.\n\nCurrent setting: $user_frequency_max_text" if (( $? == 0 )); then G_CONFIG_INJECT 'CONFIG_CPU_MAX_FREQ=' "CONFIG_CPU_MAX_FREQ=$G_WHIP_RETURNED_VALUE" /DietPi/dietpi.txt fi # - MIN else G_WHIP_DEFAULT_ITEM=$user_frequency_min_current G_WHIP_MENU "Limit the minimum frequency that your processor can reach.\nThis can be useful for some timing critical stuff (eg. 1-wire below 480 Mhz won't work).\n\nCurrent setting: $user_frequency_min_text" if (( $? == 0 )); then G_CONFIG_INJECT 'CONFIG_CPU_MIN_FREQ=' "CONFIG_CPU_MIN_FREQ=$G_WHIP_RETURNED_VALUE" /DietPi/dietpi.txt fi fi ((index++)) done unset available_frequency_array /DietPi/dietpi/func/dietpi-set_cpu fi ;; 'Overclocking'*) TARGETMENUID=13 ;; 'CPU Governor'*) # - Scaling govs not available (No Gavnor!) if [[ ! -f $FP_CPU_SCALING_GOV ]]; then G_WHIP_MSG 'Your processor, or kernel, does not support this feature.\n\n(Info): scaling_available_governors does not exist.' # - Obtain available Govs. Setup their menu and description. (Yes Gavnor!) else local Description='CPU Governor:' G_WHIP_MENU_ARRAY=() if grep -qi 'ondemand' $FP_CPU_SCALING_GOV; then G_WHIP_MENU_ARRAY+=('ondemand' ": Scales CPU frequency between $frequency_min_cpu_governor MHz and $frequency_max_cpu_governor MHz.") Description+='\nOndemand | Dynamic CPU frequency based on usage (recommended).' fi if grep -qi 'interactive' $FP_CPU_SCALING_GOV; then G_WHIP_MENU_ARRAY+=('interactive' ": Scales CPU frequency between $frequency_min_cpu_governor MHz and $frequency_max_cpu_governor MHz.") Description+='\nInteractive | Dynamic CPU frequency based on usage.' fi if grep -qi 'conservative' $FP_CPU_SCALING_GOV; then G_WHIP_MENU_ARRAY+=('conservative' ": Scales CPU frequency between $frequency_min_cpu_governor MHz and $frequency_max_cpu_governor MHz.") Description+='\nConservative | Same as ondemand. Bias towards powersaving, slower scaling.' fi if grep -qi 'powersave' $FP_CPU_SCALING_GOV; then G_WHIP_MENU_ARRAY+=('powersave' ": Limits CPU frequency to $frequency_min_cpu_governor MHz.") Description+='\nPowersave | Static. Reduces energy consumption, heat, performance.' fi if grep -qi 'performance' $FP_CPU_SCALING_GOV; then G_WHIP_MENU_ARRAY+=('performance' ": Forces CPU frequency to $frequency_max_cpu_governor MHz.") Description+='\nPerformance | Static. Increases energy consumption, heat, performance.' fi G_WHIP_DEFAULT_ITEM=$current_cpu_governor if G_WHIP_MENU "$Description"; then G_CONFIG_INJECT 'CONFIG_CPU_GOVERNOR=' "CONFIG_CPU_GOVERNOR=$G_WHIP_RETURNED_VALUE" /DietPi/dietpi.txt /DietPi/dietpi/func/dietpi-set_cpu fi fi ;; 'CPU Throttle Up'*) MIN_VALUE=30 MAX_VALUE=95 G_WHIP_DEFAULT_ITEM=$current_cpu_throttle_up G_WHIP_INPUTBOX "When the CPU usage (%) is greater than this value, the CPU frequency will increase from $frequency_min_cpu_governor MHz to $frequency_max_cpu_governor MHz.\n - Valid range $MIN_VALUE - $MAX_VALUE\n - Recommended settings: Desktop = 50%, Server = 85%" if (( $? == 0 )); then if G_CHECK_VALIDINT "$G_WHIP_RETURNED_VALUE" $MIN_VALUE $MAX_VALUE; then G_CONFIG_INJECT 'CONFIG_CPU_USAGE_THROTTLE_UP=' "CONFIG_CPU_USAGE_THROTTLE_UP=$G_WHIP_RETURNED_VALUE" /DietPi/dietpi.txt /DietPi/dietpi/func/dietpi-set_cpu fi fi ;; 'ARM Temp Limit'*) MIN_VALUE=45 MAX_VALUE=85 G_WHIP_DEFAULT_ITEM=$current_cpu_temp_limit G_WHIP_INPUTBOX "When the ARM temperature ('c) reaches this value, the ARM will underclock to reduce heat. \n - Recommended value is 65 \n - Valid range $MIN_VALUE - $MAX_VALUE" if (( $? == 0 )); then if G_CHECK_VALIDINT "$G_WHIP_RETURNED_VALUE" $MIN_VALUE $MAX_VALUE; then if (( $G_WHIP_RETURNED_VALUE > 65 )); then G_WHIP_MSG "Higher operating temperatures will reduce the life of your ARM SoC. Heat also dissipates through the PCB into other components, decreasing the lifespan of the whole device. Use at your own risk.\n\nDietPi recommends 65'c as a safe value (75'c for RPi 3).\n\nMore info: https://github.com/MichaIng/DietPi/issues/356" fi G_CONFIG_INJECT 'temp_limit=' "temp_limit=$G_WHIP_RETURNED_VALUE" /DietPi/config.txt REBOOT_REQUIRED=1 fi fi ;; esac fi } Change_Hostname(){ # Get existing Hostname local hostname_existing=$(= 512 )); then G_WHIP_MENU_ARRAY+=(256 ': General Gaming') G_WHIP_MENU_ARRAY+=(320 ': Kodi') if (( $ram_mem_total >= 1024 )); then G_WHIP_MENU_ARRAY+=(448 '') G_WHIP_MENU_ARRAY+=(512 '') fi fi G_WHIP_DEFAULT_ITEM=$gpu_mem_current if G_WHIP_MENU "Hardware : $G_HW_MODEL_DESCRIPTION\nCurrent: $gpu_mem_current MB GPU | $ram_mem_current MB RAM"; then /DietPi/dietpi/func/dietpi-set_hardware gpumemsplit $G_WHIP_RETURNED_VALUE REBOOT_REQUIRED=1 TARGETMENUID=6 # Return to this menu fi # Odroid C1: REMOVE v6.24 elif (( $G_HW_MODEL == 10 && $G_DISTRO == 3 )); then # Odroid HDMI/headless extra data local display_output_enabled=$(grep -ci -m1 '^setenv hdmioutput "1"' /DietPi/boot.ini) local display_vpu_enabled=$(grep -ci -m1 '^setenv vpu "1"' /DietPi/boot.ini) local display_output_text='[On]' local display_vpu_text='[On]' (( $display_output_enabled )) || display_output_text='[Off]' (( $display_vpu_enabled )) || display_vpu_text='[Off]' G_WHIP_MENU_ARRAY=( 'Headless' 'HDMI: Disabled | VPU: Disabled' 'Server' 'HDMI: Enabled | VPU: Disabled' 'Desktop' 'HDMI: Enabled | VPU: Enabled' ) G_WHIP_MENU "Hardware : $G_HW_MODEL_DESCRIPTION \nCurrent : HDMI: $display_output_text | VPU: $display_vpu_text \n Memory : $gpu_mem_current MB GPU | $ram_mem_current MB RAM \n NB: GPU/RAM figures require a reboot after a change is made." if (( $? == 0 )); then REBOOT_REQUIRED=1 TARGETMENUID=6 # Return to this menu case "$G_WHIP_RETURNED_VALUE" in 'Headless') /DietPi/dietpi/func/dietpi-set_hardware headless 1 ;; 'Server') /DietPi/dietpi/func/dietpi-set_hardware headless 0 G_CONFIG_INJECT 'setenv vpu ' 'setenv vpu "0"' /DietPi/boot.ini ;; 'Desktop') /DietPi/dietpi/func/dietpi-set_hardware headless 0 ;; esac fi # Odroid C2 elif (( $G_HW_MODEL == 12 )); then # Odroid HDMI/headless extra data local display_output_enabled=$(grep -ci -m1 '^setenv nographics "0"' /DietPi/boot.ini) local display_output_text='[On]' (( $display_output_enabled )) || display_output_text='[Off]' G_WHIP_MENU_ARRAY=( 'Headless' 'HDMI: Disabled | VPU: Disabled | +300MB RAM' 'Default' 'HDMI: Enabled | VPU: Enabled | -300MB RAM' ) G_WHIP_MENU "Hardware : $G_HW_MODEL_DESCRIPTION \nCurrent : HDMI: $display_output_text | VPU: $display_output_text \n Memory : $gpu_mem_current MB GPU | $ram_mem_current MB RAM \n NB: GPU/RAM figures require a reboot after a change is made." if (( $? == 0 )); then REBOOT_REQUIRED=1 TARGETMENUID=6 # Return to this menu case "$G_WHIP_RETURNED_VALUE" in 'Headless') /DietPi/dietpi/func/dietpi-set_hardware headless 1 ;; 'Default') /DietPi/dietpi/func/dietpi-set_hardware headless 0 ;; esac fi else Info_HW_OptionNotSupported fi } # TARGETMENUID=7 Menu_LanguageOptions(){ TARGETMENUID=0 local locale_current=$(grep -m1 '^[[:blank:]]*AUTO_SETUP_LOCALE=' /DietPi/dietpi.txt | sed 's/^[^=]*=//') G_WHIP_MENU_ARRAY=( 'Locale' ": [$locale_current]" 'Timezone' ": [$( /tmp/available_locale G_WHIP_MENU_ARRAY=() local index=0 # convert for whiptail 0-1=1st option 2-3=2nd while read line do G_WHIP_MENU_ARRAY[$index]=$line ((index++)) G_WHIP_MENU_ARRAY[$index]='' ((index++)) done < /tmp/available_locale rm /tmp/available_locale G_WHIP_DEFAULT_ITEM=$locale_current if G_WHIP_MENU 'Please select a system locale. DietPi will automatically apply this as the default locale:'; then /DietPi/dietpi/func/dietpi-set_software locale "$G_WHIP_RETURNED_VALUE" fi ;; 'Timezone') REBOOT_REQUIRED=1 dpkg-reconfigure tzdata ;; 'Keyboard') REBOOT_REQUIRED=1 G_WHIP_MSG 'NB: A keyboard must be physically plugged into the system, before its configuration can be changed.\n\nIf a keyboard is plugged in, please ignore this message. If not, plug one in ;)' dpkg-reconfigure keyboard-configuration invoke-rc.d keyboard-setup start ;; esac fi } NET_RX_BYTE=0 NET_TX_BYTE=0 NET_RX_MB='Unknown' NET_TX_MB='Unknown' # $1 = device+index Net_Update_UsageStats(){ local input=$1 NET_RX_BYTE=0 NET_TX_BYTE=0 NET_RX_MB='N/A' NET_TX_MB='N/A' if [[ -f /sys/class/net/$input/statistics/rx_bytes && -f /sys/class/net/$input/statistics/tx_bytes ]]; then NET_RX_BYTE=$( /dev/null ifdown wlan$WIFI_DEV_INDEX --force &> /dev/null # Kill dhclient killall dhclient &> /dev/null # Flush, not viable to handle this if change of IP, requires a detect of SSH loss/ip change, then exit script. # - ip addr flush dev eth$ETH_DEV_INDEX &> /dev/null # - ip addr flush dev wlan$WIFI_DEV_INDEX &> /dev/null # Restart Networking G_DIETPI-NOTIFY 2 'Restarting network, please wait...' systemctl daemon-reload # Manually bring up adapters (( $ETH_DISABLED == 0 )) && ifup eth$ETH_DEV_INDEX --force (( $WIFI_DISABLED == 0 )) && ifup wlan$WIFI_DEV_INDEX --force # Restart all services (required for hotspot) /DietPi/dietpi/dietpi-services start # - Add a little delay to ensure all network device data are updated (eg: SSID current takes a little longer) G_DIETPI-NOTIFY 2 'Reloading networking data, please wait...' sleep 2 # Update network data Network_GetData G_DIETPI-NOTIFY 0 'Network restarted' if ( (( $ETH_MODE_TARGET == 0 )) && [[ $ETH_IP != $ETH_IP_STATIC ]] ) || ( (( $WIFI_MODE_TARGET == 0 )) && [[ $WIFI_IP != $WIFI_IP_STATIC ]] ); then G_WHIP_MSG "IP STATIC address change detected. A reboot is required to apply the new IP.\n\nPlease reboot the system." REBOOT_REQUIRED=1 fi } Network_ApplyChanges(){ # Eth local eth_enabled_text='' (( $ETH_DISABLED )) && eth_enabled_text='#' local eth_dhcp_static_text='dhcp' local eth_dns_text='#' if (( $ETH_MODE_TARGET == 0 )); then eth_dhcp_static_text='static' eth_dns_text='' ETH_IP=$ETH_IP_STATIC ETH_GATEWAY=$ETH_GATEWAY_STATIC ETH_MASK=$ETH_MASK_STATIC ETH_DNS=$ETH_DNS_STATIC fi # WiFi local wifi_enabled_text='' (( $WIFI_DISABLED )) && wifi_enabled_text='#' local wifi_dhcp_static_text='dhcp' local wifi_dns_text='#' if (( $WIFI_MODE_TARGET == 0 )); then wifi_dhcp_static_text='static' wifi_dns_text='' WIFI_IP=$WIFI_IP_STATIC WIFI_GATEWAY=$WIFI_GATEWAY_STATIC WIFI_MASK=$WIFI_MASK_STATIC WIFI_DNS=$WIFI_DNS_STATIC fi cat << _EOF_ > /etc/network/interfaces # Location: /etc/network/interfaces # Please modify network settings via: dietpi-config # Or create your own drop-ins in: /etc/network/interfaces.d/ # Drop-in configs source interfaces.d/* # Local auto lo iface lo inet loopback # Ethernet ${eth_enabled_text}allow-hotplug eth$ETH_DEV_INDEX iface eth$ETH_DEV_INDEX inet $eth_dhcp_static_text address $ETH_IP netmask $ETH_MASK gateway $ETH_GATEWAY ${eth_dns_text}dns-nameservers $ETH_DNS # WiFi ${wifi_enabled_text}allow-hotplug wlan$WIFI_DEV_INDEX iface wlan$WIFI_DEV_INDEX inet $wifi_dhcp_static_text address $WIFI_IP netmask $WIFI_MASK gateway $WIFI_GATEWAY ${wifi_dns_text}dns-nameservers $WIFI_DNS wireless-power off wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf _EOF_ # - Additional settings/changes, required for hotspot mode if (( $WIFI_HOTSPOT )); then # - Remove all entries below wlan, so we can recreate them. sed -i '/allow-hotplug wlan/q0' /etc/network/interfaces cat << _EOF_ >> /etc/network/interfaces iface wlan$WIFI_DEV_INDEX inet static address 192.168.42.1 netmask 255.255.255.0 #gateway 192.168.0.1 wireless-power off #dns-nameservers 8.8.8.8 8.8.4.4 # IP tables up iptables-restore < /etc/iptables.ipv4.nat _EOF_ fi # - Remove wireless-power setting, if not supported by adapter/firmware iwconfig wlan$WIFI_DEV_INDEX power off &> /dev/null || sed -i '/^wireless-power/d' /etc/network/interfaces # - Update WiFi db/wpa_supplicant /DietPi/dietpi/func/dietpi-wifidb 1 # Update Current Mode for network restart ETH_MODE=$ETH_MODE_TARGET WIFI_MODE=$WIFI_MODE_TARGET # Restart net Network_Restart } Change_StaticIp(){ # Ethernet if (( $1 == 0 )); then G_WHIP_DEFAULT_ITEM=$ETH_IP_STATIC G_WHIP_INPUTBOX 'Please enter a new static IP address' && ETH_IP_STATIC=$G_WHIP_RETURNED_VALUE # WiFi elif (( $1 == 1 )); then G_WHIP_DEFAULT_ITEM=$WIFI_IP_STATIC G_WHIP_INPUTBOX 'Please enter a new static IP address' && WIFI_IP_STATIC=$G_WHIP_RETURNED_VALUE fi } Change_StaticGateway(){ # Ethernet if (( $1 == 0 )); then G_WHIP_DEFAULT_ITEM=$ETH_GATEWAY_STATIC G_WHIP_INPUTBOX 'Please enter a new static Gateway address' && ETH_GATEWAY_STATIC=$G_WHIP_RETURNED_VALUE # WiFi elif (( $1 == 1 )); then G_WHIP_DEFAULT_ITEM=$WIFI_GATEWAY_STATIC G_WHIP_INPUTBOX 'Please enter a new static Gateway address' && WIFI_GATEWAY_STATIC=$G_WHIP_RETURNED_VALUE fi } Change_StaticMask(){ # Ethernet if (( $1 == 0 )); then G_WHIP_DEFAULT_ITEM=$ETH_MASK_STATIC G_WHIP_INPUTBOX 'Please enter a new static Mask address' && ETH_MASK_STATIC=$G_WHIP_RETURNED_VALUE # WiFi elif (( $1 == 1 )); then G_WHIP_DEFAULT_ITEM=$WIFI_MASK_STATIC G_WHIP_INPUTBOX 'Please enter a new static Mask address' && WIFI_MASK_STATIC=$G_WHIP_RETURNED_VALUE fi } Change_StaticDns(){ # $1 = Adapater type | 0=Eth, 1=WiFi # Store current into var local current_value=0 # - Ethernet if (( $1 == 0 )); then current_value=$ETH_DNS_STATIC # - WiFi elif (( $1 == 1 )); then current_value=$WIFI_DNS_STATIC fi local return_value=$current_value # Create Menu List for Whiptail G_WHIP_MENU_ARRAY=( 'Custom' 'Manually enter your DNS server' '8.8.8.8 8.8.4.4' ': Google' '208.67.222.222 208.67.220.220' ': OpenDNS' '209.244.0.3 209.244.0.4' ': Level3' '216.146.35.35 216.146.36.36' ': Dyn' '37.235.1.174 37.235.1.177' ': FreeDNS' '64.6.64.6 64.6.65.6' ': Verisign' '84.200.69.80 84.200.70.40' ': DNS Watch' '1.1.1.1 1.0.0.1' ': Cloudflare' ) G_WHIP_DEFAULT_ITEM=$current_value if G_WHIP_MENU 'Please select a DNS server, or choose custom for manual entry.'; then case $G_WHIP_RETURNED_VALUE in 'Custom') G_WHIP_DEFAULT_ITEM=$current_value G_WHIP_INPUTBOX 'Please enter a new DNS server address\n - 2 maximum, seperated by a space.\n - eg: 8.8.8.8 8.8.4.4' (( $? )) || return_value=$G_WHIP_RETURNED_VALUE ;; *) return_value=$G_WHIP_RETURNED_VALUE ;; esac fi # Apply new value # - Ethernet if (( $1 == 0 )); then ETH_DNS_STATIC=$return_value # - WiFi elif (( $1 == 1 )); then WIFI_DNS_STATIC=$return_value fi } Change_WifiCountryCode(){ local wifi_country_code_target=$WIFI_COUNTRYCODE G_WHIP_MENU_ARRAY=( 'GB' 'Europe / Great Britain' 'US' 'United States' 'JP' 'Japan' 'CN' 'China' 'Manual' 'Enter a custom country code' ) G_WHIP_DEFAULT_ITEM=$WIFI_COUNTRYCODE if G_WHIP_MENU 'Please select a country, to enable WiFi channels and power ratings allowed in your country.'; then if [[ $G_WHIP_RETURNED_VALUE == 'Manual' ]]; then G_WHIP_DEFAULT_ITEM=$WIFI_COUNTRYCODE G_WHIP_INPUTBOX 'Please enter a 2 character country code: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2' || return [[ $G_WHIP_RETURNED_VALUE == [[:upper:]][[:upper:]] ]] || { G_WHIP_MSG "[ERROR] Invalid country code ($G_WHIP_RETURNED_VALUE). Aborting..."; return; } fi wifi_country_code_target=$G_WHIP_RETURNED_VALUE /DietPi/dietpi/func/dietpi-set_hardware wificountrycode "$wifi_country_code_target" # - Restart networking Network_Restart # - Additional fallback for (older kernel?) devices that fail with wpa_supplicant.conf https://github.com/MichaIng/DietPi/issues/838 # NB: Requires adapter up... hence, not in dietpi-set_hardware iw reg set $wifi_country_code_target # - Check if country code was successfully applied # Wait a bid until setting got applied sleep 0.1 WIFI_COUNTRYCODE=$(iw reg get | mawk '/country/ {print $2;exit}' | tr -d ':') if [[ $WIFI_COUNTRYCODE != $wifi_country_code_target ]]; then G_WHIP_MSG "Country code ($wifi_country_code_target) could not been applied. Please check the country code and try again.\n\nIf problems persist, this may be a limitation with the driver/chipset." fi fi } Wifi_Reconnect(){ G_WHIP_YESNO 'WiFi will connect to the strongest configured SSID that is secure, with an open SSID being the last priority.\n\nSave all changes and restart networking?\n\nNB: All WiFi connections will be dropped!' (( $? == 0 )) && Network_ApplyChanges } Ethernet_Reconnect(){ if G_WHIP_YESNO 'Do you wish to apply settings and reconnect network now? \n\n(NOTICE) All Ethernet connections will be dropped!'; then printf '\ec' # clear current terminal screen echo 'Reconnecting Ethernet , please wait...' Network_ApplyChanges fi } INTERNET_TEST_STATE=0 # 0=not tested, 1=failed, 2=online INTERNET_TEST_URL='https://google.com' Network_GetData(){ # Update DietPi system network details /DietPi/dietpi/func/obtain_network_details # Copy /etc/network/interfaces to /tmp (tmpfs) and pull data from it. cp /etc/network/interfaces /tmp/net_interfaces # Reset ETH_IP_STATIC=$(mawk '/address / {print $2;exit}' /tmp/net_interfaces) ETH_GATEWAY_STATIC=$(mawk '/gateway / {print $2;exit}' /tmp/net_interfaces) ETH_MASK_STATIC=$(mawk '/netmask / {print $2;exit}' /tmp/net_interfaces) ETH_DNS_STATIC=$(mawk '/dns-nameservers / {print $2,$3;exit}' /tmp/net_interfaces) # Remove trailing space in case of single nameserver, due to mawk '{print $2,$3}' ETH_DNS_STATIC=${ETH_DNS_STATIC%[[:blank:]]} ETH_DEV_INDEX=$(sed -n 1p /DietPi/dietpi/.network) ETH_DISABLED=$(grep -ci -m1 "#allow-hotplug eth$ETH_DEV_INDEX" /tmp/net_interfaces) ETH_HARDWARE=0 ETH_CONNECTED=0 ETH_IP='0.0.0.0' ETH_GATEWAY='0.0.0.0' ETH_MASK='0.0.0.0' ETH_DNS='0.0.0.0' ETH_MODE=1 ETH_MODE_TARGET=$ETH_MODE WIFI_IP_STATIC=$(mawk '/address / {print $2}' /tmp/net_interfaces | sed -n 2p) WIFI_GATEWAY_STATIC=$(mawk '/gateway / {print $2}' /tmp/net_interfaces | sed -n 2p) WIFI_MASK_STATIC=$(mawk '/netmask / {print $2}' /tmp/net_interfaces | sed -n 2p) WIFI_DNS_STATIC=$(mawk '/dns-nameservers / {print $2,$3}' /tmp/net_interfaces | sed -n 2p) # Remove trailing space in case of single nameserver, due to mawk '{print $2,$3}' WIFI_DNS_STATIC=${WIFI_DNS_STATIC%[[:blank:]]} WIFI_DEV_INDEX=$(sed -n 2p /DietPi/dietpi/.network) WIFI_DISABLED=$(grep -ci -m1 "#allow-hotplug wlan$WIFI_DEV_INDEX" /tmp/net_interfaces) WIFI_HARDWARE=0 WIFI_CONNECTED=0 WIFI_IP='0.0.0.0' WIFI_GATEWAY='0.0.0.0' WIFI_MASK='0.0.0.0' WIFI_DNS='0.0.0.0' WIFI_MODE=1 WIFI_MODE_TARGET=$WIFI_MODE command -v iwgetid &> /dev/null && WIFI_SSID_CURRENT=$(iwgetid -r) [[ ! $WIFI_SSID_CURRENT ]] && WIFI_SSID_CURRENT='Disconnected / No SSID' WIFI_CRED_INDEX=0 # Which index of SSID/KEY etc we are editing # Get extra WiFi stats WIFI_BITRATE=0 WIFI_SIGNALSTRENGTH=0 # - Hotspot enabled? WIFI_HOTSPOT=0 [[ -f /usr/sbin/hostapd ]] && WIFI_HOTSPOT=1 WIFI_COUNTRYCODE='GB' # - Prevent "nl80211 not found" message, when running this command with cfg80211 module disabled. command -v iw &> /dev/null && WIFI_COUNTRYCODE=$(iw reg get | mawk '/country/ {print $2;exit}' | tr -d ':') # Convert CIDR integer to net mask, e.g. "192.168.0.100/24" (take "24") to "255.255.255.0" cidr2mask() { local i mask='' local full_octets=$(( $1 / 8 )) local partial_octet=$(( $1%8 )) for i in {0..3}; do if (( $i < $full_octets )); then mask+=255 elif (( $i == $full_octets )); then mask+=$(( 256 - 2 ** ( 8 - $partial_octet ) )) else mask+=0 fi (( $i < 3 )) && mask+=. done echo $mask } # Eth if [[ -d /sys/class/net/eth$ETH_DEV_INDEX ]]; then # Hardware ETH_HARDWARE=1 # Static or DHCP? ETH_MODE=$(grep -ci -m1 "iface eth$ETH_DEV_INDEX inet dhcp" /tmp/net_interfaces) ETH_MODE_TARGET=$ETH_MODE # Connected and Valid IP? ETH_CONNECTED=$(ip -o r l dev eth$ETH_DEV_INDEX | grep -vcim1 '[[:blank:]]linkdown') # Enabled and Connected if (( $ETH_DISABLED == 0 && $ETH_CONNECTED == 1 )); then ETH_IP=$(ip a s eth$ETH_DEV_INDEX | grep -m1 '^[[:blank:]]*inet ' | mawk '{print $2}' | sed 's|/.*$||') ETH_GATEWAY=$(ip r | mawk '/default/ {print $3;exit}') ETH_MASK=$(cidr2mask $(ip a s eth$ETH_DEV_INDEX | grep -m1 '^[[:blank:]]*inet ' | mawk '{print $2}' | sed 's|^.*/||')) ETH_DNS=$(mawk '/nameserver/ {print $2;exit}' /etc/resolv.conf) fi fi # WiFi if [[ -d /sys/class/net/wlan$WIFI_DEV_INDEX ]]; then # Hardware WIFI_HARDWARE=1 # Static or DHCP? WIFI_MODE=$(grep -ci -m1 "iface wlan$WIFI_DEV_INDEX inet dhcp" /tmp/net_interfaces) WIFI_MODE_TARGET=$WIFI_MODE # Connected and Valid IP? WIFI_CONNECTED=$(ip -o r l dev wlan$ETH_DEV_INDEX | grep -vcim1 '[[:blank:]]linkdown') # Enabled and Connected if (( $WIFI_DISABLED == 0 && $WIFI_CONNECTED == 1 )); then WIFI_IP=$(ip a s wlan$WIFI_DEV_INDEX | grep -m1 '^[[:blank:]]*inet ' | mawk '{print $2}' | sed 's|/.*$||') WIFI_GATEWAY=$(ip r | mawk '/default/ {print $3;exit}') WIFI_MASK=$(cidr2mask $(ip a s wlan$WIFI_DEV_INDEX | grep -m1 '^[[:blank:]]*inet ' | mawk '{print $2}' | sed 's|^.*/||')) WIFI_DNS=$(mawk '/nameserver/ {print $2;exit}' /etc/resolv.conf) # Get extra WiFi stats WIFI_BITRATE=$(iwconfig wlan$WIFI_DEV_INDEX | mawk '/Bit Rate/ {print $2;exit}' | sed 's/Rate[:=]//g') WIFI_SIGNALSTRENGTH=$(iwconfig wlan$WIFI_DEV_INDEX | mawk '/Signal level=/ {print $4;exit}' | sed 's/level=//g' | cut -f1 -d "/") # - try and detect if this is dBm (contains -) or % if disable_error=1 G_CHECK_VALIDINT "$WIFI_SIGNALSTRENGTH" -500 -1; then WIFI_SIGNALSTRENGTH="$WIFI_SIGNALSTRENGTH dBm" else WIFI_SIGNALSTRENGTH="$WIFI_SIGNALSTRENGTH %" fi fi fi # Cleanup tmp [[ -f /tmp/net_interfaces ]] && rm /tmp/net_interfaces } # TARGETMENUID=8 Menu_NetworkAdapters(){ # Check Network Network_GetData # Obtain enabled/disabled status local eth_disabled_text='[On]' (( $ETH_DISABLED )) && eth_disabled_text='[Off]' local wlan_disabled_text='[On]' (( $WIFI_DISABLED )) && wlan_disabled_text='[Off]' # Obtain Hardware Status local eth_hardware_text='Available' (( $ETH_HARDWARE )) || eth_hardware_text='Not Found' local wlan_hardware_text='Available' (( $WIFI_HARDWARE )) || wlan_hardware_text='Not Found' # Obtain Connected/Carrier Status local eth_connected_text='Disconnected' (( $ETH_CONNECTED )) && eth_connected_text='Connected' local wlan_connected_text='Disconnected' if (( $WIFI_CONNECTED )); then (( $WIFI_HOTSPOT )) && wlan_connected_text='WiFi Hotspot Mode' || wlan_connected_text='Connected' fi # Internet Connection Status local Internet_connected_text='Run internet connection test' if (( $INTERNET_TEST_STATE == 2 )); then Internet_connected_text='[Success] | Online' elif (( $INTERNET_TEST_STATE == 1 )); then Internet_connected_text='[Failure] | Offine' fi # Proxy settings: Scrapes $http_proxy, otherwise obtains current values stored in dietpi.txt Load_Proxy_Vars local proxy_state_text='[Off]' (( $PROXY_ENABLED )) && proxy_state_text="[On] | $PROXY_ADDRESS:$PROXY_PORT" G_WHIP_MENU_ARRAY=('' '●─ Adapter Options ') G_WHIP_MENU_ARRAY+=('Ethernet' ": $eth_hardware_text | $eth_disabled_text | $eth_connected_text") G_WHIP_MENU_ARRAY+=('WiFi' ": $wlan_hardware_text | $wlan_disabled_text | $wlan_connected_text") # - Onboard WiFi # RPi 3/Zero W if (( $HW_ONBOARD_WIFI )); then local onboard_wifi_enabled=1 if [[ -f '/etc/modprobe.d/disable_wifi_rpi3_onboard.conf' ]]; then onboard_wifi_enabled=0 G_WHIP_MENU_ARRAY+=('Onboard WiFi' ': [Off]') else G_WHIP_MENU_ARRAY+=('Onboard WiFi' ': [On]') fi fi G_WHIP_MENU_ARRAY+=('' '●─ Additional Options ') # IPv6 local ipv6_status_text='[WARNING] Not supported or disabled on kernel level!' if [[ -d '/proc/sys/net/ipv6' ]]; then local ipv6_enabled=0 ipv6_status_text='[Off]' if [[ $(ip -6 a) ]]; then ipv6_enabled=1 ipv6_status_text='[On]' fi G_WHIP_MENU_ARRAY+=('IPv6' ": $ipv6_status_text") # Only offer to prefer IPv4, if IPv6 is enabled if (( $ipv6_enabled )); then local ipv4_preferred=0 local ipv4_status_text='[Off]' if [[ -f /etc/apt/apt.conf.d/99-dietpi-force-ipv4 ]]; then ipv4_preferred=1 ipv4_status_text='[On]' fi G_WHIP_MENU_ARRAY+=('Prefer IPv4' ": $ipv4_status_text") fi fi G_WHIP_MENU_ARRAY+=('Proxy' ": $proxy_state_text") G_WHIP_MENU_ARRAY+=('Test' ": $Internet_connected_text") if G_WHIP_MENU 'Please select an option to change:'; then case "$G_WHIP_RETURNED_VALUE" in 'Onboard WiFi') if (( $onboard_wifi_enabled )); then /DietPi/dietpi/func/dietpi-set_hardware wifimodules onboard_disable else /DietPi/dietpi/func/dietpi-set_hardware wifimodules onboard_enable fi G_WHIP_MSG 'Onboard WiFi modules setting applied\n\nNB: A reboot is required for the changes to take effect.' ;; 'IPv6') if (( $ipv6_enabled )); then /DietPi/dietpi/func/dietpi-set_hardware enableipv6 0 else /DietPi/dietpi/func/dietpi-set_hardware enableipv6 1 fi ;; 'Prefer IPv4') if (( $ipv4_preferred )); then /DietPi/dietpi/func/dietpi-set_hardware preferipv4 0 else /DietPi/dietpi/func/dietpi-set_hardware preferipv4 1 fi ;; 'Ethernet') # No hardware found if (( ! $ETH_HARDWARE )); then G_WHIP_MSG 'No Ethernet hardware was detected on your device.' # Disabled elif (( $ETH_DISABLED )); then if G_WHIP_YESNO 'Ethernet must be enabled before settings can be changed.\n Would you like to enable Ethernet now?\n - (NOTICE) Connections may drop!'; then ETH_DISABLED=0 Network_ApplyChanges TARGETMENUID=9 fi else TARGETMENUID=9 fi ;; 'WiFi') # Disabled | Offer chance to enable (also enables WiFi modules) if (( $WIFI_DISABLED )); then if G_WHIP_YESNO 'WiFi must be enabled before settings can be changed.\n Would you like to enable WiFi now? \n - (NOTICE) Connections may drop!'; then WIFI_DISABLED=0 Network_ApplyChanges fi # No hardware found elif (( ! $WIFI_HARDWARE )); then if G_WHIP_YESNO 'No supported WiFi hardware was found.\n Would you like to disable WiFi? \n - (NOTICE) Connections may drop!'; then WIFI_DISABLED=1 Network_ApplyChanges fi else TARGETMENUID=10 fi ;; 'Test') G_WHIP_DEFAULT_ITEM=$INTERNET_TEST_URL if G_WHIP_INPUTBOX 'Please enter a URL address to test (eg: https://dietpi.com)'; then INTERNET_TEST_URL=$G_WHIP_RETURNED_VALUE INTERNET_TEST_STATE=0 # Not tested G_ERROR_HANDLER_INFO_ONLY=1 G_CHECK_URL "$INTERNET_TEST_URL" if (( $G_ERROR_HANDLER_EXITCODE_RETURN == 0 )); then INTERNET_TEST_STATE=2 # Online else INTERNET_TEST_STATE=1 # Failed fi fi ;; 'Proxy') TARGETMENUID=17 ;; esac # Cancel else TARGETMENUID=0 # Return to main menu # Exit DietPi-Config on back to previous menu? if (( $EXITONBACK == 1 )); then TARGETMENUID=8 # Return to this menu Menu_Exit fi fi } # TARGETMENUID=9 Menu_NetworkAdapters_Ethernet(){ TARGETMENUID=8 # - Get current Mode details local mode_current='DHCP' (( $ETH_MODE == 0 )) && mode_current='STATIC' # - Target Details local mode_target='DHCP' (( $ETH_MODE_TARGET == 0 )) && mode_target='STATIC' G_WHIP_MENU_ARRAY=('' '●─ DHCP/STATIC IP ') G_WHIP_MENU_ARRAY+=('Change Mode' ": [$mode_target]") # - show static options if (( $ETH_MODE_TARGET == 0 )); then G_WHIP_MENU_ARRAY+=('Copy' ': Copy current address to "Static"') G_WHIP_MENU_ARRAY+=('Static Ip' ": [$ETH_IP_STATIC]") G_WHIP_MENU_ARRAY+=('Static Mask' ": [$ETH_MASK_STATIC]") G_WHIP_MENU_ARRAY+=('Static Gateway' ": [$ETH_GATEWAY_STATIC]") G_WHIP_MENU_ARRAY+=('Static DNS' ": [$ETH_DNS_STATIC]") fi G_WHIP_MENU_ARRAY+=('' '●─ Additional Options ') G_WHIP_MENU_ARRAY+=('Disable' ': Disable Ethernet adapter') G_WHIP_MENU_ARRAY+=('' '●─ Apply ') G_WHIP_MENU_ARRAY+=('Apply' ': Save all changes and restart networking') Net_Update_UsageStats eth$ETH_DEV_INDEX G_WHIP_DEFAULT_ITEM=$WHIP_SELECTION_PREVIOUS G_WHIP_MENU "Ethernet Details:\nUsage : Sent = $NET_TX_MB | Recieved = $NET_RX_MB\nAddress : IP = $ETH_IP | Mask = $ETH_MASK | Gateway = $ETH_GATEWAY | DNS = $ETH_DNS" if (( $? == 0 )); then TARGETMENUID=9 # Return to this menu WHIP_SELECTION_PREVIOUS=$G_WHIP_RETURNED_VALUE case "$G_WHIP_RETURNED_VALUE" in 'Change Mode') ((ETH_MODE_TARGET++)) (( $ETH_MODE_TARGET >= 2 )) && ETH_MODE_TARGET=0 ;; 'Disable') G_WHIP_YESNO 'Would you like to disable the Ethernet adapter?\n - (NOTICE) All Ethernet connections will be dropped.' if (( $? == 0 )); then ETH_DISABLED=1 Network_ApplyChanges TARGETMENUID=8 fi ;; 'Apply') Ethernet_Reconnect ;; 'Copy') Network_ETH_CopyCurrentToStatic ;; 'Static Ip') Change_StaticIp 0 ;; 'Static Gateway') Change_StaticGateway 0 ;; 'Static Mask') Change_StaticMask 0 ;; 'Static DNS') Change_StaticDns 0 ;; esac fi } HOTSPOT_SSID='' HOTSPOT_CHANNEL='' HOTSPOT_KEY='' WiFi_Monitor_Disable(){ systemctl stop dietpi-wifi-monitor systemctl disable dietpi-wifi-monitor } WiFi_Monitor_Enable(){ systemctl enable dietpi-wifi-monitor G_RUN_CMD systemctl start dietpi-wifi-monitor } # TARGETMENUID=10 Menu_NetworkAdapters_Wifi(){ TARGETMENUID=8 Net_Update_UsageStats wlan$ETH_DEV_INDEX local whip_options_total=0 local description_text="WiFi Details:\nUsage : Sent = $NET_TX_MB | Recieved = $NET_RX_MB\n" G_WHIP_MENU_ARRAY=('' '●─ Basic Options ') # WiFi Hotspot Menu if (( $WIFI_HOTSPOT )); then # - Load current details into global vars, once. if [[ ! $HOTSPOT_SSID ]]; then HOTSPOT_SSID=$(grep -m1 '^[[:blank:]]*ssid=' /etc/hostapd/hostapd.conf | sed 's/^[^=]*=//') HOTSPOT_CHANNEL=$(grep -m1 '^[[:blank:]]*channel=' /etc/hostapd/hostapd.conf | sed 's/^[^=]*=//') HOTSPOT_KEY=$(grep -m1 '^[[:blank:]]*wpa_passphrase=' /etc/hostapd/hostapd.conf | sed 's/^[^=]*=//') fi # - N enabled? local hotspot_n_enabled=0 local hotspot_n_text='Disabled' if grep -q '^ieee80211n=1' /etc/hostapd/hostapd.conf; then hotspot_n_enabled=1 hotspot_n_text='Enabled' fi # - Toggle local hotspot_active_state=$(systemctl is-active hostapd | grep -ci -m1 '^active' ) local hotspot_status_text='Status : Offline' local hotspot_active_state_text='[Disabled] | Select to turn on hotspot' if (( $hotspot_active_state )); then hotspot_status_text+='Status : Online' hotspot_active_state_text='[Enabled] | Select to turn off hotspot' fi G_WHIP_MENU_ARRAY+=('SSID' ": [$HOTSPOT_SSID]") G_WHIP_MENU_ARRAY+=('Channel' ": [$HOTSPOT_CHANNEL]") G_WHIP_MENU_ARRAY+=('Key' ": [$HOTSPOT_KEY]") G_WHIP_MENU_ARRAY+=('802.11 N' ": [$hotspot_n_text]") description_text+=$hotspot_status_text # WiFi Menu else # - Get current Mode details local mode_current='DHCP' (( $WIFI_MODE )) || mode_current='STATIC' # - Target Details local mode_target='DHCP' (( $WIFI_MODE_TARGET )) || mode_target='STATIC' G_WHIP_MENU_ARRAY+=('Scan' ': Scan and configure SSID') if (( $WIFI_CONNECTED )) || systemctl is-active dietpi-wifi-monitor | grep -qi '^active'; then local wifi_auto_reconnect_text='[Off]' WIFI_AUTO_RECONNECT_ACTIVE=0 if systemctl is-active dietpi-wifi-monitor | grep -qi '^active'; then WIFI_AUTO_RECONNECT_ACTIVE=1 wifi_auto_reconnect_text='[On]' fi G_WHIP_MENU_ARRAY+=('Auto Reconnect' ": $wifi_auto_reconnect_text") fi G_WHIP_MENU_ARRAY+=('' '●─ DHCP/STATIC IP ') G_WHIP_MENU_ARRAY+=('Change Mode' ": [$mode_target]") # - show static options if (( $WIFI_MODE_TARGET == 0 )); then G_WHIP_MENU_ARRAY+=('Copy' ': Copy current address to "Static"') G_WHIP_MENU_ARRAY+=('Static Ip' ": [$WIFI_IP_STATIC]") G_WHIP_MENU_ARRAY+=('Static Mask' ": [$WIFI_MASK_STATIC]") G_WHIP_MENU_ARRAY+=('Static Gateway' ": [$WIFI_GATEWAY_STATIC]") G_WHIP_MENU_ARRAY+=('Static DNS' ": [$WIFI_DNS_STATIC]") fi description_text+="SSID : $WIFI_SSID_CURRENT | $WIFI_BITRATE Mbit | Strength: $WIFI_SIGNALSTRENGTH\nAddress : IP = $WIFI_IP | Mask = $WIFI_MASK | Gateway = $WIFI_GATEWAY | DNS = $WIFI_DNS" fi G_WHIP_MENU_ARRAY+=('' '●─ Additional Options ') # - Unset country code? if [[ $WIFI_COUNTRYCODE == '00' ]]; then G_WHIP_MENU_ARRAY+=('Country' ": [$WIFI_COUNTRYCODE] (Not set, please configure)") else G_WHIP_MENU_ARRAY+=('Country' ": [$WIFI_COUNTRYCODE]") fi G_WHIP_MENU_ARRAY+=('' '●─ Toggle State ') if (( $WIFI_HOTSPOT )); then G_WHIP_MENU_ARRAY+=('State' ": $hotspot_active_state_text") else G_WHIP_MENU_ARRAY+=('Disable' ': Disable WiFi adapter') fi G_WHIP_MENU_ARRAY+=('' '●─ Apply ') G_WHIP_MENU_ARRAY+=('Apply' ': Save all changes and restart networking') G_WHIP_DEFAULT_ITEM=$WHIP_SELECTION_PREVIOUS if G_WHIP_MENU "$description_text"; then TARGETMENUID=10 # Return to this menu WHIP_SELECTION_PREVIOUS=$G_WHIP_RETURNED_VALUE case "$G_WHIP_RETURNED_VALUE" in 'Auto Reconnect') if (( $WIFI_AUTO_RECONNECT_ACTIVE )); then WiFi_Monitor_Disable else WiFi_Monitor_Enable fi ;; 'Key') G_WHIP_DEFAULT_ITEM=$HOTSPOT_KEY G_WHIP_INPUTBOX 'Please enter a key/password for the WiFi hotspot\n - NB: Minimum of 8 characters' (( $? == 0 )) && HOTSPOT_KEY=$G_WHIP_RETURNED_VALUE ;; 'SSID') G_WHIP_DEFAULT_ITEM=$HOTSPOT_SSID G_WHIP_INPUTBOX 'Please enter a SSID for the WiFi hotspot' && HOTSPOT_SSID=$G_WHIP_RETURNED_VALUE ;; 'Channel') #2.4ghz only atm local channel_mhz=2412 local channel_min=1 local channel_max=13 G_WHIP_MENU_ARRAY=() for ((i=$channel_min; i<=$channel_max; i++)) do G_WHIP_MENU_ARRAY+=($i ": $channel_mhz MHz") ((channel_mhz+=5)) done G_WHIP_DEFAULT_ITEM=$HOTSPOT_CHANNEL G_WHIP_MENU 'Please select a WiFi channel for the hotspot.' && HOTSPOT_CHANNEL=$G_WHIP_RETURNED_VALUE ;; '802.11 N') ((hotspot_n_enabled++)) if (( $hotspot_n_enabled >= 2 )); then hotspot_n_enabled=0 fi G_CONFIG_INJECT 'ieee80211n=' "ieee80211n=$hotspot_n_enabled" /etc/hostapd/hostapd.conf ;; 'Country') Change_WifiCountryCode ;; 'Disable') G_WHIP_YESNO 'Would you like to disable the WiFi adapter?\n - (NOTICE) All WiFi connections will be dropped.' if (( $? == 0 )); then WIFI_DISABLED=1 WiFi_Monitor_Disable Network_ApplyChanges TARGETMENUID=8 fi ;; 'Scan') /DietPi/dietpi/func/dietpi-wifidb ;; 'Change Mode') ((WIFI_MODE_TARGET++)) if (( $WIFI_MODE_TARGET >= 2 )); then WIFI_MODE_TARGET=0 G_WHIP_MSG 'Information for STATIC IP:\n\nWhen using STATIC IP, please ensure only 1 SSID entry exists in the "Scan" menu. Else, WiFi will most likely fail, and, the IP conflict committee will be displeased ;)' fi ;; 'Apply') if (( $WIFI_HOTSPOT == 1 )); then # - update dietpi.txt sed -i "/SOFTWARE_WIFI_HOTSPOT_SSID=/c\SOFTWARE_WIFI_HOTSPOT_SSID=$HOTSPOT_SSID" /DietPi/dietpi.txt sed -i "/SOFTWARE_WIFI_HOTSPOT_CHANNEL=/c\SOFTWARE_WIFI_HOTSPOT_CHANNEL=$HOTSPOT_CHANNEL" /DietPi/dietpi.txt sed -i "/SOFTWARE_WIFI_HOTSPOT_KEY=/c\SOFTWARE_WIFI_HOTSPOT_KEY=$HOTSPOT_KEY" /DietPi/dietpi.txt # - update hostapd conf sed -i "/ssid=/c\ssid=$HOTSPOT_SSID" /etc/hostapd/hostapd.conf sed -i "/channel=/c\channel=$HOTSPOT_CHANNEL" /etc/hostapd/hostapd.conf sed -i "/wpa_passphrase=/c\wpa_passphrase=$HOTSPOT_KEY" /etc/hostapd/hostapd.conf # - Apply/Restart network Network_ApplyChanges else Wifi_Reconnect fi ;; 'Copy') Network_WIFI_CopyCurrentToStatic ;; 'Static Ip') Change_StaticIp 1 ;; 'Static Gateway') Change_StaticGateway 1 ;; 'Static Mask') Change_StaticMask 1 ;; 'Static DNS') Change_StaticDns 1 ;; 'State') if (( $hotspot_active_state )); then G_RUN_CMD systemctl stop hostapd else G_RUN_CMD systemctl start hostapd fi ;; esac fi } # TARGETMENUID=11 Menu_Tools(){ TARGETMENUID=0 G_WHIP_MENU_ARRAY=( 'Benchmarks' ': CPU, RAM, LAN and filesystem benchmarks' 'Stress Test' ': CPU Burn and system stability tests (CPU/IO/RAM)' ) if G_WHIP_MENU 'Please select an option:'; then case "$G_WHIP_RETURNED_VALUE" in 'Benchmarks') TARGETMENUID=12 ;; 'Stress Test') TARGETMENUID=15 ;; esac fi } # TARGETMENUID=12 Menu_FilesystemBenchmark(){ TARGETMENUID=11 # - Init/load previous bench results [[ -f '/var/lib/dietpi/dietpi-benchmark/results' ]] || /DietPi/dietpi/func/dietpi-benchmark 0 . /var/lib/dietpi/dietpi-benchmark/results # - Sanity for beta testing. As this value won't exist until re-save of /var/lib/dietpi/dietpi-benchmark/results [[ $BENCH_NET_LAN_SPEED ]] || BENCH_NET_LAN_SPEED='Not Tested' G_WHIP_MENU_ARRAY=( '' '●─ DietPi-Benchmark ' 'DietPi-Benchmark' ': Starts CPU, RAM and IO benchmark suite. Scores can be viewed online.' '' '●─ Additional benchmarks ' 'Custom Filesystem' ': Benchmark IO performance from a selection of mounted devices.' 'Network LAN' ': Benchmark LAN performance using 2 DietPi systems.' ) G_WHIP_DEFAULT_ITEM='DietPi-Benchmark' if G_WHIP_MENU "\ DietPi-Benchmark | https://dietpi.com/survey#benchmark : - CPU Performance : Duration = $BENCH_CPU seconds (lower is faster) - CPU Temp : Idle = ${BENCH_CPU_TEMP_START}'c | Full load = ${BENCH_CPU_TEMP_END}'c - RootFS : Write = $BENCH_ROOTFS_WRITE MB/s | Read = $BENCH_ROOTFS_READ MB/s - RAM : Write = $BENCH_RAM_WRITE MB/s | Read = $BENCH_RAM_READ MB/s Additional benchmarks: - Custom Filesystem : Write = $BENCH_CUSTOMFS_WRITE MB/s | Read = $BENCH_CUSTOMFS_READ MB/s - Network LAN : Transfer rate = $BENCH_NET_LAN_SPEED MB/s"; then TARGETMENUID=12 # Return to this menu case "$G_WHIP_RETURNED_VALUE" in 'DietPi-Benchmark') /DietPi/dietpi/func/dietpi-benchmark 2 ;; 'Network LAN') G_WHIP_MENU_ARRAY=( 'Server' ': Run this device as the server' 'Client' ': Connect to an existing server, to begin the test' ) G_WHIP_MENU 'Please select an option:\n\n - Server: Run a server on the current device. Another system can then use the "Client" option to connect and begin the test.\n\n - Client: Connect to an existing server and begin the test.' if (( $? == 0 )); then if [[ $G_WHIP_RETURNED_VALUE == 'Server' ]]; then /DietPi/dietpi/func/dietpi-benchmark 3 elif [[ $G_WHIP_RETURNED_VALUE == 'Client' ]]; then /DietPi/dietpi/func/dietpi-benchmark 4 fi fi ;; 'Custom Filesystem') /DietPi/dietpi/dietpi-drive_manager 1 local fp_fsbench_custom_mount=$( /dev/null; then G_WHIP_MENU_ARRAY+=('DietPi-JustBoom' ': Launches EQ and MPD audio options menu') fi # - RPi, low power mode (PSU noise ripple reduction): https://github.com/MichaIng/DietPi/issues/757 if (( $G_HW_MODEL < 10 )); then local current_cpu_governor=$(grep -m1 '^[[:blank:]]*CONFIG_CPU_GOVERNOR=' /DietPi/dietpi.txt | sed 's/^[^=]*=//') local hdmi_output=1 grep -qi 'hdmi_ignore_hotplug=1' /DietPi/config.txt && grep -qi 'hdmi_ignore_composite=1' /DietPi/config.txt && hdmi_output=0 local psu_noise_reduction_enabled=0 if [[ $current_cpu_governor == 'powersave' ]] && (( ! $hdmi_output )); then G_WHIP_MENU_ARRAY+=('PSU noise reduction' ': [On]') psu_noise_reduction_enabled=1 else G_WHIP_MENU_ARRAY+=('PSU noise reduction' ': [Off]') fi fi if G_WHIP_MENU 'Please select an option:'; then TARGETMENUID=14 # Return to this menu if [[ $G_WHIP_RETURNED_VALUE == 'PSU noise reduction' ]]; then if (( ! $psu_noise_reduction_enabled )); then G_WHIP_MSG "PSU noise reduction:\n\nThis mode attempts to reduce power consumption on your SBC. In turn, this may reduce PSU inflicted noise, that may degrade audio output quality.\n\nThe following has now been set:\n - CPU gov = Powersave\n - HDMI output = Disabled" G_CONFIG_INJECT 'CONFIG_CPU_GOVERNOR=' 'CONFIG_CPU_GOVERNOR=powersave' /DietPi/dietpi.txt /DietPi/dietpi/func/dietpi-set_cpu /DietPi/dietpi/func/dietpi-set_hardware headless 1 else G_CONFIG_INJECT 'CONFIG_CPU_GOVERNOR=' 'CONFIG_CPU_GOVERNOR=ondemand' /DietPi/dietpi.txt /DietPi/dietpi/func/dietpi-set_cpu /DietPi/dietpi/func/dietpi-set_hardware headless 0 fi REBOOT_REQUIRED=1 elif [[ $G_WHIP_RETURNED_VALUE == 'Soundcard' ]]; then G_WHIP_MENU_ARRAY=() # - Global: # RPi, none disables HDMI as well. if (( $G_HW_MODEL < 10 )); then G_WHIP_MENU_ARRAY+=('none' ': Disables HDMI + 3.5mm Analogue') # NanoPi M2/M3, BPi Pro, OPi Zero elif (( $G_HW_MODEL == 32 || $G_HW_MODEL == 51 || $G_HW_MODEL == 61 || $G_HW_MODEL == 62 )); then G_WHIP_MENU_ARRAY+=('default' ': 3.5mm Analogue') # Native PC/MISC devices | Detect and list available elif (( $G_HW_MODEL == 15 || $G_HW_MODEL == 21 || $G_HW_MODEL == 40 || $G_HW_MODEL == 42 || $G_HW_MODEL == 43 || $G_HW_MODEL == 44 || $G_HW_MODEL == 67 )); then G_WHIP_MENU_ARRAY+=('default' ': HW:0,0') # Install prereqs to allow for detection dpkg-query -s alsa-utils &> /dev/null || /DietPi/dietpi/func/dietpi-set_hardware soundcard default for i in {0..9} do if [[ -f /proc/asound/card$i/id ]]; then for j in {0..9} do if [[ -f /proc/asound/card$i/pcm${j}p/info ]]; then local card_index=$(mawk '/^card:/ {print $2;exit}' /proc/asound/card$i/pcm${j}p/info) local device_index=$(mawk '/^device:/ {print $2;exit}' /proc/asound/card$i/pcm${j}p/info) local card_name=$( /dev/null if (( $STRESS_TEST_MODE == 0 )); then stress -c $(( $G_HW_CPU_CORES * 2 )) -t "$STRESS_TEST_DURATION"s & elif (( $STRESS_TEST_MODE == 1 )); then stress -c $(( $G_HW_CPU_CORES * 2 )) -i $G_HW_CPU_CORES -m $G_HW_CPU_CORES --vm-bytes "$memory_per_thread"M -t "$STRESS_TEST_DURATION"s & elif (( $STRESS_TEST_MODE == 2 )); then stress -c $(( $G_HW_CPU_CORES * 2 )) -i $G_HW_CPU_CORES -m $G_HW_CPU_CORES --vm-bytes "$memory_per_thread"M -d 2 -t "$STRESS_TEST_DURATION"s & fi # - Reset STRESS_TEST_RESULTS_TEMP_MIN=1000 STRESS_TEST_RESULTS_TEMP_MAX=0 # - Check if system supports temp readouts local cpu_supports_temp=0 local cpu_temp=$(G_OBTAIN_CPU_TEMP) disable_error=1 G_CHECK_VALIDINT "$cpu_temp" && cpu_supports_temp=1 # - Loop until stress completed local remaning_time=0 while pgrep 'stress' &> /dev/null do cpu_temp=$(G_OBTAIN_CPU_TEMP) remaning_time=$(( $STRESS_TEST_DURATION + ( $start_time_epoch - $(date +%s) ) )) echo -e "$(date) | $cpu_temp'c | $remaning_time seconds remaining" echo -e "$(date) | $cpu_temp'c" >> "$fp_log" if (( $cpu_supports_temp )); then if (( $cpu_temp > $STRESS_TEST_RESULTS_TEMP_MAX )); then STRESS_TEST_RESULTS_TEMP_MAX=$cpu_temp fi if (( $cpu_temp < $STRESS_TEST_RESULTS_TEMP_MIN )); then STRESS_TEST_RESULTS_TEMP_MIN=$cpu_temp fi fi sleep 1 ((time_since_start++)) done local end_time=$(date) local end_time_epoch=$(date +%s) local duration_seconds=$(( $end_time_epoch - $start_time_epoch )) local output_string=" - Start Time: $start_time - End Time : $end_time - Duration : $duration_seconds seconds - Min Temp : $STRESS_TEST_RESULTS_TEMP_MIN 'c - Max Temp : $STRESS_TEST_RESULTS_TEMP_MAX 'c - log : $fp_log" G_DIETPI-NOTIFY 0 'Stress Test Completed' G_DIETPI-NOTIFY 2 "$output_string" G_WHIP_MSG "Stress test results:\n$output_string" fi fi } # TARGETMENUID=16 Menu_Network_Nas_Misc(){ TARGETMENUID=0 # Update installed software Load_Installed_Software # No-IP Client local noip_installed=0 local noip_status='Not Installed' local noip_menutext='Install No-IP now' if (( ${aSOFTWARE_INSTALL_STATE[67]:=0} == 2 )); then noip_installed=1 noip_status='Offline - Please enter No-IP details' noip_menutext='Enter/Setup No-IP details' # Check if No-IP is running (indicates login details are valid) if pgrep '/usr/local/bin/noip2' &> /dev/null; then noip_status='Online / Active' noip_menutext='Change No-IP details' fi fi # APT mirror local apt_mirror_current=$(grep -m1 '^[[:blank:]]*deb[[:blank:]]' /etc/apt/sources.list | mawk '{print $2}') [[ $apt_mirror_current ]] || apt_mirror_current='Unknown, no string from scrape' # NTP mirror local ntp_mirror_current=$(grep -m1 '^[[:blank:]]*CONFIG_NTP_MIRROR=' /DietPi/dietpi.txt | sed 's/^[^=]*=//') [[ $ntp_mirror_current ]] || ntp_mirror_current='Unknown, no string from scrape' # Network boot wait local boot_wait_for_network=$(grep -m1 '^[[:blank:]]*CONFIG_BOOT_WAIT_FOR_NETWORK=' /DietPi/dietpi.txt | sed 's/^[^=]*=//') local boot_wait_for_network_text='' if (( $boot_wait_for_network == 0 )); then boot_wait_for_network_text+='Off' elif (( $boot_wait_for_network == 1 )); then boot_wait_for_network_text+='10 Seconds MAX (default)' elif (( $boot_wait_for_network == 2 )); then boot_wait_for_network_text+='Infinite wait' fi local check_url_timeout=$(grep -m1 '^[[:blank:]]*CONFIG_G_CHECK_URL_TIMEOUT=' /DietPi/dietpi.txt | sed 's/^[^=]*=//') local check_url_attempts=$(grep -m1 '^[[:blank:]]*CONFIG_G_CHECK_URL_ATTEMPTS=' /DietPi/dietpi.txt | sed 's/^[^=]*=//') G_WHIP_MENU_ARRAY=( '' '●─ Mirror Options ' 'APT Mirror' ": [$apt_mirror_current]" 'NTP Mirror' ": [$ntp_mirror_current]" '' '●─ Connection Test Options ' 'Boot Net Wait' ": [$boot_wait_for_network_text]" 'G_CHECK_URL Timeout' ": [$check_url_timeout Seconds]" 'G_CHECK_URL Attempts' ": [$check_url_attempts Tries]" '' '●─ Additional Options ' 'Network Drives' ': Mount/control networked storage' 'No-IP' ": [$noip_menutext]" ) if G_WHIP_MENU ''; then TARGETMENUID=16 # Return to this menu case "$G_WHIP_RETURNED_VALUE" in 'G_CHECK_URL Timeout') local min=5 max=60 G_WHIP_DEFAULT_ITEM=$check_url_timeout G_WHIP_INPUTBOX "This setting tells DietPi how long to wait, before G_CHECK_URL assumes a dead connection attempt (and failure).\nIncrease this value if you have a 'flaky' connection.\n\nPlease enter a value between $min and $max." if (( $? == 0 )) && G_CHECK_VALIDINT "$G_WHIP_RETURNED_VALUE" $min $max; then G_CONFIG_INJECT 'CONFIG_G_CHECK_URL_TIMEOUT=' "CONFIG_G_CHECK_URL_TIMEOUT=$G_WHIP_RETURNED_VALUE" /DietPi/dietpi.txt fi ;; 'G_CHECK_URL Attempts') local min=2 max=10 G_WHIP_DEFAULT_ITEM=$check_url_attempts G_WHIP_INPUTBOX "This setting tells DietPi how many times to check a URL, before G_CHECK_URL assumes a dead URL link (and failure).\nIncrease this value if you have a 'flaky' connection.\n\nPlease enter a value between $min and $max." if (( $? == 0 )) && G_CHECK_VALIDINT "$G_WHIP_RETURNED_VALUE" $min $max; then G_CONFIG_INJECT 'CONFIG_G_CHECK_URL_ATTEMPTS=' "CONFIG_G_CHECK_URL_ATTEMPTS=$G_WHIP_RETURNED_VALUE" /DietPi/dietpi.txt fi ;; 'Network Drives') G_WHIP_YESNO 'The ability to mount and control networked drives has moved to:\n - DietPi-Drive_manager\n\nWould you like to launch the program now?' (( $? == 0 )) && /DietPi/dietpi/dietpi-drive_manager ;; 'Boot Net Wait') G_WHIP_MENU_ARRAY=( '0' ': Disabled' '1' ': Wait 10 Seconds MAX for network, before continuing boot (default)' '2' ': Infinite wait for network, before continuing boot' ) G_WHIP_DEFAULT_ITEM=$boot_wait_for_network G_WHIP_MENU 'The following options will allow you to delay boot, until a valid network connection is available:' (( $? == 0 )) && G_CONFIG_INJECT 'CONFIG_BOOT_WAIT_FOR_NETWORK=' "CONFIG_BOOT_WAIT_FOR_NETWORK=$G_WHIP_RETURNED_VALUE" /DietPi/dietpi.txt ;; 'APT Mirror') # Jessie ARMv8: https://github.com/MichaIng/DietPi/issues/2665#issuecomment-477348864 if (( $G_HW_ARCH == 3 && $G_DISTRO < 4 )); then G_WHIP_MSG '[INFO] Debian has dropped the Jessie ARMv8 branch from the official APT repository.\n Related packages are now available only from the archive: http://archive.debian.org/debian/\n This has been applied to your APT sources.list during DietPi update to v6.23 and it cannot be changed.\n Aborting...' return fi # Create Menu List for Whiptail G_WHIP_MENU_ARRAY=('Custom' ': Manually enter APT mirror') # - Raspbian if (( $G_HW_MODEL < 10 )); then G_WHIP_MENU_ARRAY+=('http://raspbian.raspberrypi.org/raspbian' ': Global mirror director') G_WHIP_MENU_ARRAY+=('http://mirror.ox.ac.uk/sites/archive.raspbian.org/archive/raspbian' ': UK') G_WHIP_MENU_ARRAY+=('ftp://ftp.fu-berlin.de/linux/raspbian/raspbian' ': Germany') G_WHIP_MENU_ARRAY+=('http://mirror.umd.edu/raspbian/raspbian' ': US') G_WHIP_MENU_ARRAY+=('http://mirrors.ustc.edu.cn/raspbian/raspbian' ': China') G_WHIP_MENU_ARRAY+=('http://raspbian.mirror.digitalpacific.com.au/raspbian' ': Australia') # - Debian else G_WHIP_MENU_ARRAY+=('https://deb.debian.org/debian/' ': Global mirror director') G_WHIP_MENU_ARRAY+=('http://ftp.debian.org/debian/' ': Global') G_WHIP_MENU_ARRAY+=('http://ftp.uk.debian.org/debian/' ': UK') G_WHIP_MENU_ARRAY+=('http://ftp.us.debian.org/debian/' ': US') G_WHIP_MENU_ARRAY+=('http://ftp.cn.debian.org/debian/' ': China') G_WHIP_MENU_ARRAY+=('http://ftp.au.debian.org/debian/' ': Australia') fi G_WHIP_DEFAULT_ITEM=$apt_mirror_current if G_WHIP_MENU 'Please select an APT mirror, or choose custom for manual entry.'; then case $G_WHIP_RETURNED_VALUE in 'Custom') G_WHIP_DEFAULT_ITEM=$apt_mirror_current if G_WHIP_INPUTBOX 'Please enter a new APT Mirror\n - eg: http://ftp.debian.org/debian'; then return_value=$G_WHIP_RETURNED_VALUE fi ;; esac /DietPi/dietpi/func/dietpi-set_software apt-mirror $G_WHIP_RETURNED_VALUE G_AGUP || G_WHIP_MSG "Failed to update APT, exit code: $exit_code.\n\nIf problems persist, please try another APT mirror." fi ;; 'NTP Mirror') # Create Menu List for Whiptail G_WHIP_MENU_ARRAY=( 'Gateway' ': Use local router as NTP server (Recommended)' 'Custom' ': Manually enter NTP mirror' 'Default' ': Fallback to system defaults' '' '●─ Continental NTP pools ' 'europe.pool.ntp.org' ': Europe' 'north-america.pool.ntp.org' ': North America' 'south-america.pool.ntp.org' ': South America' 'africa.pool.ntp.org' ': Africa' 'asia.pool.ntp.org' ': Asia' 'oceania.pool.ntp.org' ': Oceania' '' '●─ Global NTP pools ' 'debian.pool.ntp.org' ': Debian Global' 'pool.ntp.org' ': Global' ) G_WHIP_DEFAULT_ITEM=$ntp_mirror_current G_WHIP_MENU 'Please select an NTP mirror:\n "Gateway": Try to detect and use local router for time sync. Recommended, allows fastest sync and reduces load to the *.pool.ntp.org servers.\n "Custom": Manually enter local or external NTP server address(es).\n "Default": Leave mirror choice to system. Usually falls back to local gateway (Stretch+ only) or "debian.pool.ntp.org".\n Use "*.pool.ntp.org" mirrors, if your device is mobile or should act as local NTP server. Further information: "http://www.pool.ntp.org/zone/@"' if (( $? == 0 )) && [[ $G_WHIP_RETURNED_VALUE ]]; then local new_setting_ntp_mirror=$G_WHIP_RETURNED_VALUE local previous_setting_ntp_mirror=$(grep -m1 '^[[:blank:]]*CONFIG_NTP_MIRROR=' /DietPi/dietpi.txt | sed 's/^[^=]*=//') local apply=1 case $G_WHIP_RETURNED_VALUE in 'Custom') G_WHIP_DEFAULT_ITEM=$ntp_mirror_current if G_WHIP_INPUTBOX 'Please enter one or more (space-separated) NTP mirrors.\n NB: If you need to use *.pool.ntp.org servers, enter the base domain only. The subdomains 0-3 will be added automatically. - Enter "uk.pool.ntp.org" to use [0-3].uk.pool.ntp.org'; then new_setting_ntp_mirror=$G_WHIP_RETURNED_VALUE else apply=0 fi ;; esac if (( $apply )); then G_CONFIG_INJECT 'CONFIG_NTP_MIRROR=' "CONFIG_NTP_MIRROR=$new_setting_ntp_mirror" /DietPi/dietpi.txt /DietPi/dietpi/func/dietpi-set_software ntpd-mode $(grep -m1 '^[[:blank:]]*CONFIG_NTP_MODE=' /DietPi/dietpi.txt | sed 's/^[^=]*=//') if ! MAX_LOOPS_CHECK=10 /DietPi/dietpi/func/run_ntpd 1; then G_WHIP_MSG "Time sync failed:\n - $G_WHIP_RETURNED_VALUE\n\nSetting reverted to previous." G_CONFIG_INJECT 'CONFIG_NTP_MIRROR=' "CONFIG_NTP_MIRROR=$previous_setting_ntp_mirror" /DietPi/dietpi.txt /DietPi/dietpi/func/dietpi-set_software ntpd-mode $(grep -m1 '^[[:blank:]]*CONFIG_NTP_MODE=' /DietPi/dietpi.txt | sed 's/^[^=]*=//') fi fi fi ;; 'No-IP') # Installed? if (( ! $noip_installed )); then G_WHIP_YESNO 'No-IP Client is not installed, would you like to install it now?\n - No-IP will allow you to use a fixed web address, regardless of your internet IP. Eg: MySuperDooperWebsite.noip2.biz would always point to this device!' && /DietPi/dietpi/dietpi-software install 67 else printf '\ec' # clear current terminal screen G_RUN_CMD systemctl stop noip2 # Failsafe: Directory required for "noip2 -C" to create the config file there mkdir -p /usr/local/etc noip2 -C read -p 'Press any key to continue...' G_RUN_CMD systemctl restart noip2 fi ;; esac # Cancel else # Exit DietPi-Config on back to previous menu? if (( $EXITONBACK == 1 )); then TARGETMENUID=16 # Return to this menu Menu_Exit fi fi } PROXY_ENABLED=0 PROXY_ADDRESS='' PROXY_PORT='' PROXY_USERNAME='' PROXY_PASSWORD='' # So we can call this in other menus (eg: submenu of this) Load_Proxy_Vars(){ if [[ -f '/etc/bashrc.d/dietpi-proxy.sh' ]]; then PROXY_ENABLED=1 . /etc/bashrc.d/dietpi-proxy.sh else PROXY_ENABLED=0 # Inform user if DietPi proxy state does not match variable existence # - This occurs either because of missing reboot/login after exiting script before, or, proxy was set up outside of DietPi scripts # - Prompt only when inside/entering proxy settings [[ $http_proxy && $TARGETMENUID == 17 ]] && G_WHIP_MSG 'Either a proxy was set up outside of DietPi scripts or you need to reload you current login session (logout+login or reboot) for changes to take effect.' fi if [[ $http_proxy ]]; then PROXY_ADDRESS=${http_proxy#*//}; PROXY_ADDRESS=${PROXY_ADDRESS%:*} PROXY_PORT=${http_proxy##*:} if [[ $http_proxy == *@* ]]; then PROXY_ADDRESS=${PROXY_ADDRESS#*@} PROXY_USERNAME=${http_proxy#*//}; PROXY_USERNAME=${PROXY_USERNAME%%:*} PROXY_PASSWORD=${http_proxy%%@*}; PROXY_PASSWORD=${PROXY_PASSWORD##*:} fi else [[ $PROXY_ADDRESS ]] || PROXY_ADDRESS=$(grep -m1 '^[[:blank:]]*CONFIG_PROXY_ADDRESS=' /DietPi/dietpi.txt | sed 's/^[^=]*=//') [[ $PROXY_PORT ]] || PROXY_PORT=$(grep -m1 '^[[:blank:]]*CONFIG_PROXY_PORT=' /DietPi/dietpi.txt | sed 's/^[^=]*=//') [[ $PROXY_USERNAME ]] || PROXY_USERNAME=$(grep -m1 '^[[:blank:]]*CONFIG_PROXY_USERNAME=' /DietPi/dietpi.txt | sed 's/^[^=]*=//') [[ $PROXY_PASSWORD ]] || PROXY_PASSWORD=$(grep -m1 '^[[:blank:]]*CONFIG_PROXY_PASSWORD=' /DietPi/dietpi.txt | sed 's/^[^=]*=//') fi } # TARGETMENUID=17 Menu_NetworkAdapters_Proxy(){ Load_Proxy_Vars local proxy_state_text='[Off]' (( $PROXY_ENABLED )) && proxy_state_text='[On]' G_WHIP_MENU_ARRAY=( 'State' ": $proxy_state_text" 'Address' ": $PROXY_ADDRESS" 'Port' ": $PROXY_PORT" 'Username' ": $PROXY_USERNAME" 'Password' ": $PROXY_PASSWORD" ) if G_WHIP_MENU 'Please select an option to change:'; then case "$G_WHIP_RETURNED_VALUE" in 'State') (( $PROXY_ENABLED )) && PROXY_ENABLED=0 || PROXY_ENABLED=1 ;; 'Address') G_WHIP_DEFAULT_ITEM=$PROXY_ADDRESS G_WHIP_INPUTBOX 'Please enter the proxy URL or IP address\n - eg: MyProxy.com' && PROXY_ADDRESS=$G_WHIP_RETURNED_VALUE G_CONFIG_INJECT 'CONFIG_PROXY_ADDRESS=' "CONFIG_PROXY_ADDRESS=$PROXY_ADDRESS" /DietPi/dietpi.txt ;; 'Port') G_WHIP_DEFAULT_ITEM=$PROXY_PORT G_WHIP_INPUTBOX 'Please enter the proxy port number\n - eg: 1234' && PROXY_PORT=$G_WHIP_RETURNED_VALUE G_CONFIG_INJECT 'CONFIG_PROXY_PORT=' "CONFIG_PROXY_PORT=$PROXY_PORT" /DietPi/dietpi.txt ;; 'Username') G_WHIP_DEFAULT_ITEM=$PROXY_USERNAME G_WHIP_INPUTBOX 'Please enter the proxy username\n - eg: JoeBloggs\n - Leave blank if not required' && PROXY_USERNAME=$G_WHIP_RETURNED_VALUE G_CONFIG_INJECT 'CONFIG_PROXY_USERNAME=' "CONFIG_PROXY_USERNAME=$PROXY_USERNAME" /DietPi/dietpi.txt ;; 'Password') G_WHIP_DEFAULT_ITEM=$PROXY_PASSWORD G_WHIP_INPUTBOX 'Please enter the proxy password\n - eg: LetMeIn\n - Leave blank if not required' && PROXY_PASSWORD=$G_WHIP_RETURNED_VALUE G_CONFIG_INJECT 'CONFIG_PROXY_PASSWORD=' "CONFIG_PROXY_PASSWORD=$PROXY_PASSWORD" /DietPi/dietpi.txt ;; esac # - Add export settings if (( $PROXY_ENABLED )); then if [[ $PROXY_USERNAME && $PROXY_PASSWORD ]]; then cat << _EOF_ > /etc/bashrc.d/dietpi-proxy.sh export {http,https,ftp}_proxy="http://$PROXY_USERNAME:$PROXY_PASSWORD@$PROXY_ADDRESS:$PROXY_PORT" _EOF_ else cat << _EOF_ > /etc/bashrc.d/dietpi-proxy.sh export {http,https,ftp}_proxy="http://$PROXY_ADDRESS:$PROXY_PORT" _EOF_ fi else [[ -f '/etc/bashrc.d/dietpi-proxy.sh' ]] && rm /etc/bashrc.d/dietpi-proxy.sh unset {http,https,ftp}_proxy # Has no effect on current login session but for this script, e.g. connection test fi REBOOT_REQUIRED=1 else TARGETMENUID=8 # Return to Network Adapters menu fi } #///////////////////////////////////////////////////////////////////////////////////// # Main Loop #///////////////////////////////////////////////////////////////////////////////////// if (( $G_DIETPI_INSTALL_STAGE >= 0 )); then # Start DietPi-Config while (( $TARGETMENUID >= 0 )); do printf '\ec' # clear current terminal screen G_WHIP_BUTTON_CANCEL_TEXT=$TEXT_MENU_BACK if (( $TARGETMENUID == 0 )); then G_WHIP_BUTTON_CANCEL_TEXT='Exit' Menu_Main elif (( $TARGETMENUID == 1 )); then Menu_DisplayOptions elif (( $TARGETMENUID == 2 )); then Menu_DisplayOptions_Driver_Resolution elif (( $TARGETMENUID == 3 )); then Menu_AdvancedOptions elif (( $TARGETMENUID == 4 )); then Menu_PerformanceOptions elif (( $TARGETMENUID == 5 )); then Menu_SecurityOptions elif (( $TARGETMENUID == 6 )); then Menu_GpumemoryOptions elif (( $TARGETMENUID == 7 )); then Menu_LanguageOptions elif (( $TARGETMENUID == 8 )); then Menu_NetworkAdapters elif (( $TARGETMENUID == 9 )); then Menu_NetworkAdapters_Ethernet elif (( $TARGETMENUID == 10 )); then Menu_NetworkAdapters_Wifi elif (( $TARGETMENUID == 11 )); then Menu_Tools elif (( $TARGETMENUID == 12 )); then Menu_FilesystemBenchmark elif (( $TARGETMENUID == 13 )); then Menu_Overclock elif (( $TARGETMENUID == 14 )); then Menu_AudioOptions elif (( $TARGETMENUID == 15 )); then Menu_StressTest elif (( $TARGETMENUID == 16 )); then Menu_Network_Nas_Misc elif (( $TARGETMENUID == 17 )); then Menu_NetworkAdapters_Proxy elif (( $TARGETMENUID == 18 )); then Menu_AdvancedOptions_Serial_UART else G_WHIP_MSG "[FAILED] Unknown menu ID $TARGETMENUID, reverting to DietPi-Config main menu\n This error should never show up. Please try to reproduce it. If it reappears, you found a coding bug. Please report it to: https://github.com/MichaIng/DietPi/issues" TARGETMENUID=0 fi done else G_WHIP_MSG '[INFO] First run setup has not reached sufficient state.\n\nPlease reboot before using DietPi-Config. If the issue persists, please report this as bug.' fi #----------------------------------------------------------------------------------- exit #----------------------------------------------------------------------------------- }