#!/bin/bash do { #//////////////////////////////////// # 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!!) #//////////////////////////////////// #Grab Inputs # - target MENU INDEX (valid interger) if [[ $1 =~ ^-?[0-9]+$ ]] { setvar TARGETMENUID = "$1" } # - Exit DietPi-Config when going back to previous menu? if [[ $2 =~ ^-?[0-9]+$ ]] { setvar EXITONBACK = "$2" setvar TEXT_MENU_BACK = ""Exit"" } #Import DietPi-Globals --------------------------------------------------------------- source /DietPi/dietpi/func/dietpi-globals G_CHECK_ROOT_USER G_CHECK_ROOTFS_RW export G_PROGRAM_NAME='DietPi-Config' #Import DietPi-Globals --------------------------------------------------------------- #///////////////////////////////////////////////////////////////////////////////////// #Obtain Hardware Details #///////////////////////////////////////////////////////////////////////////////////// setvar HW_ONBOARD_WIFI = $(sed -n 10p /DietPi/dietpi/.hw_model) setvar FP_CPU_SCALING_GOV = ''/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors'' #///////////////////////////////////////////////////////////////////////////////////// #Obtain Installed software #///////////////////////////////////////////////////////////////////////////////////// proc Load_Installed_Software { if test -f /DietPi/dietpi/.installed { source /DietPi/dietpi/.installed } } #///////////////////////////////////////////////////////////////////////////////////// #Whiltail Info #///////////////////////////////////////////////////////////////////////////////////// setvar HW_MSG_NOTSUPPORTED = ""Not Supported"" proc Info_HW_OptionNotSupported { setvar WHIP_QUESTION = ""This option is not available for $G_HW_MODEL_DESCRIPTION"" whiptail --title $WHIP_TITLE --msgbox $WHIP_QUESTION --backtitle $WHIP_BACKTITLE 8 65 } proc Info_Input_Not_Valid_Integer { whiptail --title "Invalid Value" --msgbox "$OPTION is an invalid value. No changes have been applied" --backtitle $WHIP_BACKTITLE 10 60 } #///////////////////////////////////////////////////////////////////////////////////// # MENUS #///////////////////////////////////////////////////////////////////////////////////// setvar TARGETMENUID = '0' setvar EXITONBACK = '0' setvar TEXT_MENU_BACK = ""Back"" setvar WHIP_BACKTITLE = ''DietPi-Config'' setvar WHIP_TITLE = ''DietPi-Config'' setvar WHIP_QUESTION = ''DietPi-Config'' setvar CHOICE = '0' setvar OPTION = '0' setvar WHIP_SELECTION_PREVIOUS = '''' # - Whiptail sizes setvar WHIP_OPTIONS_MAX_DISPLAY = '9' setvar REBOOT_REQUIRED = '0' #Interger min/max value holders setvar MIN_VALUE = '0' setvar MAX_VALUE = '0' #TARGETMENUID=0 proc Menu_Main { setvar WHIP_TITLE = ''DietPi-Config'' setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu " Hardware : $G_HW_MODEL_DESCRIPTION" --cancel-button "Exit" --backtitle "$WHIP_BACKTITLE" 18 50 10 \ "1" "Display Options" \ "2" "Audio Options" \ "3" "Performance Options" \ "4" "Advanced Options" \ "5" "Language/Regional Options" \ "6" "Security Options" \ "7" "Network Options: Adapters" \ "8" "Network Options: NAS/Misc" \ "9" "AutoStart Options" \ "10" "Tools" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { if (( $OPTION == 1 )) { setvar TARGETMENUID = '1' if (( $G_HW_MODEL == 20 )) { setvar TARGETMENUID = '0' Info_HW_OptionNotSupported } } elif (( $OPTION == 2 )) { setvar TARGETMENUID = '14' if (( $G_HW_MODEL == 20 )) { setvar TARGETMENUID = '0' Info_HW_OptionNotSupported } } elif (( $OPTION == 3 )) { setvar TARGETMENUID = '4' if (( $G_HW_MODEL == 20 )) { setvar TARGETMENUID = '0' Info_HW_OptionNotSupported } } elif (( $OPTION == 4 )) { setvar TARGETMENUID = '3' } elif (( $OPTION == 5 )) { setvar TARGETMENUID = '7' } elif (( $OPTION == 6 )) { setvar TARGETMENUID = '5' } elif (( $OPTION == 7 )) { setvar TARGETMENUID = '8' } elif (( $OPTION == 8 )) { setvar TARGETMENUID = '16' } elif (( $OPTION == 9 )) { /DietPi/dietpi/dietpi-autostart setvar REBOOT_REQUIRED = '1' } elif (( $OPTION == 10 )) { setvar TARGETMENUID = '11' } else { Menu_Exit } } else { Menu_Exit } } proc Menu_Exit { # TARGETMENUID = -1 , if we are to exit the menu # The good old "Are you really sure" question. setvar WHIP_TITLE = '' Exit DietPi-Config? '' setvar WHIP_QUESTION = '' Exit DietPi-Config? '' whiptail --title $WHIP_TITLE --yesno $WHIP_QUESTION --yes-button "Ok" --no-button "Back" --defaultno --backtitle $WHIP_BACKTITLE 10 50 setvar CHOICE = ""$? #Exit if (( $CHOICE == 0 )) { setvar TARGETMENUID = '-1' #Disable Reboot when run from dietpi-software if (( $(ps aux | grep -ci -m1 '/DietPi/dietpi/[d]ietpi-software') == 1 )) { setvar REBOOT_REQUIRED = '0' } # Reboot Required if(( $REBOOT_REQUIRED == 1 )) { setvar WHIP_TITLE = ''Changes Made - Reboot Now?'' setvar WHIP_QUESTION = '' A reboot is required to apply your new settings.\n Would you like to reboot now?'' whiptail --title $WHIP_TITLE --yesno $WHIP_QUESTION --defaultno --backtitle $WHIP_BACKTITLE 9 65 setvar CHOICE = ""$? if (( $CHOICE == 0 )) { #Reboot reboot } } #Return to DietPiConfig main menu } elif (( $EXITONBACK == 0 )) { setvar TARGETMENUID = '0' } } proc Display_Rotation_Calc_XY_Invert { local input=$1 if (( $G_HW_MODEL < 10 )) { local framebuffer_x=$(cat /DietPi/config.txt | grep -m1 'framebuffer'_width= | sed 's/.*=//') local framebuffer_y=$(cat /DietPi/config.txt | grep -m1 'framebuffer'_height= | sed 's/.*=//') # 0/180 if (( $input == 0 )) { if (( $framebuffer_x < $framebuffer_y )) { local temp=$framebuffer_x setvar framebuffer_x = "$framebuffer_y" setvar framebuffer_y = "$temp" sed -i "/framebuffer_width=/c\framebuffer_width=$framebuffer_x" /DietPi/config.txt sed -i "/framebuffer_height=/c\framebuffer_height=$framebuffer_y" /DietPi/config.txt } # 90/270 | flip XY FB values } elif (( $input == 1 )) { if (( $framebuffer_x > $framebuffer_y )) { local temp=$framebuffer_x setvar framebuffer_x = "$framebuffer_y" setvar framebuffer_y = "$temp" sed -i "/framebuffer_width=/c\framebuffer_width=$framebuffer_x" /DietPi/config.txt sed -i "/framebuffer_height=/c\framebuffer_height=$framebuffer_y" /DietPi/config.txt } } } } #TARGETMENUID=1 proc Menu_DisplayOptions { setvar TARGETMENUID = '0' local whiptail_menu_array=() if (( $G_HW_MODEL == 21 )) { setvar whiptail_menu_array = ''("1" "Display Driver") } else { setvar whiptail_menu_array = ''("1" "Change Resolution") setvar whiptail_menu_array = ''("2" "GPU/RAM Memory Split") local lcdpanel_text=$(cat /DietPi/dietpi.txt | grep -m1 '^CONFIG_LCDPANEL=' | sed 's/.*=//') setvar whiptail_menu_array = ''("3" "LCD Panel addon: $lcdpanel_text") } setvar whiptail_menu_array = ''("14" "LED Control") #RPi only if (( $G_HW_MODEL < 10 )) { # - Get Current Settings local overscan_enabled=$(cat /DietPi/config.txt | grep -ci -m1 'disable_overscan=0') local overscan_text='Disabled' if (( $overscan_enabled )) { setvar overscan_text = ''Enabled'' } local hdmi_boost_disabled=$(cat /DietPi/config.txt | grep -ci -m1 '#config_hdmi_boost=') local hdmi_boost_text='Enabled' if (( $hdmi_boost_disabled )) { setvar hdmi_boost_text = ''Disabled'' } local rpi_camera_module_enabled=$(cat /DietPi/config.txt | grep -ci -m1 'start_x=1') local rpi_camera_module_text='Disabled' if (( $rpi_camera_module_enabled == 1 )) { setvar rpi_camera_module_text = ''Enabled'' } local rpi_camera_led_enabled=$(cat /DietPi/config.txt | grep -ci -m1 'disable_camera_led=0') local rpi_camera_led_text='Disabled' if (( $rpi_camera_led_enabled == 1 )) { setvar rpi_camera_led_text = ''Enabled'' } local rotation_hdmi_current=$(cat /DietPi/config.txt | grep -m1 '^display_rotate=' | sed 's/.*=//') local rotation_lcd_current=$(cat /DietPi/config.txt | grep -m1 '^lcd_rotate=' | sed 's/.*=//') local vc1_key_current=$(cat /DietPi/config.txt | grep -m1 '^decode_WVC1=' | sed 's/.*=//') local mpeg2_key_current=$(cat /DietPi/config.txt | grep -m1 '^decode_MPG2=' | sed 's/.*=//') #JustBoom IR Remote local justboom_ir_remote_text='Disabled' local justboom_ir_remote_enabled=0 if test -f /etc/systemd/system/justboom-ir-mpd.service { setvar justboom_ir_remote_text = ''Enabled'' setvar justboom_ir_remote_enabled = '1' } setvar whiptail_menu_array = ''("4" "Rotation (HDMI) : $rotation_hdmi_current") setvar whiptail_menu_array = ''("5" "Rotation (LCD) : $rotation_lcd_current") setvar whiptail_menu_array = ''("6" "Overscan : $overscan_text") if (( $overscan_enabled )) { local overscan_options=( 'overscan_left' 'overscan_right' 'overscan_top' 'overscan_bottom' ) local overscan_left=$(cat /DietPi/config.txt | grep -m1 'overscan_left=' | sed 's/.*=//') local overscan_right=$(cat /DietPi/config.txt | grep -m1 'overscan_right=' | sed 's/.*=//') local overscan_top=$(cat /DietPi/config.txt | grep -m1 'overscan_top=' | sed 's/.*=//') local overscan_bottom=$(cat /DietPi/config.txt | grep -m1 'overscan_bottom=' | sed 's/.*=//') setvar whiptail_menu_array = ''("15" "Overscan Compensation : L:$overscan_left R:$overscan_right T:$overscan_top B:$overscan_bottom") } setvar whiptail_menu_array = ''("7" "HDMI Boost : $hdmi_boost_text") setvar whiptail_menu_array = ''("8" "RPi Camera : $rpi_camera_module_text") setvar whiptail_menu_array = ''("9" "RPI Camera led : $rpi_camera_led_text") setvar whiptail_menu_array = ''("11" "JustBoom IR remote : $justboom_ir_remote_text") setvar whiptail_menu_array = ''("12" "VC1 Key : $vc1_key_current") setvar whiptail_menu_array = ''("13" "MPEG2 Key : $mpeg2_key_current") } #Odroid Remote if (( $G_HW_MODEL >= 10 && $G_HW_MODEL <= 12 )) { local odroid_remote_text='Disabled' local odroid_remote_enabled=0 if test -f /etc/systemd/system/odroid-remote.service { setvar odroid_remote_text = ''Enabled'' setvar odroid_remote_enabled = '1' } setvar whiptail_menu_array = ''("10" "Odroid remote : $odroid_remote_text") } setvar WHIP_TITLE = ''DietPi - Display Options'' setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu "Please select an option:" --cancel-button "$TEXT_MENU_BACK" --default-item "$WHIP_SELECTION_PREVIOUS" --backtitle "$WHIP_BACKTITLE" 18 70 10 "${whiptail_menu_array[@]}" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? unset whiptail_menu_array if (( $CHOICE == 0 )) { setvar WHIP_SELECTION_PREVIOUS = "$OPTION" if (( $OPTION == 15 )) { for ((i=0; i<${#overscan_options[@]}; i++)) do WHIP_TITLE='DietPi - Overscan Compensation' OPTION=$(whiptail --inputbox "Please enter a value (pixel count) for ${overscan_options[$i]}.:\n - EG: 16" 10 60 "${!overscan_options[$i]}" --title "$WHIP_TITLE" 3>&1 1>&2 2>&3) CHOICE=$? if (( $CHOICE == 0 )); then sed -i "/${overscan_options[$i]}=/c ${overscan_options[$i]}=$OPTION" /DietPi/config.txt REBOOT_REQUIRED=1 else break fi done setvar TARGETMENUID = '1' } elif (( $OPTION == 1 )) { setvar TARGETMENUID = '2' } elif (( $OPTION == 3 )) { if (( $G_HW_MODEL < 10 || $G_HW_MODEL == 10 || $G_HW_MODEL == 11 || $G_HW_MODEL == 12 )) { local whiptail_menu_array=() setvar whiptail_menu_array = ''("none" "Uninstall all panels") setvar whiptail_menu_array = ''("waveshare32" "320x240 panel with touch input") if (( $G_HW_MODEL == 11 )) { setvar whiptail_menu_array = ''("odroid-cloudshell" "320x240 panel") } if (( $G_HW_MODEL >= 10 && $G_HW_MODEL < 20 )) { setvar whiptail_menu_array = ''("odroid-lcd35" "480x320 panel with touch input") } setvar WHIP_TITLE = ''DietPi - LCD Panel'' setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu "Please select an option:" --default-item "$lcdpanel_text" --cancel-button "$TEXT_MENU_BACK" 14 60 5 "${whiptail_menu_array[@]}" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { /DietPi/dietpi/func/dietpi-set_hardware lcdpanel $OPTION setvar REBOOT_REQUIRED = '1' } unset whiptail_menu_array } else { Info_HW_OptionNotSupported } #Return to this menu setvar TARGETMENUID = '1' } elif (( $OPTION == 2 )) { if (( $G_HW_MODEL < 10 || $G_HW_MODEL == 10 || $G_HW_MODEL == 12 )) { setvar WHIP_QUESTION = ''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.'' whiptail --title $WHIP_TITLE --msgbox $WHIP_QUESTION --backtitle $WHIP_BACKTITLE 12 60 setvar TARGETMENUID = '6' } else { Info_HW_OptionNotSupported #Return to this menu setvar TARGETMENUID = '1' } } elif (( $OPTION == 6 )) { #RPI only if (( $G_HW_MODEL < 10 )) { if (( $overscan_enabled )) { sed -i '/disable_overscan=/c\disable_overscan=1' /DietPi/config.txt for ((i=0; i<${#overscan_options[@]}; i++)) do sed -i "/${overscan_options[$i]}=/c ${overscan_options[$i]}=0" /DietPi/config.txt done setvar REBOOT_REQUIRED = '1' } elif (( ! $overscan_enabled )) { sed -i '/disable_overscan=/c\disable_overscan=0' /DietPi/config.txt setvar REBOOT_REQUIRED = '1' } } else { Info_HW_OptionNotSupported } #Return to This Menu setvar TARGETMENUID = '1' } elif (( $OPTION == 7 )) { #RPI only if (( $G_HW_MODEL < 10 )) { #Enabled if test $hdmi_boost_disabled = 0 { setvar WHIP_QUESTION = "" Current setting: $hdmi_boost_text \n Would you like to disable HDMI Signal Boost?"" whiptail --title $WHIP_TITLE --yesno $WHIP_QUESTION --yes-button "Ok" --no-button "Back" --defaultno --backtitle $WHIP_BACKTITLE 12 60 setvar CHOICE = ""$? if (( $CHOICE == 0 )) { sed -i '/config_hdmi_boost=/c\#config_hdmi_boost=4' /DietPi/config.txt setvar REBOOT_REQUIRED = '1' } #Disabled } elif test $hdmi_boost_disabled = 1 { setvar WHIP_QUESTION = "" Current setting: $hdmi_boost_text \n Would you like to enable HDMI Signal Boost? \n \n If you have no display output, or, blinking, selecting Enable may resolve it "" whiptail --title $WHIP_TITLE --yesno $WHIP_QUESTION --yes-button "Ok" --no-button "Back" --defaultno --backtitle $WHIP_BACKTITLE 12 60 setvar CHOICE = ""$? if (( $CHOICE == 0 )) { sed -i '/config_hdmi_boost=/c\config_hdmi_boost=4' /DietPi/config.txt setvar REBOOT_REQUIRED = '1' } } } else { Info_HW_OptionNotSupported } #Return to This Menu setvar TARGETMENUID = '1' } elif (( $OPTION == 8 )) { #RPI only if (( $G_HW_MODEL < 10 )) { if (( ! $rpi_camera_module_enabled )) { /DietPi/dietpi/func/dietpi-set_hardware rpi-camera enable setvar REBOOT_REQUIRED = '1' } else { /DietPi/dietpi/func/dietpi-set_hardware rpi-camera disable setvar REBOOT_REQUIRED = '1' } } else { Info_HW_OptionNotSupported } #Return to This Menu setvar TARGETMENUID = '1' } elif (( $OPTION == 9 )) { #RPI only if (( $G_HW_MODEL < 10 )) { if (( ! $rpi_camera_led_enabled )) { #enable sed -i '/disable_camera_led=/c\disable_camera_led=0' /DietPi/config.txt setvar REBOOT_REQUIRED = '1' } else { #disable sed -i '/disable_camera_led=/c\disable_camera_led=1' /DietPi/config.txt setvar REBOOT_REQUIRED = '1' } } else { Info_HW_OptionNotSupported } #Return to This Menu setvar TARGETMENUID = '1' } elif (( $OPTION == 10 )) { # - Enable if (( ! $odroid_remote_enabled )) { whiptail --title "Odroid Remote" --yesno "This will enable the IR modules, setup Lirc and the Odroid Remote for Odroid C1, C2 and XU4 Cloudshell.\n\nNB: Other remotes can be configured by running 'irrecord' and applying the codes to '/etc/lirc/lircd.conf'\n\nDo you wish to continue?" --yes-button "Ok" --no-button "Back" --defaultno --backtitle $WHIP_BACKTITLE 14 70 setvar CHOICE = ""$? if (( $CHOICE == 0 )) { /DietPi/dietpi/func/dietpi-set_hardware remoteir odroid_remote } } else { /DietPi/dietpi/func/dietpi-set_hardware remoteir none } setvar REBOOT_REQUIRED = '1' #Return to This Menu setvar TARGETMENUID = '1' } elif (( $OPTION == 11 )) { # - Enable if (( ! $justboom_ir_remote_enabled )) { whiptail --title "JustBoom IR Remote" --yesno "Got a JustBoom IR Remote? Excellent!\n\nDietPi will enable the IR modules, setup Lirc and enable support for MPD controls by default:\n\nDo you wish to continue?" --yes-button "Ok" --no-button "Back" --defaultno --backtitle $WHIP_BACKTITLE 14 70 setvar CHOICE = ""$? if (( $CHOICE == 0 )) { /DietPi/dietpi/func/dietpi-set_hardware remoteir justboom_ir_remote } } else { /DietPi/dietpi/func/dietpi-set_hardware remoteir none } setvar REBOOT_REQUIRED = '1' #Return to This Menu setvar TARGETMENUID = '1' } elif (( $OPTION == 12 )) { setvar WHIP_TITLE = ''DietPi - VC1 Key'' setvar OPTION = $(whiptail --inputbox "Please enter your key for VC1:\n - EG: 0x00000000" 12 60 "$vc1_key_current" --title "$WHIP_TITLE" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { if (( ! $(cat /DietPi/config.txt | grep -ci -m1 'decode_WVC1=') )) { echo -e "\ndecode_WVC1=0x00000000" >> /DietPi/config.txt } sed -i "/decode_WVC1=/c\decode_WVC1=$OPTION" /DietPi/config.txt setvar REBOOT_REQUIRED = '1' } #Return to This Menu setvar TARGETMENUID = '1' } elif (( $OPTION == 13 )) { setvar WHIP_TITLE = ''DietPi - MPEG2 Key'' setvar OPTION = $(whiptail --inputbox "Please enter your key for MPEG2:\n - EG: 0x00000000" 12 60 "$mpeg2_key_current" --title "$WHIP_TITLE" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { if (( ! $(cat /DietPi/config.txt | grep -ci -m1 'decode_MPG2=') )) { echo -e "\ndecode_MPG2=0x00000000" >> /DietPi/config.txt } sed -i "/decode_MPG2=/c\decode_MPG2=$OPTION" /DietPi/config.txt setvar REBOOT_REQUIRED = '1' } setvar REBOOT_REQUIRED = '1' #Return to This Menu setvar TARGETMENUID = '1' } elif (( $OPTION == 4 )) { local whiptail_menu_array=() setvar whiptail_menu_array = ''("0" "Disabled (default)") setvar whiptail_menu_array = ''("1" "90 degrees") setvar whiptail_menu_array = ''("2" "180 degrees") setvar whiptail_menu_array = ''("3" "270 degrees") setvar whiptail_menu_array = ''("0x10000" "Horizontal flip") setvar whiptail_menu_array = ''("0x20000" "Vertical flip") setvar WHIP_TITLE = ''DietPi - Display Rotation (HDMI)'' setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu "Please select an option:\n\nNB: If you have the RPi touchscreen, please set this to 0 and use LCD rotation option." --default-item "$rotation_hdmi_current" --cancel-button "$TEXT_MENU_BACK" 18 60 6 "${whiptail_menu_array[@]}" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { sed -i "/display_rotate=/c\display_rotate=$OPTION" /DietPi/config.txt # rotation 90/270 | invert x/y on FB (Y > X) if test $OPTION = "1" || test $OPTION = "3" { Display_Rotation_Calc_XY_Invert 1 # X > Y } else { Display_Rotation_Calc_XY_Invert 0 } setvar REBOOT_REQUIRED = '1' } unset whiptail_menu_array setvar REBOOT_REQUIRED = '1' #Return to This Menu setvar TARGETMENUID = '1' } elif (( $OPTION == 5 )) { local whiptail_menu_array=() setvar whiptail_menu_array = ''("0" "Disabled (default)") setvar whiptail_menu_array = ''("2" "180 degrees") setvar WHIP_TITLE = ''DietPi - Display Rotation (LCD)'' setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu "Please select an option:\n\nNB: This option is for RPi touchscreen." --default-item "$rotation_lcd_current" --cancel-button "$TEXT_MENU_BACK" 14 60 2 "${whiptail_menu_array[@]}" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { sed -i "/lcd_rotate=/c\lcd_rotate=$OPTION" /DietPi/config.txt setvar REBOOT_REQUIRED = '1' } unset whiptail_menu_array setvar REBOOT_REQUIRED = '1' #Return to This Menu setvar TARGETMENUID = '1' } elif (( $OPTION == 14 )) { /DietPi/dietpi/func/dietpi-led_control setvar TARGETMENUID = '1' } } unset overscan_options } #TARGETMENUID=2 proc Menu_DisplayOptions_Driver_Resolution { #Return to Display Options Menu setvar TARGETMENUID = '1' #Native PC if (( $G_HW_MODEL == 21 )) { local whiptail_menu_array=() local nvidia_installed=0 local nvidia_text='Install GPU driver' if (( $(dpkg --get-selections | grep -ci -m1 '^nvidia-driver') )) { setvar nvidia_installed = '1' setvar nvidia_text = ''Uninstall GPU driver'' } setvar whiptail_menu_array = ''('Nvidia' " : $nvidia_text") local radeon_installed=0 local intel_installed=0 # Xserver configure available? # NB: Needs further testing... # if (( $(dpkg --get-selections | grep -ci -m1 '^xserver-xorg') )); then # whiptail_menu_array+=('Xorg Configuration' " : Configure X server") # fi setvar WHIP_TITLE = ''DietPi - Display Driver'' setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu "Please select an option:" --cancel-button "$TEXT_MENU_BACK" --default-item "$WHIP_SELECTION_PREVIOUS" --backtitle "$WHIP_BACKTITLE" 14 70 4 "${whiptail_menu_array[@]}" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar TARGETMENUID = '2' if test $OPTION = 'Nvidia' { if (( ! $nvidia_installed )) { /DietPi/dietpi/dietpi-software install 151 } else { /DietPi/dietpi/dietpi-software uninstall 151 } setvar REBOOT_REQUIRED = '1' } elif test $OPTION = 'Xorg Configuration' { whiptail --title "Info: Xorg Configuration" --msgbox "NB: This feature will only work if no X server is currently running.\n\nPlease ensure:\n - No current X server (desktop) is running\n\nIf a desktop is running, please set 'dietpi-autostart' to 'Console', reboot system, then rerun this option." --backtitle $WHIP_BACKTITLE 16 65 X -configure } } #RPI } elif (( $G_HW_MODEL < 10 )) { #Get Current Values local framebuffer_x=$(cat /DietPi/config.txt | grep -m1 'framebuffer'_width= | sed 's/.*=//') local framebuffer_y=$(cat /DietPi/config.txt | grep -m1 'framebuffer'_height= | sed 's/.*=//') local display_output_text="$framebuffer_x X $framebuffer_y" # - openGL detection if (( $(cat /DietPi/config.txt | grep -ci -m1 '^dtoverlay=vc4-kms-v3d') )) { setvar display_output_text = ''OpenGL 1080p'' } #check for headless if (($(cat /DietPi/dietpi.txt | grep -ci -m1 'CONFIG_HDMI_OUTPUT=0') == 1)) { setvar display_output_text = ""Headless"" } setvar WHIP_TITLE = ''DietPi - Resolution'' setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu " Hardware : $G_HW_MODEL_DESCRIPTION \n Current: $display_output_text" --cancel-button "$TEXT_MENU_BACK" 19 60 9 \ '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' 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar REBOOT_REQUIRED = '1' #Return to This Menu setvar TARGETMENUID = '2' # - Always enable HDMI output by default sed -i "/CONFIG_HDMI_OUTPUT=/c\CONFIG_HDMI_OUTPUT=1" /DietPi/dietpi.txt # - Always disable composite by default sed -i '/sdtv_mode=/c\#sdtv_mode=0' /DietPi/config.txt # - Always disable OpenGL by default: /DietPi/dietpi/func/dietpi-set_hardware rpi-opengl disable if test $OPTION = "OpenGL" { /DietPi/dietpi/func/dietpi-set_hardware rpi-opengl enable # - although not used, dietpi-config reads current resolution from these, so apply also. sed -i '/framebuffer_width=/c\framebuffer_width=1920' /DietPi/config.txt sed -i '/framebuffer_height=/c\framebuffer_height=1080' /DietPi/config.txt } elif [[ "$OPTION" = "sdtv_mode"* ]] { echo $OPTION sed -i "/sdtv_mode=/c $OPTION" /DietPi/config.txt sed -i '/framebuffer_width=/c\framebuffer_width=720' /DietPi/config.txt sed -i '/framebuffer_height=/c\framebuffer_height=576' /DietPi/config.txt } else { case (OPTION) { "DietPi-Cloudshell" { sed -i '/framebuffer_width=/c\framebuffer_width=320' /DietPi/config.txt sed -i '/framebuffer_height=/c\framebuffer_height=240' /DietPi/config.txt } 1080p { sed -i '/framebuffer_width=/c\framebuffer_width=1920' /DietPi/config.txt sed -i '/framebuffer_height=/c\framebuffer_height=1080' /DietPi/config.txt } 720p { sed -i '/framebuffer_width=/c\framebuffer_width=1280' /DietPi/config.txt sed -i '/framebuffer_height=/c\framebuffer_height=720' /DietPi/config.txt } 480p { sed -i '/framebuffer_width=/c\framebuffer_width=854' /DietPi/config.txt sed -i '/framebuffer_height=/c\framebuffer_height=480' /DietPi/config.txt } "RPi Touchscreen" { sed -i '/framebuffer_width=/c\framebuffer_width=800' /DietPi/config.txt sed -i '/framebuffer_height=/c\framebuffer_height=480' /DietPi/config.txt } PC1 { sed -i '/framebuffer_width=/c\framebuffer_width=1024' /DietPi/config.txt sed -i '/framebuffer_height=/c\framebuffer_height=768' /DietPi/config.txt } PC2 { sed -i '/framebuffer_width=/c\framebuffer_width=800' /DietPi/config.txt sed -i '/framebuffer_height=/c\framebuffer_height=640' /DietPi/config.txt } PC3 { sed -i '/framebuffer_width=/c\framebuffer_width=640' /DietPi/config.txt sed -i '/framebuffer_height=/c\framebuffer_height=480' /DietPi/config.txt } Headless { whiptail --title $WHIP_TITLE --msgbox " Using the Headless option will: \n - Disable HDMI output \n - Lower energy consumption by 0.1+ Watts \n - Set framebuffer to 16x16xD8 \n - Improve RAM performance by 1-5% (VideoCore shares RAM bandwidth) \n - More info here : https://www.raspberrypi.org/forums/viewtopic.php?p=105008#p105008" --backtitle $WHIP_BACKTITLE 14 75 sed -i "/CONFIG_HDMI_OUTPUT=/c\CONFIG_HDMI_OUTPUT=0" /DietPi/dietpi.txt } } } } #Odroid C1 } elif (( $G_HW_MODEL == 10 )) { #Get Current Values local current_resolution=$(cat /DietPi/boot.ini | grep -m1 'setenv m "' | awk -F '"' '{print $2}') setvar WHIP_TITLE = ''DietPi - Resolution'' setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu " Hardware : $G_HW_MODEL_DESCRIPTION \n Current: $current_resolution" --cancel-button "$TEXT_MENU_BACK" 16 60 6 \ "1080p" "1920 x 1080" \ "720p" "1280 x 720" \ "480p" "720 x 480" \ "VU7+" "1024 x 600" \ "PC1" "1024 x 768" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar REBOOT_REQUIRED = '1' #Return to This Menu setvar TARGETMENUID = '2' # - Always reset to HDMI sed -i '/setenv vout_mode /c\setenv vout_mode "hdmi"' /DietPi/boot.ini case (OPTION) { 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 } } } #Odroid xu3/4 } elif (( $G_HW_MODEL == 11 )) { #Get Current Values local current_resolution="" if (( $(cat /DietPi/boot.ini | grep -m1 'setenv videoconfig "' | grep -ci -m1 1920x1080) == 1 )) { setvar current_resolution = ""1080p"" } elif (( $(cat /DietPi/boot.ini | grep -m1 'setenv videoconfig "' | grep -ci -m1 1280x720) == 1 )) { setvar current_resolution = ""720p"" } elif (( $(cat /DietPi/boot.ini | grep -m1 'setenv videoconfig "' | grep -ci -m1 720x480) == 1 )) { setvar current_resolution = ""480p"" } setvar WHIP_TITLE = ''DietPi - Resolution'' setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu " Hardware : $G_HW_MODEL_DESCRIPTION \n Current: $current_resolution" --cancel-button "$TEXT_MENU_BACK" 14 60 4 \ "1080p" "1920 x 1080" \ "720p" "1280 x 720" \ "480p" "720 x 480" \ "VU7+" "1024 x 600" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar REBOOT_REQUIRED = '1' #Return to This Menu setvar TARGETMENUID = '2' # - Always reset to hdmi sed -i '/setenv vout /c\setenv vout "hdmi"' /DietPi/boot.ini case (OPTION) { 1080p { sed -i '/setenv videoconfig /c\setenv videoconfig "drm_kms_helper.edid_firmware=edid/1920x1080.bin"' /DietPi/boot.ini } 720p { sed -i '/setenv videoconfig /c\setenv videoconfig "drm_kms_helper.edid_firmware=edid/1280x720.bin"' /DietPi/boot.ini } 480p { sed -i '/setenv videoconfig /c\setenv videoconfig "drm_kms_helper.edid_firmware=edid/720x480.bin"' /DietPi/boot.ini } "VU7+" { sed -i '/setenv videoconfig /c\setenv videoconfig "drm_kms_helper.edid_firmware=edid/1024x600.bin"' /DietPi/boot.ini sed -i '/setenv vout /c\setenv vout "dvi"' /DietPi/boot.ini } } } #Odroid C2 } elif (( $G_HW_MODEL == 12 )) { #Get Current Values local current_resolution=$(cat /DietPi/boot.ini | grep -m1 'setenv m "' | awk -F '"' '{print $2}' | sed 's/p/p /') # - NB: also added space after xxxp, so its easier to read, and selects default item. setvar WHIP_TITLE = ''DietPi - Resolution'' setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu " Hardware : $G_HW_MODEL_DESCRIPTION \n Current: $current_resolution" --default-item "$current_resolution" --cancel-button "$TEXT_MENU_BACK" 18 60 9 \ "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" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { if test $current_resolution != $OPTION { setvar 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 test $OPTION = "1024x600p 60hz" { # + DVI mode sed -i '/setenv vout "dvi"/c\setenv vout "dvi"' /DietPi/boot.ini } #Remove the space from option setvar OPTION = $(echo -e "$OPTION" | tr -d '[:blank:]') sed -i "/setenv m /c\setenv m \"$OPTION\"" /DietPi/boot.ini #Return to This Menu setvar TARGETMENUID = '2' } #Pine a64 } elif (( $G_HW_MODEL == 40 )) { #Get Current Values local current_resolution=$(cat /DietPi/uEnv.txt | grep -m1 'optargs=disp.screen0_output_mode=' | sed 's/.*=//') setvar WHIP_TITLE = ''DietPi - Resolution'' setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu " Hardware : $G_HW_MODEL_DESCRIPTION \n Current: $current_resolution" --default-item "$current_resolution" --cancel-button "$TEXT_MENU_BACK" 18 55 9 \ "720p50" "" \ "720p60" "720p" \ "1080i50" "" \ "1080i60" "1080i" \ "1080p24" "" \ "1080p50" "" \ "1080p60" "1080p" \ "2160p24" "" \ "2160p25" "" \ "2160p30" "4K" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { if test $current_resolution != $OPTION { sed -i "/^optargs=disp.screen0_output_mode=/c\optargs=disp.screen0_output_mode=$OPTION" /DietPi/uEnv.txt setvar REBOOT_REQUIRED = '1' } #Return to This Menu setvar TARGETMENUID = '2' } } else { Info_HW_OptionNotSupported } } #TARGETMENUID=3 proc Menu_AdvancedOptions { setvar TARGETMENUID = '0' local whiptail_menu_array=() #Get Current Settings local swap_size=$(grep -m1 '^CONF_SWAPSIZE=' /etc/dphys-swapfile | sed 's/.*=//') local swap_text="$swap_size MB" if (( $swap_size == 0 )) { setvar swap_text = ""Disabled"" } setvar whiptail_menu_array = ''("Swapfile size" ": $swap_text") #NTPD local ntpd_mode_current=$(grep -m1 '^CONFIG_NTP_MODE=' /DietPi/dietpi.txt | sed 's/.*=//') local ntpd_mode_text="" if (( $ntpd_mode_current == 0 )) { setvar ntpd_mode_text = ""Disabled"" } elif (( $ntpd_mode_current == 1 )) { setvar ntpd_mode_text = ""Boot Only"" } elif (( $ntpd_mode_current == 2 )) { setvar ntpd_mode_text = ""Boot + Daily"" } elif (( $ntpd_mode_current == 3 )) { setvar ntpd_mode_text = ""Boot + Hourly"" } elif (( $ntpd_mode_current == 4 )) { setvar ntpd_mode_text = ""Daemon + Drift"" } setvar whiptail_menu_array = ''("Time sync mode" ": $ntpd_mode_text") setvar serialconsole_state = $(cat /DietPi/dietpi.txt | grep -m1 '^CONFIG_SERIAL_CONSOLE_ENABLE=' | sed 's/.*=//') setvar serialconsole_text = ''Disabled'' if (( $serialconsole_state == 1 )) { setvar serialconsole_text = ''Enabled'' } setvar whiptail_menu_array = ''("Update firmware" "") local bluetooth_state_text='Enabled' local bluetooth_state=1 if test -f /etc/modprobe.d/disable_bt.conf { setvar bluetooth_state = '0' setvar bluetooth_state_text = ''Disabled'' } # - No bluetooth for VM if (( $G_HW_MODEL != 20 )) { setvar whiptail_menu_array = ''("Bluetooth" ": $bluetooth_state_text") } # - No serial console for VM if (( $G_HW_MODEL != 20 )) { setvar whiptail_menu_array = ''("Serial console" ": $serialconsole_text") } #RPi Specific if (( $G_HW_MODEL < 10 )) { local rpi_i2c_enabled=$(cat /DietPi/config.txt | grep -ci -m1 'dtparam=i2c_arm=on') local rpi_i2c_text='Disabled' if (( $rpi_i2c_enabled == 1 )) { setvar rpi_i2c_text = ''Enabled'' } local rpi_i2cbaudrate_hz="$(( $(cat /DietPi/config.txt | grep -m1 'i2c_arm_baudrate=' | sed 's/.*=//') / 1000 )) kHz" local usb_max_current_enabled=$(cat /DietPi/config.txt | grep -ci -m1 'max_usb_current=1') local rpi_usbmaxcurrent_text='Disabled' if test $usb_max_current_enabled = 1 { setvar rpi_usbmaxcurrent_text = ''Enabled'' } if (( $G_HW_MODEL == 3 )) { local rpi3_usb_boot_bit_enabled=$(vcgencmd otp_dump | grep -m1 '17:' | grep -ci -m1 '3020000a') local rpi3_usb_boot_bit_enabled_text='Disabled' if (( $rpi3_usb_boot_bit_enabled )) { setvar rpi3_usb_boot_bit_enabled_text = ''Enabled'' } setvar whiptail_menu_array = ''("USB boot support" ": $rpi3_usb_boot_bit_enabled_text") } setvar whiptail_menu_array = ''("Max USB current" ": $rpi_usbmaxcurrent_text") setvar whiptail_menu_array = ''("I2c state" ": $rpi_i2c_text") setvar whiptail_menu_array = ''("I2c frequency" ": $rpi_i2cbaudrate_hz") } setvar WHIP_TITLE = ''DietPi - Advanced Options'' setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu "Please select an option:" --cancel-button "$TEXT_MENU_BACK" 16 60 8 "${whiptail_menu_array[@]}" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? unset whiptail_menu_array if (( $CHOICE == 0 )) { if test $OPTION = "Swapfile size" { setvar MIN_VALUE = '0' setvar MAX_VALUE = '2000' setvar OPTION = $(whiptail --inputbox "This will set the size of your swap file in MB:\n\nSwapfile has a swapiness setting of 1. Swapfile is used only to prevent out of memory errors.\n\n - Recommended value = 1 (auto)\n - 0 = Disable swapfile\n - 1 = Auto size swapfile (2GB - RAM = size)\n - 2 - $MAX_VALUE = Manual size" 16 75 "$swap_size" --title "SwapFile Size (MB)" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { if [[ $OPTION =~ ^-?[0-9]+$ ]] && (( $OPTION >= $MIN_VALUE )) && (( $OPTION <= $MAX_VALUE )) { #Generate swapfile with new size if (( $OPTION != $swap_size )) { /DietPi/dietpi/func/dietpi-set_dphys-swapfile $OPTION } } else { Info_Input_Not_Valid_Integer } } #Return to This Menu setvar TARGETMENUID = '3' } elif test $OPTION = "Time sync mode" { setvar OPTION = $(whiptail --title "Time Sync (NTP)" --menu "Here you can adjust the frequency of NTP time syncs.\n\n - Modes 1-3:\nDietPi will launch NTPD as a program, rather than a daemon. Once the time has been updated on your system, NTPD will exit to reduce resource usage.\n\n - Mode 4:\nsystemd-timesyncd will run as a background daemon/service. Differences in time will be gradually adjusted over time, rather than instantly." --cancel-button "$TEXT_MENU_BACK" --default-item "$ntpd_mode_current" 23 70 5 \ "0" "Disabled" \ "1" "Boot Only" \ "2" "Boot + Daily (Recommended)" \ "3" "Boot + Hourly" \ "4" "Daemon + Drift" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { /DietPi/dietpi/func/dietpi-set_software ntpd-mode $OPTION } #Return to This Menu setvar TARGETMENUID = '3' } elif test $OPTION = "Update firmware" { #RPI if (( $G_HW_MODEL < 10 )) { setvar WHIP_QUESTION = ""Would you like to update the firmware/kernel for $G_HW_MODEL_DESCRIPTION?\n - This will run G_RPI_UPDATE"" whiptail --title $WHIP_TITLE --yesno $WHIP_QUESTION --yes-button "Ok" --no-button "Back" --defaultno --backtitle $WHIP_BACKTITLE 14 70 setvar CHOICE = ""$? if (( $CHOICE == 0 )) { G_RPI_UPDATE setvar REBOOT_REQUIRED = '1' } #PineA64 } elif (( $G_HW_MODEL == 40 )) { setvar WHIP_QUESTION = ""Would you like to update the firmware/kernel for $G_HW_MODEL_DESCRIPTION?\n - This will run longsleep's update scripts to update the U-Boot and kernel."" whiptail --title $WHIP_TITLE --yesno $WHIP_QUESTION --yes-button "Ok" --no-button "Back" --defaultno --backtitle $WHIP_BACKTITLE 14 70 setvar CHOICE = ""$? if (( $CHOICE == 0 )) { /usr/local/sbin/pine64_update_uboot.sh /usr/local/sbin/pine64_update_kernel.sh } #G_AGDUG based (not all devices support this) } else { setvar WHIP_QUESTION = ""Would you like to update the firmware/kernel for $G_HW_MODEL_DESCRIPTION?\n - This will run G_AGDUG\n - Most (but not all) devices allow APT based firmware updates\n\nNB: If requested to overwrite the current kernel, press TAB and then ENTER (to confirm)."" whiptail --title $WHIP_TITLE --yesno $WHIP_QUESTION --yes-button "Ok" --no-button "Back" --defaultno --backtitle $WHIP_BACKTITLE 16 70 setvar CHOICE = ""$? if (( $CHOICE == 0 )) { G_AGUP G_AGDUG } } #Return to This Menu setvar TARGETMENUID = '3' } elif test $OPTION = "Max USB current" { #Enabled if (( $usb_max_current_enabled == 1 )) { setvar WHIP_QUESTION = "" Current setting: $rpi_usbmaxcurrent_text (1.2AMP) \n Would you like to disable this setting ? \n \n Once Disabled: \n - Max USB current will be limited to 0.6AMP.\n - Shared by all USB ports."" whiptail --title $WHIP_TITLE --yesno $WHIP_QUESTION --yes-button "Ok" --no-button "Back" --defaultno --backtitle $WHIP_BACKTITLE 12 70 setvar CHOICE = ""$? if (( $CHOICE == 0 )) { sed -i '/max_usb_current=/c\max_usb_current=0' /DietPi/config.txt setvar REBOOT_REQUIRED = '1' } #Disabled } elif (( $usb_max_current_enabled == 0 )) { setvar WHIP_QUESTION = "" Current setting: $rpi_usbmaxcurrent_text (0.6AMP) \n Would you like to enable this setting ? \n \n Once Enabled: \n - Max USB current will be set to 1.2AMP.\n - Shared by all USB ports."" whiptail --title $WHIP_TITLE --yesno $WHIP_QUESTION --yes-button "Ok" --no-button "Back" --defaultno --backtitle $WHIP_BACKTITLE 14 70 setvar CHOICE = ""$? if (( $CHOICE == 0 )) { sed -i '/max_usb_current=/c\max_usb_current=1' /DietPi/config.txt setvar REBOOT_REQUIRED = '1' } } #Return to This Menu setvar TARGETMENUID = '3' } elif test $OPTION = "I2c state" { if (( $rpi_i2c_enabled == 0 )) { /DietPi/dietpi/func/dietpi-set_hardware i2c enable setvar REBOOT_REQUIRED = '1' } else { /DietPi/dietpi/func/dietpi-set_hardware i2c disable setvar REBOOT_REQUIRED = '1' } #Return to This Menu setvar TARGETMENUID = '3' } elif test $OPTION = "I2c frequency" { #remove kHz from current setvar rpi_i2cbaudrate_hz = $(echo -e "$rpi_i2cbaudrate_hz" | tr -d ' kHz') setvar OPTION = $(whiptail --inputbox "Please enter the required i2c baudrate frequency (kHz)." 8 60 "$rpi_i2cbaudrate_hz" --title "i2c baudrate frequency (kHz)" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { #check valid int if [[ $OPTION =~ ^-?[0-9]+$ ]] { /DietPi/dietpi/func/dietpi-set_hardware i2c $OPTION setvar REBOOT_REQUIRED = '1' } else { Info_Input_Not_Valid_Integer } } #Return to This Menu setvar TARGETMENUID = '3' } elif test $OPTION = "Serial console" { if (( $serialconsole_state == 0 )) { /DietPi/dietpi/func/dietpi-set_hardware serialconsole enable setvar REBOOT_REQUIRED = '1' } else { /DietPi/dietpi/func/dietpi-set_hardware serialconsole disable setvar REBOOT_REQUIRED = '1' } #Return to This Menu setvar TARGETMENUID = '3' } elif test $OPTION = "Bluetooth" { if (( $bluetooth_state )) { /DietPi/dietpi/func/dietpi-set_hardware bluetooth disable } else { /DietPi/dietpi/func/dietpi-set_hardware bluetooth enable } #Return to This Menu setvar TARGETMENUID = '3' } elif test $OPTION = "USB boot support" { if (( ! $rpi3_usb_boot_bit_enabled )) { setvar WHIP_QUESTION = ''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.\n\nNB:\n - Not all USB mass storage devices are supported\n - The HW bit which enables this setting is non-reversible\n\nDo you wish to enable USB mass storage boot support?'' whiptail --title $WHIP_TITLE --yesno $WHIP_QUESTION --yes-button "Ok" --no-button "Back" --defaultno --backtitle $WHIP_BACKTITLE 16 70 setvar CHOICE = ""$? if (( $CHOICE == 0 )) { /DietPi/dietpi/func/dietpi-set_hardware rpi3_usb_boot enable setvar REBOOT_REQUIRED = '1' # Reboot now? setvar WHIP_QUESTION = ''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?'' whiptail --title $WHIP_TITLE --yesno $WHIP_QUESTION --defaultno --backtitle $WHIP_BACKTITLE 14 75 setvar CHOICE = ""$? if (( $CHOICE == 0 )) { reboot } } } #Return to This Menu setvar TARGETMENUID = '3' } } } #TARGETMENUID=4 proc Menu_PerformanceOptions { setvar TARGETMENUID = '0' #All devices local current_cpu_governor=$(grep -m1 '^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' if test -f $fp_frequency_min_cpu_governor { setvar frequency_min_cpu_governor = $(( $(cat "$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' if test -f $fp_frequency_max_cpu_governor { setvar frequency_max_cpu_governor = $(( $(cat "$fp_frequency_max_cpu_governor") / 1000 )) } local arm_temp=$(G_OBTAIN_CPU_TEMP) local arm_temp_f='Unknown' if [[ $arm_temp =~ ^-?[0-9]+$ ]] { setvar arm_temp_f = ""$(( ( $arm_temp * 9 / 5 ) + 32 ))'f"" setvar arm_temp = ""'c"" } local memory_total=$(( $(cat /proc/meminfo | grep -m1 'MemTotal:' | awk '{print $2}') / 1000 )) local memory_free=$(( $(cat /proc/meminfo | grep -m1 'MemFree:' | awk '{print $2}') / 1000 )) local memory_usage=$(($memory_total - $memory_free)) #Create Menu List for Whiptail # - this will list the menu options available for each device. local whiptail_menu_array=() #Overclocking if (( $G_HW_MODEL < 10 )) { setvar whiptail_menu_array = ''("Overclocking" "Set Profile") } #CPU GOV setvar whiptail_menu_array = ''("Change CPU Governor" ": $current_cpu_governor") #Ondemand/Interactive Throttle up menu if test $current_cpu_governor = "ondemand" || test $current_cpu_governor = "conservative" || test $current_cpu_governor = "interactive" { local current_cpu_throttle_up=$(cat /DietPi/dietpi.txt | grep -m1 '^CONFIG_CPU_USAGE_THROTTLE_UP=' | sed 's/.*=//') setvar whiptail_menu_array = ''("CPU Throttle Up" ": $current_cpu_throttle_up%") } #Ondemand extras if test $current_cpu_governor = ondemand { local current_cpu_sample_rate=$(( $(cat /DietPi/dietpi.txt | grep -m1 '^CONFIG_CPU_ONDEMAND_SAMPLE_RATE=' | sed 's/.*=//') / 1000 )) #convert to ms setvar whiptail_menu_array = ''("Ondemand Sample Rate" ": $current_cpu_sample_rate ms") local current_cpu_down_factor=$(grep -m1 '^CONFIG_CPU_ONDEMAND_SAMPLE_DOWNFACTOR=' /DietPi/dietpi.txt | sed 's/.*=//') local current_cpu_down_factor_ms=$(( $current_cpu_down_factor * $current_cpu_sample_rate )) setvar whiptail_menu_array = ''("Ondemand Down Factor" ": $current_cpu_down_factor ($current_cpu_down_factor_ms ms)") } # User Scaling Max Freq limit. local user_frequency_max_current=$(cat /DietPi/dietpi.txt | grep -m1 '^CONFIG_CPU_MAX_FREQ=' | sed 's/.*=//') local user_frequency_max_text="$user_frequency_max_current MHz" if (( ! $user_frequency_max_current )) { setvar user_frequency_max_text = ""Disabled"" } setvar whiptail_menu_array = ''("CPU Max Freq Limit" ": $user_frequency_max_text") # User Scaling Min Freq limit. local user_frequency_min_current=$(cat /DietPi/dietpi.txt | grep -m1 '^CONFIG_CPU_MIN_FREQ=' | sed 's/.*=//') local user_frequency_min_text="$user_frequency_min_current MHz" if (( ! $user_frequency_min_current )) { setvar user_frequency_min_text = ""Disabled"" } setvar whiptail_menu_array = ''("CPU Min Freq Limit" ": $user_frequency_min_text") #RPi extras if (( $G_HW_MODEL < 10 )) { local current_arm_temp_limit=$(cat /DietPi/config.txt | grep -m1 'temp_limit' | sed 's/.*=//') local current_initial_turbo=$(cat /DietPi/config.txt | grep -m1 'initial_turbo' | sed 's/.*=//') local text_current_initial_turbo="$current_initial_turbo seconds" if (( $current_initial_turbo == 0 )) { setvar text_current_initial_turbo = ""Disabled"" } setvar whiptail_menu_array = ''("ARM Initial Turbo" ": $text_current_initial_turbo") setvar whiptail_menu_array = ''("ARM Temp Limit " ": $current_arm_temp_limit 'c") #Min freqs local rpi_freq_min_enabled=1 local rpi_freq_min_text="Enabled" if (( $(cat /DietPi/config.txt | grep -ci -m1 '#arm_freq_min=') == 1 )) { setvar rpi_freq_min_enabled = '0' setvar rpi_freq_min_text = ""Disabled"" } ##Disabled due to https://github.com/Fourdee/DietPi/issues/73 #whiptail_menu_array+=("Lower Idle Frequencies" ": $rpi_freq_min_text") } setvar WHIP_TITLE = ''DietPi - Performance Options'' setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu " Hardware : $G_HW_MODEL_DESCRIPTION \n ARM Temp: $arm_temp : $arm_temp_f\n RAM: $memory_total MB | Used: $memory_usage MB | Free: $memory_free MB" --cancel-button "$TEXT_MENU_BACK" --backtitle "$WHIP_BACKTITLE" 18 60 8 "${whiptail_menu_array[@]}" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? #delete[] array unset whiptail_menu_array if (( $CHOICE == 0 )) { case (OPTION) { "Ondemand Down Factor"* { setvar MIN_VALUE = '1' setvar MAX_VALUE = '200' setvar OPTION = $(whiptail --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." 17 70 "$current_cpu_down_factor" --title "$OPTION" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { if [[ $OPTION =~ ^-?[0-9]+$ ]] && (($OPTION <= $MAX_VALUE)) && (($OPTION >= $MIN_VALUE)) { sed -i "/CONFIG_CPU_ONDEMAND_SAMPLE_DOWNFACTOR=/c\CONFIG_CPU_ONDEMAND_SAMPLE_DOWNFACTOR=$OPTION" /DietPi/dietpi.txt #Apply changes /DietPi/dietpi/dietpi-cpu_set } else { Info_Input_Not_Valid_Integer } } #Return to this menu setvar TARGETMENUID = '4' } "Ondemand Sample Rate"* { local index=0 local input_fp=( '/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=0; i<${#input_fp[@]}; i++)) do if [ -f "${input_fp[$i]}" ]; then index=$i break fi done setvar MIN_VALUE = $(( $(cat "${input_fp[$index]}") / 1000 )) setvar MAX_VALUE = '300' setvar OPTION = $(whiptail --inputbox "Sample rate in miliseconds, 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" 10 70 "$current_cpu_sample_rate" --title "$OPTION (ms)" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { if [[ $OPTION =~ ^-?[0-9]+$ ]] && (($OPTION <= $MAX_VALUE)) && (($OPTION >= $MIN_VALUE)) { sed -i "/CONFIG_CPU_ONDEMAND_SAMPLE_RATE=/c\CONFIG_CPU_ONDEMAND_SAMPLE_RATE=$(($OPTION * 1000))" /DietPi/dietpi.txt #Apply changes /DietPi/dietpi/dietpi-cpu_set } else { Info_Input_Not_Valid_Integer } } unset input_fp #Return to this menu setvar TARGETMENUID = '4' } "Lower Idle Frequencies"* { setvar WHIP_QUESTION = ""Toggle the use of lower idle frequencies for CPU, CORE and RAM.\n\nAs the lower frequencies are active only when the device is idle, enabling this feature allows for potential power saving without impacting performance.\n\nCurrent Setting: $rpi_freq_min_text\n\nEnable: (Allows for potential power saving)\nSets arm_freq_min=100, core_freq_min=75 and sdram_freq_min=200.\n\nDisable: (Default)\nSets arm_freq_min=700, core_freq_min=250 and sdram_freq_min=400."" local whiptail_menu_array=() setvar whiptail_menu_array = ''("Enable" "Lowers the idle frequencies for CPU, CORE, RAM.") setvar whiptail_menu_array = ''("Disable" "Returns the idle frequencies to defaults.") setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu "$WHIP_QUESTION" --cancel-button "$TEXT_MENU_BACK" --backtitle "$WHIP_BACKTITLE" 22 75 2 "${whiptail_menu_array[@]}" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? #delete[] array unset whiptail_menu_array if (( $CHOICE == 0 )) { if test $OPTION = "Enable" { sed -i "/arm_freq_min=/c\arm_freq_min=100" /DietPi/config.txt sed -i "/core_freq_min=/c\core_freq_min=75" /DietPi/config.txt sed -i "/sdram_freq_min=/c\sdram_freq_min=200" /DietPi/config.txt } else { sed -i "/arm_freq_min=/c\#arm_freq_min=700" /DietPi/config.txt sed -i "/core_freq_min=/c\#core_freq_min=250" /DietPi/config.txt sed -i "/sdram_freq_min=/c\#sdram_freq_min=400" /DietPi/config.txt } setvar REBOOT_REQUIRED = '1' } #Return to This Menu setvar TARGETMENUID = '4' } "CPU Max Freq Limit"* { /DietPi/dietpi/dietpi-cpuinfo 2 if test ! -f /tmp/dietpi-available_cpu_freqs { whiptail --title "Not Available" --msgbox "Your processor / kernel, does not support this feature.\n\n(Info): Scaling_available_frequencies does not exist." --backtitle $WHIP_BACKTITLE 10 65 } else { local whiptail_menu_list=() local max_clock=0 local available_frequency_array=() readarray available_frequency_array < /tmp/dietpi-available_cpu_freqs for ((i=0; i<${#available_frequency_array[@]}; i++)) do whiptail_menu_list+=("$(( ${available_frequency_array[$i]} / 1000 ))" "MHz") if (( ${available_frequency_array[$i]} > $max_clock )); then max_clock=$(( ${available_frequency_array[$i]} / 1000 )) fi done #Add disable option setvar whiptail_menu_list = ''("Disabled" "Returns clocks to default") #Run menu setvar OPTION = $(whiptail --title "$WHIP_TITLE" --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" --cancel-button "Back" --backtitle "$WHIP_BACKTITLE" --default-item "$user_frequency_max_current" 18 65 7 "${whiptail_menu_list[@]}" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { # Set max > return to default if test $OPTION = "Disabled" { sed -i "/CONFIG_CPU_MAX_FREQ=/c\CONFIG_CPU_MAX_FREQ=$max_clock" /DietPi/dietpi.txt /DietPi/dietpi/dietpi-cpu_set } sed -i "/CONFIG_CPU_MAX_FREQ=/c\CONFIG_CPU_MAX_FREQ=$OPTION" /DietPi/dietpi.txt /DietPi/dietpi/dietpi-cpu_set } #delete[] arrays unset whiptail_menu_list unset available_frequency_array } #Return to This Menu setvar TARGETMENUID = '4' } "CPU Min Freq Limit"* { /DietPi/dietpi/dietpi-cpuinfo 2 if test ! -f /tmp/dietpi-available_cpu_freqs { whiptail --title "Not Available" --msgbox "Your processor / kernel, does not support this feature.\n\n(Info): Scaling_available_frequencies does not exist." --backtitle $WHIP_BACKTITLE 10 65 } else { local whiptail_menu_list=() local min_clock=0 local available_frequency_array=() readarray available_frequency_array < /tmp/dietpi-available_cpu_freqs for ((i=0; i<${#available_frequency_array[@]}; i++)) do whiptail_menu_list+=("$(( ${available_frequency_array[$i]} / 1000 ))" "MHz") done setvar min_clock = $(( ${available_frequency_array[0]} / 1000 )) #Add disable option setvar whiptail_menu_list = ''("Disabled" "Returns clocks to default") #Run menu setvar OPTION = $(whiptail --title "$WHIP_TITLE" --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" --cancel-button "Back" --backtitle "$WHIP_BACKTITLE" --default-item "$user_frequency_min_current" 18 65 7 "${whiptail_menu_list[@]}" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { # Set min > return to default if test $OPTION = "Disabled" { sed -i "/CONFIG_CPU_MIN_FREQ=/c\CONFIG_CPU_MIN_FREQ=$min_clock" /DietPi/dietpi.txt /DietPi/dietpi/dietpi-cpu_set } sed -i "/CONFIG_CPU_MIN_FREQ=/c\CONFIG_CPU_MIN_FREQ=$OPTION" /DietPi/dietpi.txt /DietPi/dietpi/dietpi-cpu_set } #delete[] arrays unset whiptail_menu_list unset available_frequency_array } #Return to This Menu setvar TARGETMENUID = '4' } "Overclocking"* { setvar TARGETMENUID = '13' } "Change CPU Governor"* { # - Scaling govs not available if test ! -f $FP_CPU_SCALING_GOV { whiptail --title "Not Available" --msgbox "Your processor, or kernel, does not support this feature.\n\n(Info): scaling_available_governors does not exist." --backtitle $WHIP_BACKTITLE 10 65 # - Obtain available Govs. Setup their menu and description. } else { local Description="Change CPU Governor:" local whiptail_menu_array=() if (( $(cat "$FP_CPU_SCALING_GOV" | grep -ci -m1 'ondemand') == 1 )) { setvar whiptail_menu_array = ''("ondemand" "Scales CPU frequency between $frequency_min_cpu_governor MHz and $frequency_max_cpu_governor MHz.") setvar Description = ""\nOndemand | Dynamic CPU frequency based on usage (recommended)."" } if (( $(cat "$FP_CPU_SCALING_GOV" | grep -ci -m1 'interactive') == 1 )) { setvar whiptail_menu_array = ''("interactive" "Scales CPU frequency between $frequency_min_cpu_governor MHz and $frequency_max_cpu_governor MHz.") setvar Description = ""\nInteractive | Dynamic CPU frequency based on usage."" } if (( $(cat "$FP_CPU_SCALING_GOV" | grep -ci -m1 'conservative') == 1 )) { setvar whiptail_menu_array = ''("conservative" "Scales CPU frequency between $frequency_min_cpu_governor MHz and $frequency_max_cpu_governor MHz.") setvar Description = ""\nConservative | Same as ondemand. Bias towards powersaving, slower scaling. "" } if (( $(cat "$FP_CPU_SCALING_GOV" | grep -ci -m1 'powersave') == 1 )) { setvar whiptail_menu_array = ''("powersave" "Limits CPU frequency to $frequency_min_cpu_governor MHz.") setvar Description = ""\nPowersave | Static. Reduces energy consumption, heat, performance."" } if (( $(cat "$FP_CPU_SCALING_GOV" | grep -ci -m1 'performance') == 1 )) { setvar whiptail_menu_array = ''("performance" "Forces CPU frequency to $frequency_max_cpu_governor MHz.") setvar Description = ""\nPerformance | Static. Increases energy consumption, heat, performance."" } setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu "$Description" --cancel-button "$TEXT_MENU_BACK" --backtitle "$WHIP_BACKTITLE" --default-item "$current_cpu_governor" 18 80 5 "${whiptail_menu_array[@]}" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? #delete[] array unset whiptail_menu_array if (( $CHOICE == 0 )) { sed -i "/CONFIG_CPU_GOVERNOR=/c\CONFIG_CPU_GOVERNOR=$OPTION" /DietPi/dietpi.txt /DietPi/dietpi/dietpi-cpu_set } } #Return to This Menu setvar TARGETMENUID = '4' } "CPU Throttle Up"* { setvar MIN_VALUE = '30' setvar MAX_VALUE = '95' setvar OPTION = $(whiptail --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%" 10 70 "$current_cpu_throttle_up" --title "CPU Throttle Up %" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { if [[ $OPTION =~ ^-?[0-9]+$ ]] && (($OPTION <= $MAX_VALUE)) && (($OPTION >= $MIN_VALUE)) { sed -i "/CONFIG_CPU_USAGE_THROTTLE_UP=/c\CONFIG_CPU_USAGE_THROTTLE_UP=$OPTION" /DietPi/dietpi.txt #Apply changes /DietPi/dietpi/dietpi-cpu_set } else { Info_Input_Not_Valid_Integer } } #Return to this menu setvar TARGETMENUID = '4' } "ARM Initial Turbo"* { setvar MIN_VALUE = '0' setvar MAX_VALUE = '60' setvar OPTION = $(whiptail --inputbox "Activates turbo mode during boot ($frequency_max_cpu_governor MHz), for the duration of value in seconds. \n - Recommended value is 20 \n - Valid range $MIN_VALUE (disabled) - $MAX_VALUE" 12 60 "$current_initial_turbo" --title "ARM Initial Turbo Duration" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { if [[ $OPTION =~ ^-?[0-9]+$ ]] && (($OPTION <= $MAX_VALUE)) && (($OPTION >= $MIN_VALUE)) { sed -i "/initial_turbo=/c\initial_turbo=$OPTION" /DietPi/config.txt setvar REBOOT_REQUIRED = '1' } else { Info_Input_Not_Valid_Integer } } #Return to this menu setvar TARGETMENUID = '4' } "ARM Temp Limit"* { setvar MIN_VALUE = '45' setvar MAX_VALUE = '85' setvar OPTION = $(whiptail --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" 11 60 "$current_arm_temp_limit" --title "ARM Temprature Limit" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { if [[ $OPTION =~ ^-?[0-9]+$ ]] && (($OPTION <= $MAX_VALUE)) && (($OPTION >= $MIN_VALUE)) { if (( $OPTION > 65 )) { whiptail --title "Warning: $OPTION 'c" --msgbox "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/Fourdee/DietPi/issues/356" 14 70 } sed -i "/temp_limit=/c\temp_limit=$OPTION" /DietPi/config.txt setvar REBOOT_REQUIRED = '1' } else { Info_Input_Not_Valid_Integer } } #Return to this menu setvar TARGETMENUID = '4' } } } } proc Change_Password { local PasswordRecieved=0 #1st input local passw1=$(whiptail --passwordbox "Please Enter Your New Password" 8 60 --title "Change PW" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { ((PasswordRecieved++)) } #2nd input (confirm) local passw2=$(whiptail --passwordbox "Please Confirm Your New Password" 8 60 --title "Confirm PW" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { ((PasswordRecieved++)) } #Password Mismatch if test $passw1 != $passw2 { setvar WHIP_TITLE = ''Error - Password Mismatch'' whiptail --title $WHIP_TITLE --msgbox " The Passwords you have entered do not match, therefor, no changes have been applied. Please try again" 8 60 #Change password } elif (( $PasswordRecieved == 2 )) { echo -e "$passw1\n$passw1" | passwd -q root setvar WHIP_TITLE = ''Password Applied'' whiptail --title $WHIP_TITLE --msgbox " Your new password has successfully been applied." 8 60 #Aborted } else { setvar WHIP_TITLE = ''Password Aborted'' whiptail --title $WHIP_TITLE --msgbox " Password change has been aborted. No changes have been applied" 8 60 } } proc Change_Hostname { #Get existing Hostname local hostname_existing=$(cat /etc/hostname) setvar OPTION = $(whiptail --inputbox "Enter Your New Hostname" 8 60 "$hostname_existing" --title "Change Hostname" --backtitle "$WHIP_BACKTITLE" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) && test $hostname_existing != $OPTION { /DietPi/dietpi/func/change_hostname $OPTION setvar REBOOT_REQUIRED = '1' setvar WHIP_TITLE = ''Hostname Change Completed'' # Reboot now? whiptail --title $WHIP_TITLE --yesno "Your Hostname has been changed: \n - From $hostname_existing \n - To $OPTION\n\nA reboot now is highly recommended for hostname change, and, before continuing with any further changes.\n\nWould you like to reboot now?" --defaultno --backtitle $WHIP_BACKTITLE 14 75 setvar CHOICE = ""$? if (( $CHOICE == 0 )) { reboot } #Aborted } else { setvar WHIP_TITLE = ''Hostname Change Aborted'' whiptail --title $WHIP_TITLE --msgbox "Hostname change has been aborted. No changes have been applied." 8 60 } } #TARGETMENUID=5 proc Menu_SecurityOptions { setvar TARGETMENUID = '0' setvar WHIP_TITLE = ''DietPi - Security Options'' setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu " Lock down your DietPi Install" --cancel-button "$TEXT_MENU_BACK" --backtitle "$WHIP_BACKTITLE" 12 60 2 \ "1" "Change Root Password" \ "2" "Change Hostname" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { if (( $OPTION == 1 )) { Change_Password setvar TARGETMENUID = '5' } elif (( $OPTION == 2 )) { Change_Hostname setvar TARGETMENUID = '5' } } } #TARGETMENUID=6 proc Menu_GpumemoryOptions { setvar TARGETMENUID = '1' #Get Current MemorySplit Settings and Data local gpu_mem_current=0 local ram_mem_current=0 local ram_mem_total=0 if (( $G_HW_MODEL == 0 )) { setvar gpu_mem_current = $(grep -m1 'gpu_mem_256=' /DietPi/config.txt | sed 's/.*=//') setvar ram_mem_current = $((256-gpu_mem_current)) setvar ram_mem_total = '256' } elif (( $G_HW_MODEL == 1 )) { setvar gpu_mem_current = $(grep -m1 'gpu_mem_512=' /DietPi/config.txt | sed 's/.*=//') setvar ram_mem_current = $((512-gpu_mem_current)) setvar ram_mem_total = '512' } elif (( $G_HW_MODEL == 2 )) || (( $G_HW_MODEL == 3 )) { setvar gpu_mem_current = $(grep -m1 'gpu_mem_1024=' /DietPi/config.txt | sed 's/.*=//') setvar ram_mem_current = $((1024-gpu_mem_current)) setvar ram_mem_total = '1024' } elif (( $G_HW_MODEL == 10 )) { setvar ram_mem_current = $(free -m | grep -m1 'Mem:' | awk '{print $2}') setvar gpu_mem_current = $((1024-ram_mem_current)) } elif (( $G_HW_MODEL == 12 )) { setvar ram_mem_current = $(free -m | grep -m1 'Mem:' | awk '{print $2}') setvar gpu_mem_current = $((2048-ram_mem_current)) } setvar WHIP_TITLE = ''DietPi - GPU/RAM Split'' #RPi's if (( $G_HW_MODEL < 10 )) { #Create array for storing menu selectable options. local -a option_name=( "Server" "Desktop" "Kodi" "Gaming" ) #Create array for storing available GPU values local -i available_gpu_values=( 16 64 128 128 ) if (( $G_HW_MODEL == 0 )) { echo -e "As above, array is defaulted to RPi1 - 256mb" &> /dev/null } elif (( $G_HW_MODEL == 1 )) { setvar available_gpu_values[2]=128 setvar available_gpu_values[3]=192 } elif (( $G_HW_MODEL == 2 )) || (( $G_HW_MODEL == 3 )) { setvar available_gpu_values[1]=128 setvar available_gpu_values[2]=192 setvar available_gpu_values[3]=256 } #Generate text array list for whiptail local option_output_text=() for ((i=0; i<${#option_name[@]}; i++)) do option_output_text+=("${option_name[$i]}" "${available_gpu_values[$i]} MB GPU | $((ram_mem_total - ${available_gpu_values[$i]})) MB RAM") done setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu " Hardware : $G_HW_MODEL_DESCRIPTION \n Current: $gpu_mem_current MB GPU | $ram_mem_current MB RAM" --cancel-button "$TEXT_MENU_BACK" --backtitle "$WHIP_BACKTITLE" 14 75 4 "${option_output_text[@]}" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { #Obtain the selected array index value by matching Option with Option Name for ((i=0; i<${#option_name[@]}; i++)) do if [ "$OPTION" = "${option_name[$i]}" ]; then local temp_index=$i break fi done # Apply /DietPi/dietpi/func/dietpi-set_hardware gpumemsplit ${available_gpu_values[$temp_index]} setvar REBOOT_REQUIRED = '1' #Return to this menu setvar TARGETMENUID = '6' } #delete [] array unset option_output_text unset option_name unset available_gpu_values #Odroid C1 } elif (( $G_HW_MODEL == 10 )) { #Odroid HDMI/headless extra data local display_output_enabled=$(cat /DietPi/boot.ini | grep -ci -m1 '^setenv hdmioutput "1"') local display_vpu_enabled=$(cat /DietPi/boot.ini | grep -ci -m1 '^setenv vpu "1"') local display_output_text="Enabled" local display_vpu_text="Enabled" if (( $display_output_enabled == 0 )) { setvar display_output_text = ""Disabled"" } if (( $display_vpu_enabled == 0 )) { setvar display_vpu_text = ""Disabled"" } setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu " Hardware : $G_HW_MODEL_DESCRIPTION \n Current : 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." --cancel-button "$TEXT_MENU_BACK" --backtitle "$WHIP_BACKTITLE" 15 70 3 \ "Headless" "HDMI: Disabled | VPU: Disabled" \ "Server" "HDMI: Enabled | VPU: Disabled" \ "Desktop" "HDMI: Enabled | VPU: Enabled" 3>&1 1>&2 2>&3) case (OPTION) { Headless { sed -i '/setenv hdmioutput /c\setenv hdmioutput "0"' /DietPi/boot.ini sed -i '/setenv vpu /c\setenv vpu "0"' /DietPi/boot.ini setvar REBOOT_REQUIRED = '1' #Return to this menu setvar TARGETMENUID = '6' } Server { sed -i '/setenv hdmioutput /c\setenv hdmioutput "1"' /DietPi/boot.ini sed -i '/setenv vpu /c\setenv vpu "0"' /DietPi/boot.ini setvar REBOOT_REQUIRED = '1' #Return to this menu setvar TARGETMENUID = '6' } Desktop { sed -i '/setenv hdmioutput /c\setenv hdmioutput "1"' /DietPi/boot.ini sed -i '/setenv vpu /c\setenv vpu "1"' /DietPi/boot.ini setvar REBOOT_REQUIRED = '1' #Return to this menu setvar TARGETMENUID = '6' } } #C2 } elif (( $G_HW_MODEL == 12 )) { #Odroid HDMI/headless extra data local display_output_enabled=$(cat /DietPi/boot.ini | grep -ci -m1 '^setenv nographics "0"') local display_output_text="Enabled" if (( $display_output_enabled == 0 )) { setvar display_output_text = ""Disabled"" } setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu " Hardware : $G_HW_MODEL_DESCRIPTION \n Current : 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." --cancel-button "$TEXT_MENU_BACK" --backtitle "$WHIP_BACKTITLE" 14 70 2 \ "Headless" "HDMI: Disabled | VPU: Disabled | +300MB RAM" \ "Default" "HDMI: Enabled | VPU: Enabled | -300MB RAM" 3>&1 1>&2 2>&3) case (OPTION) { Headless { sed -i '/setenv nographics /c\setenv nographics "1"' /DietPi/boot.ini setvar REBOOT_REQUIRED = '1' #Return to this menu setvar TARGETMENUID = '6' } Default { sed -i '/setenv nographics /c\setenv nographics "0"' /DietPi/boot.ini setvar REBOOT_REQUIRED = '1' #Return to this menu setvar TARGETMENUID = '6' } } } else { Info_HW_OptionNotSupported } } #TARGETMENUID=7 proc Menu_LanguageOptions { setvar TARGETMENUID = '0' setvar WHIP_TITLE = ''DietPi - Language and Regional Options'' setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu "Please select an option:" --cancel-button "$TEXT_MENU_BACK" --backtitle "$WHIP_BACKTITLE" 12 60 3 \ "Locale" "Change Language and Regional Settings" \ "Timezone" "Change Timezone Location Setting" \ "Keyboard" "Change Keyboard Layout Setting" 3>&1 1>&2 2>&3) case (OPTION) { Locale { setvar REBOOT_REQUIRED = '1' dpkg-reconfigure locales local locale_new=$(grep -m1 '^LANG=' /etc/default/locale | sed 's/.*=//') # Sanity, No result, revert back to default if test -z $locale_new { setvar locale_new = ''en_GB.UTF-8'' } # - Re-apply locale + auto install en_GB.UTF-8 alongside /DietPi/dietpi/func/dietpi-set_software locale $locale_new #Return to this menu setvar TARGETMENUID = '7' } Timezone { setvar REBOOT_REQUIRED = '1' dpkg-reconfigure tzdata #Return to this menu setvar TARGETMENUID = '7' } Keyboard { setvar REBOOT_REQUIRED = '1' #Keyboard must be plugged in for this to bring up the menu.. whiptail --title "DietPi keyboard-configuration" --msgbox "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 ;)" --backtitle $WHIP_BACKTITLE 12 65 dpkg-reconfigure keyboard-configuration invoke-rc.d keyboard-setup start #Return to this menu setvar TARGETMENUID = '7' } } } setvar ETH_IP_STATIC = ""0.0.0.0"" setvar ETH_GATEWAY_STATIC = ""0.0.0.0"" setvar ETH_MASK_STATIC = ""0.0.0.0"" setvar ETH_DNS_STATIC = ""0.0.0.0"" setvar ETH_INDEX = '0' setvar ETH_DISABLED = '0' setvar ETH_HARDWARE = '0' setvar ETH_CONNECTED = '0' setvar ETH_IP = ""0.0.0.0"" setvar ETH_GATEWAY = ""0.0.0.0"" setvar ETH_MASK = ""0.0.0.0"" setvar ETH_DNS = ""0.0.0.0"" setvar ETH_MODE = '1' #0=static 1=dhcp setvar ETH_MODE_TARGET = '0' setvar WIFI_IP_STATIC = ""0.0.0.0"" setvar WIFI_GATEWAY_STATIC = ""0.0.0.0"" setvar WIFI_MASK_STATIC = ""0.0.0.0"" setvar WIFI_DNS_STATIC = ""0.0.0.0"" setvar WIFI_INDEX = '0' setvar WIFI_DISABLED = '0' setvar WIFI_HARDWARE = '0' setvar WIFI_CONNECTED = '0' setvar WIFI_IP = ""0.0.0.0"" setvar WIFI_GATEWAY = ""0.0.0.0"" setvar WIFI_MASK = ""0.0.0.0"" setvar WIFI_DNS = ""0.0.0.0"" setvar WIFI_MODE = '1' #0=static 1=dhcp setvar WIFI_MODE_TARGET = '0' setvar WIFI_SSID = ""WifiSSID"" setvar WIFI_KEY = ""WifiKey"" setvar WIFI_BITRATE = '0' setvar WIFI_SIGNALSTRENGTH = '0' setvar WIFI_HOTSPOT = '0' setvar WIFI_COUNTRYCODE = ""Unknown"" setvar WIFI_AUTO_RECONNECT_ACTIVE = '0' proc Network_ETH_CopyCurrentToStatic { #Apply, Only if we have a connection if (( $ETH_CONNECTED == 1 )) { setvar ETH_IP_STATIC = "$ETH_IP" setvar ETH_GATEWAY_STATIC = "$ETH_GATEWAY" setvar ETH_MASK_STATIC = "$ETH_MASK" setvar ETH_DNS_STATIC = "$ETH_DNS" } } proc Network_WIFI_CopyCurrentToStatic { #Apply, Only if we have a connection if (( $WIFI_CONNECTED == 1 )) { setvar WIFI_IP_STATIC = "$WIFI_IP" setvar WIFI_GATEWAY_STATIC = "$WIFI_GATEWAY" setvar WIFI_MASK_STATIC = "$WIFI_MASK" setvar WIFI_DNS_STATIC = "$WIFI_DNS" } } proc Network_Restart { #Stop all services (required for hotspot) /DietPi/dietpi/dietpi-services stop # Enable/Disable wifi modules # - enable if (( $WIFI_DISABLED == 0 )) { /DietPi/dietpi/func/dietpi-set_hardware wifimodules enable # - disable } else { /DietPi/dietpi/func/dietpi-set_hardware wifimodules disable } #Release all DHCP leases (too slow, quicker to allow router to decide leases) #dhclient -r #Drop Connections G_DIETPI-NOTIFY 2 "Dropping connections, please wait..." ifdown eth$ETH_INDEX &> /dev/null ifdown wlan$WIFI_INDEX &> /dev/null #Kill dhclient killall dhclient &> /dev/null #Restart Networking G_DIETPI-NOTIFY 2 'Restarting networking services, please wait...' systemctl daemon-reload systemctl restart networking #Manually bring up adapters (just incase) if (( $ETH_DISABLED == 0 )) { ifup eth$ETH_INDEX } if (( $WIFI_DISABLED == 0 )) { ifup wlan$WIFI_INDEX # disable power saving systemctl restart wifi_disable_powersave } #Stop all services (required for hotspot) /DietPi/dietpi/dietpi-services start #Update network data Network_GetData } proc Network_ApplyChanges { #Disable all adapters sed -i "/allow-hotplug eth/c\#allow-hotplug eth$ETH_INDEX" /etc/network/interfaces sed -i "/allow-hotplug wlan/c\#allow-hotplug wlan$WIFI_INDEX" /etc/network/interfaces #Enable adapters if (( $ETH_DISABLED == 0 )) { sed -i "/allow-hotplug eth/c\allow-hotplug eth$ETH_INDEX" /etc/network/interfaces } if (( $WIFI_DISABLED == 0 )) { sed -i "/allow-hotplug wlan/c\allow-hotplug wlan$WIFI_INDEX" /etc/network/interfaces } #Save STATIC/DHCP # - eth if (( $ETH_MODE_TARGET == 0 )) { #Change to STATIC sed -i "/iface eth/c\iface eth$ETH_INDEX inet static" /etc/network/interfaces } elif (( $ETH_MODE_TARGET == 1 )) { #Change to DHCP sed -i "/iface eth/c\iface eth$ETH_INDEX inet dhcp" /etc/network/interfaces } #Update Current Mode for network restart setvar ETH_MODE = "$ETH_MODE_TARGET" # - Wifi if (( $WIFI_MODE_TARGET == 0 )) { #Change to STATIC sed -i "/iface wlan/c\iface wlan$WIFI_INDEX inet static" /etc/network/interfaces } elif (( $WIFI_MODE_TARGET == 1 )) { #Change to DHCP sed -i "/iface wlan/c\iface wlan$WIFI_INDEX inet dhcp" /etc/network/interfaces } #Update Current Mode for network restart setvar WIFI_MODE = "$WIFI_MODE_TARGET" #dns-nameservers (If static IP. dns-nameservers MUST be enabled) # - Disable all sed -i 's/^dns-nameservers/#dns-nameservers/g' /etc/network/interfaces # - Enable eth if (( $ETH_DISABLED == 0 )) && (( $ETH_MODE == 0 )) { sed -i "$(cat -n /etc/network/interfaces | grep 'dns-nameservers ' | sed -n 1p | awk '{print $1}')s/^#dns-nameservers/dns-nameservers/g" /etc/network/interfaces } # - Enable Wifi if (( ! $WIFI_DISABLED )) && (( $WIFI_MODE == 0 )) { sed -i "$(cat -n /etc/network/interfaces | grep 'dns-nameservers ' | sed -n 2p | awk '{print $1}')s/^#dns-nameservers/dns-nameservers/g" /etc/network/interfaces } #Save Static IPs (not applied to # disabled lines) # - eth sed -i "$(cat -n /etc/network/interfaces | grep 'address ' | sed -n 1p | awk '{print $1}')s/address.*/address $ETH_IP_STATIC/" /etc/network/interfaces sed -i "$(cat -n /etc/network/interfaces | grep 'gateway ' | sed -n 1p | awk '{print $1}')s/gateway.*/gateway $ETH_GATEWAY_STATIC/" /etc/network/interfaces sed -i "$(cat -n /etc/network/interfaces | grep 'netmask ' | sed -n 1p | awk '{print $1}')s/netmask.*/netmask $ETH_MASK_STATIC/" /etc/network/interfaces sed -i "$(cat -n /etc/network/interfaces | grep 'dns-nameservers ' | sed -n 1p | awk '{print $1}')s/dns-nameservers.*/dns-nameservers $ETH_DNS_STATIC/" /etc/network/interfaces # - wifi | If not running in hotspot mode, as these are disabled in the file. if (( $WIFI_HOTSPOT == 0 )) { sed -i "$(cat -n /etc/network/interfaces | grep 'address ' | sed -n 2p | awk '{print $1}')s/address.*/address $WIFI_IP_STATIC/" /etc/network/interfaces sed -i "$(cat -n /etc/network/interfaces | grep 'gateway ' | sed -n 2p | awk '{print $1}')s/gateway.*/gateway $WIFI_GATEWAY_STATIC/" /etc/network/interfaces sed -i "$(cat -n /etc/network/interfaces | grep 'netmask ' | sed -n 2p | awk '{print $1}')s/netmask.*/netmask $WIFI_MASK_STATIC/" /etc/network/interfaces sed -i "$(cat -n /etc/network/interfaces | grep 'dns-nameservers ' | sed -n 2p | awk '{print $1}')s/dns-nameservers.*/dns-nameservers $WIFI_DNS_STATIC/" /etc/network/interfaces } #Save WiFi creds if (( $WIFI_HOTSPOT == 0 )) { # - Update globals sed -i "/^AUTO_SETUP_NET_WIFI_SSID=/c\AUTO_SETUP_NET_WIFI_SSID=$WIFI_SSID" /DietPi/dietpi.txt sed -i "/^AUTO_SETUP_NET_WIFI_KEY=/c\AUTO_SETUP_NET_WIFI_KEY=$WIFI_KEY" /DietPi/dietpi.txt # Open host if test -z $WIFI_KEY { sed -i '/AUTO_SETUP_NET_WIFI_KEYMGR=/c\AUTO_SETUP_NET_WIFI_KEYMGR=NONE' /DietPi/dietpi.txt # Key host #??? Can we check for WEP/WPA-PSK on the SSID and set accordingly? # WEP tests failed, dropping support as its outdated and not secure. WPA-PSK is recommended for router. } else { sed -i '/AUTO_SETUP_NET_WIFI_KEYMGR=/c\AUTO_SETUP_NET_WIFI_KEYMGR=WPA-PSK' /DietPi/dietpi.txt } # - Function apply /DietPi/dietpi/func/dietpi-set_hardware wificreds set } #restart net Network_Restart } proc Change_StaticIp { #Ethernet if (( $1 == 0 )) { setvar OPTION = $(whiptail --inputbox "Enter Your New Ip Address" 8 60 "$ETH_IP_STATIC" --title "Set Static Ip Address" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar ETH_IP_STATIC = "$OPTION" } #wifi } elif (( $1 == 1 )) { setvar OPTION = $(whiptail --inputbox "Enter Your New Ip Address" 8 60 "$WIFI_IP_STATIC" --title "Set Static Ip Address" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar WIFI_IP_STATIC = "$OPTION" } } } proc Change_StaticGateway { #Ethernet if (( $1 == 0 )) { setvar OPTION = $(whiptail --inputbox "Enter Your New Gateway Address" 8 60 "$ETH_GATEWAY_STATIC" --title "Set Static Gateway Address" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar ETH_GATEWAY_STATIC = "$OPTION" } #wifi } elif (( $1 == 1 )) { setvar OPTION = $(whiptail --inputbox "Enter Your New Gateway Address" 8 60 "$WIFI_GATEWAY_STATIC" --title "Set Static Gateway Address" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar WIFI_GATEWAY_STATIC = "$OPTION" } } } proc Change_StaticMask { #Ethernet if (( $1 == 0 )) { setvar OPTION = $(whiptail --inputbox "Enter Your New Mask Address" 8 60 "$ETH_MASK_STATIC" --title "Set Static Mask Address" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar ETH_MASK_STATIC = "$OPTION" } #wifi } elif (( $1 == 1 )) { setvar OPTION = $(whiptail --inputbox "Enter Your New Mask Address" 8 60 "$WIFI_MASK_STATIC" --title "Set Static Mask Address" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar WIFI_MASK_STATIC = "$OPTION" } } } proc Change_StaticDns { #$1 = Adapater type | 0=Eth, 1=WiFi #Store current into var local current_value=0 # - Ethernet if (( $1 == 0 )) { setvar current_value = "$ETH_DNS_STATIC" # - WiFi } elif (( $1 == 1 )) { setvar current_value = "$WIFI_DNS_STATIC" } local return_value=$current_value #Create Menu List for Whiptail local whiptail_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" ) setvar OPTION = $(whiptail --title "Choose DNS server" --menu "Please select a DNS server, or choose custom for manual entry." --default-item "$current_value" --cancel-button "$TEXT_MENU_BACK" --backtitle "$WHIP_BACKTITLE" 16 70 8 "${whiptail_menu_array[@]}" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { case (OPTION) { Custom { setvar OPTION = $(whiptail --inputbox "Enter Your DNS Server Address\n - 2 maximum, seperated by a space.\n - eg: 8.8.8.8 8.8.4.4" 10 60 "$current_value" --title "Set Static DNS Address" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar return_value = "$OPTION" } } * { setvar return_value = "$OPTION" } } } #delete [] unset whiptail_menu_array #Apply new value # - Ethernet if (( $1 == 0 )) { setvar ETH_DNS_STATIC = "$return_value" # - WiFi } elif (( $1 == 1 )) { setvar WIFI_DNS_STATIC = "$return_value" } } proc Change_WifiSsid { setvar OPTION = $(whiptail --inputbox "Enter the SSID name to connect to." 8 60 "$WIFI_SSID" --title "Set Your SSID" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar WIFI_SSID = "$OPTION" } } proc Change_WifiKey { setvar OPTION = $(whiptail --inputbox "Enter the Access Key (WPA/WEP)." 8 60 "$WIFI_KEY" --title "Set Your Access Key" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar WIFI_KEY = "$OPTION" } } proc Change_WifiCountryCode { local wifi_country_code_target=$WIFI_COUNTRYCODE local whiptail_menu_array=() setvar whiptail_menu_array = ''("GB" "Europe / Great Britain") setvar whiptail_menu_array = ''("US" "United States") setvar whiptail_menu_array = ''("JP" "Japan") setvar whiptail_menu_array = ''("CN" "China") setvar whiptail_menu_array = ''("Manual" "Enter a custom country code") local description_text="Choose a country, to enable WiFi channels and power ratings allowed in your country." setvar WHIP_TITLE = ''Change WiFi country code'' setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu "$description_text" --cancel-button "$TEXT_MENU_BACK" --backtitle "$WHIP_BACKTITLE" --default-item "$WIFI_COUNTRYCODE" 15 60 5 "${whiptail_menu_array[@]}" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? #delete [] unset whiptail_menu_array if (( $CHOICE == 0 )) { case (OPTION) { Manual { setvar OPTION = $(whiptail --inputbox "Please enter a 2 character country code: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2" 8 60 "$WIFI_COUNTRYCODE" --title "WiFi Country Code" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar wifi_country_code_target = "$OPTION" } } * { setvar wifi_country_code_target = "$OPTION" } } #Apply /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/Fourdee/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 setvar WIFI_COUNTRYCODE = $(iw reg get | grep -m1 'country' | awk '{print $2}' | tr -d ':') if test $WIFI_COUNTRYCODE != $wifi_country_code_target { whiptail --title "Error: Country Code" --msgbox "Country code ($wifi_country_code_target) could not been applied. Please check the country code and try again." --backtitle $WHIP_BACKTITLE 8 55 } } } proc Scan_Wifi { #Ensure adapater is up ifup wlan$WIFI_INDEX #Get all ssids clear echo -e "Scanning SSIDS, please wait...." echo -e "-------------------------------" iwlist wlan$WIFI_INDEX scan | grep ESSID: | sed 's/[ \t]*ESSID:"\(.*\)"/\1/' > /tmp/dietpi-config_temp #read file to array readarray wifi_ssid_array < /tmp/dietpi-config_temp #Create List with indexs for Whiptail local wifi_ssid_list=() for ((i=0; i<${#wifi_ssid_array[@]}; i++)) do wifi_ssid_list+=("$i" "${wifi_ssid_array[$i]}") done setvar WHIP_TITLE = ''DietPi-Config - Wifi SSID Scan'' setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu "Please select a Wifi SSID" --cancel-button "$TEXT_MENU_BACK" --backtitle "$WHIP_BACKTITLE" 14 60 6 "${wifi_ssid_list[@]}" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar WIFI_SSID = ${wifi_ssid_array[$OPTION]} Change_WifiKey Wifi_Reconnect } #Clean up tmp files rm /tmp/dietpi-config_temp &> /dev/null #delete[] arrays unset wifi_ssid_array unset wifi_ssid_list } proc Wifi_Reconnect { setvar WHIP_QUESTION = ""SSID: $WIFI_SSID \nKEY: $WIFI_KEY \n\nConnect now? \n\n(NOTICE) All WiFi connections will be dropped!"" whiptail --title $WHIP_TITLE --yesno $WHIP_QUESTION --yes-button "Ok" --no-button "Back" --defaultno --backtitle $WHIP_BACKTITLE 14 60 setvar CHOICE = ""$? if (( $CHOICE == 0 )) { #Apply Changes clear echo -e "Connecting to $WIFI_SSID , please wait" Network_ApplyChanges } } proc Ethernet_Reconnect { setvar WHIP_QUESTION = ""Do you wish to apply settings and reconnect network now? \n\n(NOTICE) All Ethernet connections will be dropped!"" whiptail --title $WHIP_TITLE --yesno $WHIP_QUESTION --yes-button "Ok" --no-button "Back" --defaultno --backtitle $WHIP_BACKTITLE 12 60 setvar CHOICE = ""$? if (( $CHOICE == 0 )) { #Apply Changes clear echo -e "Reconnecting Ethernet , please wait" Network_ApplyChanges } } setvar INTERNET_ONLINE = '0' # 0=not tested, 1=failed, 2=online setvar INTERNET_URL = ''http://mirrordirector.raspbian.org'' proc Network_CheckInternetConnection { setvar INTERNET_ONLINE = '0' #Not tested #Check for connection wget --spider --timeout=10 --tries=2 $INTERNET_URL if (( $? == 0 )) { setvar INTERNET_ONLINE = '2' #Online } else { setvar INTERNET_ONLINE = '1' #Failed } } proc 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 setvar ETH_IP_STATIC = $(cat -n /tmp/net_interfaces | grep 'address ' | sed -n 1p | awk '{print $3}') setvar ETH_GATEWAY_STATIC = $(cat -n /tmp/net_interfaces | grep 'gateway ' | sed -n 1p | awk '{print $3}') setvar ETH_MASK_STATIC = $(cat -n /tmp/net_interfaces | grep 'netmask ' | sed -n 1p | awk '{print $3}') setvar ETH_DNS_STATIC = $(cat -n /tmp/net_interfaces | grep 'dns-nameservers ' | sed -n 1p | awk '{print $3,$4}') setvar ETH_INDEX = $(sed -n 1p /DietPi/dietpi/.network) setvar ETH_DISABLED = $(cat /tmp/net_interfaces | grep -ci -m1 "#allow-hotplug eth$ETH_INDEX") setvar ETH_HARDWARE = '0' setvar ETH_CONNECTED = '0' setvar ETH_IP = ''0.0.0.0'' setvar ETH_GATEWAY = ''0.0.0.0'' setvar ETH_MASK = ''0.0.0.0'' setvar ETH_DNS = ''0.0.0.0'' setvar ETH_MODE = '1' setvar ETH_MODE_TARGET = "$ETH_MODE" setvar WIFI_IP_STATIC = $(cat -n /tmp/net_interfaces | grep 'address ' | sed -n 2p | awk '{print $3}') setvar WIFI_GATEWAY_STATIC = $(cat -n /tmp/net_interfaces | grep 'gateway ' | sed -n 2p | awk '{print $3}') setvar WIFI_MASK_STATIC = $(cat -n /tmp/net_interfaces | grep 'netmask ' | sed -n 2p | awk '{print $3}') setvar WIFI_DNS_STATIC = $(cat -n /tmp/net_interfaces | grep 'dns-nameservers ' | sed -n 2p | awk '{print $3,$4}') setvar WIFI_INDEX = $(sed -n 2p /DietPi/dietpi/.network) setvar WIFI_DISABLED = $(cat /tmp/net_interfaces | grep -ci -m1 "#allow-hotplug wlan$WIFI_INDEX") setvar WIFI_HARDWARE = '0' setvar WIFI_CONNECTED = '0' setvar WIFI_IP = ''0.0.0.0'' setvar WIFI_GATEWAY = ''0.0.0.0'' setvar WIFI_MASK = ''0.0.0.0'' setvar WIFI_DNS = ''0.0.0.0'' setvar WIFI_MODE = '1' setvar WIFI_MODE_TARGET = "$WIFI_MODE" setvar WIFI_SSID = ''MySuperDooperWiFi'' setvar WIFI_KEY = ''0123456789'' #Get extra wifi stats setvar WIFI_BITRATE = '0' setvar WIFI_SIGNALSTRENGTH = '0' # - Hotspot enabled? setvar WIFI_HOTSPOT = '0' if test -f /usr/sbin/hostapd { setvar WIFI_HOTSPOT = '1' } # - Prevent "nl80211 not found" message, when running this command with cfg80211 module disabled. #?????????????????????????????????????????????????????? # We cant rely on lsmod for this. Some of our images have cfg80211 built into kernel, so lsmod wont show a result. # Redirect stderr and stdout does nowt 2> /dev/null and &> /dev/null no effect. #if (( $(lsmod | grep -ci -m1 'cfg80211' ) )); then setvar WIFI_COUNTRYCODE = ''GB'' if test -n $(which iw) { setvar WIFI_COUNTRYCODE = $(iw reg get | grep -m1 'country' | awk '{print $2}' | tr -d ':') } #?????????????????????????????????????????????????????? #eth if test -d /sys/class/net/eth$ETH_INDEX { #Hardware setvar ETH_HARDWARE = '1' #Static or Dhcp? setvar ETH_MODE = $(cat /tmp/net_interfaces | grep -ci -m1 "iface eth$ETH_INDEX inet dhcp") setvar ETH_MODE_TARGET = "$ETH_MODE" #Connected and Valid IP? setvar ETH_CONNECTED = $(ip r | grep -ci -m1 "eth$ETH_INDEX") #Enabled and Connected if (( $ETH_DISABLED == 0 )) && (( $ETH_CONNECTED == 1 )) { setvar ETH_IP = $(ifconfig eth$ETH_INDEX | grep -m1 'inet' | awk '{ print $2 }' | sed 's/addr://g') setvar ETH_GATEWAY = $(ip r | grep -m1 'default' | awk '{ print $3 }') setvar ETH_MASK = $(ifconfig eth$ETH_INDEX | grep -m1 'inet' | awk '{ print $4 }' | sed 's/Mask://g') setvar ETH_DNS = $(grep -m1 'nameserver' /etc/resolv.conf | awk '{print $2}') } } if test -d /sys/class/net/wlan$WIFI_INDEX { #Hardware setvar WIFI_HARDWARE = '1' #Static or Dhcp? setvar WIFI_MODE = $(cat /tmp/net_interfaces | grep -ci -m1 "iface wlan$WIFI_INDEX inet dhcp") setvar WIFI_MODE_TARGET = "$WIFI_MODE" #Connected and Valid IP? setvar WIFI_CONNECTED = $(ip r | grep -ci -m1 "wlan$WIFI_INDEX") #Wifi Extras setvar WIFI_SSID = "$(grep -m1 '^AUTO_SETUP_NET_WIFI_SSID=' /DietPi/dietpi.txt | sed 's/.*=//')" setvar WIFI_KEY = "$(grep -m1 '^AUTO_SETUP_NET_WIFI_KEY=' /DietPi/dietpi.txt | sed 's/.*=//')" #Enabled and Connected if (( $WIFI_DISABLED == 0 )) && (( $WIFI_CONNECTED == 1 )) { setvar WIFI_IP = $(ifconfig wlan$WIFI_INDEX | grep -m1 'inet' | awk '{ print $2 }' | sed 's/addr://g') setvar WIFI_GATEWAY = $(ip r | grep -m1 'default' | awk '{ print $3 }') setvar WIFI_MASK = $(ifconfig wlan$WIFI_INDEX | grep -m1 'inet' | awk '{ print $4 }' | sed 's/Mask://g') setvar WIFI_DNS = $(cat /etc/resolv.conf | grep -m1 nameserver | awk '{print $2}') #Get extra wifi stats setvar WIFI_BITRATE = $(iwconfig wlan$WIFI_INDEX | grep -m1 'Bit Rate' | awk '{ print $2 }' | sed 's/Rate[:=]//g') setvar WIFI_SIGNALSTRENGTH = $(iwconfig wlan$WIFI_INDEX | grep -m1 'Signal level=' | awk '{ print $4 }' | sed 's/level=//g' | cut -f1 -d "/") # - try and detect if this is dBm (contains -) or % if [[ $WIFI_SIGNALSTRENGTH =~ ^-?[0-9]+$ ]] && (( $WIFI_SIGNALSTRENGTH < 0 )) { setvar WIFI_SIGNALSTRENGTH = ""$WIFI_SIGNALSTRENGTH dBm"" } else { setvar WIFI_SIGNALSTRENGTH = ""$WIFI_SIGNALSTRENGTH %"" } } } #cleanup tmp rm /tmp/net_interfaces &> /dev/null } #TARGETMENUID=8 proc Menu_NetworkAdapters { setvar TARGETMENUID = '0' #Check Network Network_GetData local whiptail_menu_array=() #Obtain enabled/disabled status local eth_disabled_text='Enabled' if (( $ETH_DISABLED == 1 )) { setvar eth_disabled_text = ''Disabled'' } local wlan_disabled_text='Enabled' if (( $WIFI_DISABLED == 1 )) { setvar wlan_disabled_text = ''Disabled'' } #Obtain Hardware Status local eth_hardware_text='Available' if (( ! $ETH_HARDWARE )) { setvar eth_hardware_text = ''Not Found'' } local wlan_hardware_text='Available' if (( ! $WIFI_HARDWARE )) { setvar wlan_hardware_text = ''Not Found'' } #Obtain Connected/Carrier Status local eth_connected_text='Disconnected' if (( $ETH_CONNECTED == 1 )) { setvar eth_connected_text = ''Connected'' } local wlan_connected_text='Disconnected' if (( $WIFI_CONNECTED == 1 )) { setvar wlan_connected_text = ''Connected'' if (( $WIFI_HOTSPOT == 1 )) { setvar wlan_connected_text = ""Wifi Hotspot Mode"" } } #Internet Connection Status local Internet_connected_text='Please run Internet Test' if (( $INTERNET_ONLINE == 2 )) { setvar Internet_connected_text = ''Online'' } elif (( $INTERNET_ONLINE == 1 )) { setvar Internet_connected_text = ''Offline / Failed'' } #Set to Not Tested for next loop setvar INTERNET_ONLINE = '0' #IPv6 status local ipv6_enabled=1 local ipv6_status_text='Enabled' if test ! -d /proc/sys/net/ipv6 { setvar ipv6_enabled = '0' setvar ipv6_status_text = ''Disabled'' } #Proxy settings (global vars, force an int to obtain current values stored in dietpi.txt) Load_Proxy_Vars local proxy_state_text='Disabled' if (( $PROXY_ENABLED == 1 )) { setvar proxy_state_text = ""Enabled | $PROXY_ADDRESS:$PROXY_PORT"" } # - Reset init flag. Ensures Menu_Proxy() reloads current settings. setvar PROXY_ENABLED = '-1' setvar whiptail_menu_array = ''("Ethernet" "Change Wired Network Settings") setvar whiptail_menu_array = ''("WiFi" "Change Wireless Network Settings") # - Onboard WiFi local onboard_wifi_enabled=1 # RPi 3/ZeroW if (( $HW_ONBOARD_WIFI == 1 )) { if test -f /etc/modprobe.d/disable_wifi_rpi3_onboard.conf { setvar onboard_wifi_enabled = '0' setvar whiptail_menu_array = ''("Onboard WiFi" "Disabled | select to toggle") } else { setvar whiptail_menu_array = ''("Onboard WiFi" "Enabled | select to toggle") } } setvar whiptail_menu_array = ''("IPv6" "Toggle IPv6 Support") setvar whiptail_menu_array = ''("Test" "Run the Internet Connection Test") setvar whiptail_menu_array = ''("Proxy" "Configure proxy settings") setvar WHIP_TITLE = ''DietPi - Network Options: Adapters'' setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu " \n Ethernet : $eth_hardware_text | $eth_disabled_text | $eth_connected_text \n Wifi : $wlan_hardware_text | $wlan_disabled_text | $wlan_connected_text\n IPv6 : $ipv6_status_text\n Internet : $Internet_connected_text\n Proxy : $proxy_state_text" --cancel-button "$TEXT_MENU_BACK" --backtitle "$WHIP_BACKTITLE" 19 65 6 "${whiptail_menu_array[@]}" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? unset whiptail_menu_array if (( $CHOICE == 0 )) { case (OPTION) { "Onboard WiFi" { if (( $onboard_wifi_enabled )) { /DietPi/dietpi/func/dietpi-set_hardware wifimodules onboard_disable } else { /DietPi/dietpi/func/dietpi-set_hardware wifimodules onboard_enable } setvar REBOOT_REQUIRED = '1' whiptail --title "Reboot required" --msgbox "NB: A reboot is required for the changes to take effect." --backtitle $WHIP_BACKTITLE 8 65 #Return to this Menu setvar TARGETMENUID = '8' } IPv6 { #Disable if (( $ipv6_enabled )) { whiptail --title "Disable IPv6?" --yesno "IPv6 is currently enabled. Would you like to disable it?\n\n - A system restart is required for settings to take effect.\n - Disabling IPv6 may break certain programs that rely on it." --yes-button "Ok" --no-button "Back" --defaultno --backtitle $WHIP_BACKTITLE 11 70 setvar CHOICE = ""$? if (( $CHOICE == 0 )) { if (( G_HW_ARCH == 10 )) { # On amd64 images, IPv6 is no kernel module, but can be disabled via grub: https://github.com/Fourdee/DietPi/issues/1343#issuecomment-359652751 if (( ! $(grep -ci -m1 'ipv6.disable=1' /etc/default/grub) )) { sed -i 's/GRUB_CMDLINE_LINUX_DEFAULT=\"/GRUB_CMDLINE_LINUX_DEFAULT=\"ipv6.disable=1 /g' /etc/default/grub update-grub } } else { # On all other images, IPv6 is a kernel module, which can be blacklisted. echo 'blacklist ipv6' > /etc/modprobe.d/99-dietpi-blacklist-ipv6.conf } # - APT force IPv4 echo 'Acquire::ForceIPv4 "true";' > /etc/apt/apt.conf.d/99-dietpi-force-ipv4 # - Wget prefer IPv4 grep -q '^[[:blank:]]*prefer-family =' /etc/wgetrc && sed -i '/^[[:blank:]]*prefer-family =/c\prefer-family = IPv4' /etc/wgetrc || grep -q '^[[:blank:]#;]*prefer-family =' /etc/wgetrc && sed -i '/^[[:blank:]#;]*prefer-family =/c\prefer-family = IPv4' /etc/wgetrc || echo 'prefer-family = IPv4' >> /etc/wgetrc setvar REBOOT_REQUIRED = '1' } #Enable } else { whiptail --title "Enable IPv6?" --yesno "IPv6 is currently disabled. Would you like to enable it?\n\n - NB: A system restart is required for settings to take effect." --yes-button "Ok" --no-button "Back" --defaultno --backtitle $WHIP_BACKTITLE 10 70 setvar CHOICE = ""$? if (( $CHOICE == 0 )) { if (( G_HW_ARCH == 10 )) { sed -i 's/ipv6.disable=1 //g' /etc/default/grub update-grub } else { rm /etc/modprobe.d/99-dietpi-blacklist-ipv6.conf &> /dev/null } # - APT allow IPv6 but do not force it: https://github.com/Fourdee/DietPi/issues/472#issuecomment-356444922 rm /etc/apt/apt.conf.d/99-dietpi-force-ipv4 &> /dev/null # - Wget prefer IPv6 grep -q '^[[:blank:]]*prefer-family =' /etc/wgetrc && sed -i '/^[[:blank:]]*prefer-family =/c\prefer-family = IPv6' /etc/wgetrc || grep -q '^[[:blank:]#;]*prefer-family =' /etc/wgetrc && sed -i '/^[[:blank:]#;]*prefer-family =/c\prefer-family = IPv6' /etc/wgetrc || echo 'prefer-family = IPv6' >> /etc/wgetrc setvar REBOOT_REQUIRED = '1' } } #Return to this Menu setvar TARGETMENUID = '8' } Ethernet { #No hardware found if (( ! $ETH_HARDWARE )) { setvar WHIP_TITLE = '' Error: No Ethernet Hardware was found.'' setvar WHIP_QUESTION = '' No Ethernet Hardware was found. You are most likely running a Pi Model A.'' whiptail --title $WHIP_TITLE --msgbox $WHIP_QUESTION --backtitle $WHIP_BACKTITLE 12 60 #Return to this Menu setvar TARGETMENUID = '8' #Disabled } elif (( $ETH_DISABLED )) { whiptail --title "Ethernet is Disabled" --yesno "Ethernet must be enabled before settings can be changed.\n\nWould you like to enable Ethernet now?\n - (NOTICE) Connections may drop!" --yes-button "Ok" --no-button "Back" --defaultno --backtitle $WHIP_BACKTITLE 12 60 setvar CHOICE = ""$? #Confirm action if (( $CHOICE == 0 )) { setvar ETH_DISABLED = '0' Network_ApplyChanges setvar TARGETMENUID = '9' } else { #Return to this Menu setvar TARGETMENUID = '8' } } else { setvar TARGETMENUID = '9' } } WiFi { #Disabled | Offer chance to enable (also enables wifi modules) if (( $WIFI_DISABLED )) { whiptail --title "WiFi is Disabled" --yesno "WiFi must be enabled before settings can be changed.\n\nWould you like to enable WiFi now? \n - (NOTICE) Connections may drop!" --yes-button "Ok" --no-button "Back" --defaultno --backtitle $WHIP_BACKTITLE 12 60 setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar WIFI_DISABLED = '0' Network_ApplyChanges } # Return to this Menu setvar TARGETMENUID = '8' # - No hardware found } elif (( ! $WIFI_HARDWARE )) { setvar WHIP_TITLE = '' Error: No Wifi Hardware was found. '' whiptail --title $WHIP_TITLE --yesno "No supported Wifi Hardware was found.\n\nWould you like to disable WiFi? \n - (NOTICE) Connections may drop!" --yes-button "Ok" --no-button "Back" --defaultno --backtitle $WHIP_BACKTITLE 12 60 setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar WIFI_DISABLED = '1' Network_ApplyChanges } #Return to this Menu setvar TARGETMENUID = '8' } else { setvar TARGETMENUID = '10' } } Test { #Request URL to test setvar OPTION = $(whiptail --inputbox "Press enter a URL address to test (eg: http://google.com)" 8 60 "$INTERNET_URL" --title "Internet Connection Test" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar INTERNET_URL = "$OPTION" Network_CheckInternetConnection } #Return to this Menu setvar TARGETMENUID = '8' } Proxy { setvar TARGETMENUID = '17' } } #Cancel } else { #Exit DietPi-Config on back to previous menu? if (( $EXITONBACK == 1 )) { #Return to this menu setvar TARGETMENUID = '8' Menu_Exit } } } #TARGETMENUID=9 proc Menu_NetworkAdapters_Ethernet { setvar TARGETMENUID = '8' # - Get current Mode details local mode_current='DHCP' if (( $ETH_MODE == 0 )) { setvar mode_current = ''STATIC'' } # - Target Details local mode_target='DHCP' if (( $ETH_MODE_TARGET == 0 )) { setvar mode_target = ''STATIC'' } local whip_options_total=0 local description_text='' local whiptail_menu_array=() setvar WHIP_TITLE = ''DietPi - Ethernet Network Options'' setvar whiptail_menu_array = ''("Change Mode" "$mode_target"); ((whip_options_total++)) # - show static options if (( $ETH_MODE_TARGET == 0 )) { setvar whiptail_menu_array = ''("Copy" "Copy Current address to Static"); ((whip_options_total++)) setvar whiptail_menu_array = ''("Static Ip" "$ETH_IP_STATIC"); ((whip_options_total++)) setvar whiptail_menu_array = ''("Static Mask" "$ETH_MASK_STATIC"); ((whip_options_total++)) setvar whiptail_menu_array = ''("Static Gateway" "$ETH_GATEWAY_STATIC"); ((whip_options_total++)) setvar whiptail_menu_array = ''("Static DNS" "$ETH_DNS_STATIC"); ((whip_options_total++)) } setvar whiptail_menu_array = ''("Disable" "Disable Ethernet adapter"); ((whip_options_total++)) setvar whiptail_menu_array = ''("Apply" "Save Changes (Restart Networking)"); ((whip_options_total++)) setvar description_text = "" Current Details: \n - Mode = $mode_current \n - Ip = $ETH_IP \n - Mask = $ETH_MASK\n - Gateway = $ETH_GATEWAY\n - DNS = $ETH_DNS"" if (( $whip_options_total > $WHIP_OPTIONS_MAX_DISPLAY )) { setvar whip_options_total = "$WHIP_OPTIONS_MAX_DISPLAY" } local description_line_count=$(( 7 + $(echo -e "$description_text" | wc -l) )) # 7 is the minimal height of whiptail with no data/entries setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu "$description_text" --cancel-button "$TEXT_MENU_BACK" --backtitle "$WHIP_BACKTITLE" --default-item "$WHIP_SELECTION_PREVIOUS" $(( $description_line_count + $whip_options_total )) 65 $whip_options_total "${whiptail_menu_array[@]}" 3>&1 1>&2 2>&3) #delete [] unset whiptail_menu_array setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar WHIP_SELECTION_PREVIOUS = "$OPTION" case (OPTION) { "Change Mode" { ((ETH_MODE_TARGET++)) if (( $ETH_MODE_TARGET >= 2 )) { setvar ETH_MODE_TARGET = '0' } #Return to this menu setvar TARGETMENUID = '9' } Disable { whiptail --title "Ethernet is Enabled" --yesno "Would you like to disable the Ethernet adapter?\n - (NOTICE) All Ethernet connections will be dropped." --yes-button "Ok" --no-button "Back" --defaultno --backtitle $WHIP_BACKTITLE 10 60 setvar CHOICE = ""$? #Confirm action if (( $CHOICE == 0 )) { setvar ETH_DISABLED = '1' Network_ApplyChanges setvar TARGETMENUID = '8' } else { #Return to this Menu setvar TARGETMENUID = '9' } } Apply { Ethernet_Reconnect #Return to this menu setvar TARGETMENUID = '9' } Copy { Network_ETH_CopyCurrentToStatic #Return to this menu setvar TARGETMENUID = '9' } "Static Ip" { Change_StaticIp 0 #Return to this menu setvar TARGETMENUID = '9' } "Static Gateway" { Change_StaticGateway 0 #Return to this menu setvar TARGETMENUID = '9' } "Static Mask" { Change_StaticMask 0 #Return to this menu setvar TARGETMENUID = '9' } "Static DNS" { Change_StaticDns 0 #Return to this menu setvar TARGETMENUID = '9' } } } } setvar HOTSPOT_SSID = """" setvar HOTSPOT_CHANNEL = """" setvar HOTSPOT_KEY = """" proc WiFi_Monitor_Disable { if test -f /etc/systemd/system/dietpi-wifi-monitor.service { systemctl stop dietpi-wifi-monitor.service rm /etc/systemd/system/dietpi-wifi-monitor.service rm /var/lib/dietpi/dietpi-wifi-monitor.sh systemctl daemon-reload } } proc WiFi_Monitor_Enable { cat <<< """ > /var/lib/dietpi/dietpi-wifi-monitor.sh #!/bin/bash { URL_PING="$WIFI_GATEWAY" ADAPTER="wlan$WIFI_INDEX" TICKRATE=10 while true do G_DIETPI-NOTIFY 2 "Checking connnection for: '$'ADAPTER" ping -I '$'ADAPTER -c 1 '$'URL_PING if (( '$'? != 0 )); then G_DIETPI-NOTIFY 2 "Detected connection loss: '$'ADAPTER. Reconnecting" ifdown "'$'ADAPTER" sleep 1 ifup "'$'ADAPTER" G_DIETPI-NOTIFY 0 'Completed' else G_DIETPI-NOTIFY 0 "Connection '$'ADAPTER" fi sleep '$'TICKRATE done exit 0 } """ > /var/lib/dietpi/dietpi-wifi-monitor.sh #!/bin/bash { URL_PING="$WIFI_GATEWAY" ADAPTER="wlan$WIFI_INDEX" TICKRATE=10 while true do G_DIETPI-NOTIFY 2 "Checking connnection for: \$ADAPTER" ping -I \$ADAPTER -c 1 \$URL_PING if (( \$? != 0 )); then G_DIETPI-NOTIFY 2 "Detected connection loss: \$ADAPTER. Reconnecting" ifdown "\$ADAPTER" sleep 1 ifup "\$ADAPTER" G_DIETPI-NOTIFY 0 'Completed' else G_DIETPI-NOTIFY 0 "Connection \$ADAPTER" fi sleep \$TICKRATE done exit 0 } _EOF_ chmod +x /var/lib/dietpi/dietpi-wifi-monitor.sh cat <<< """ > /etc/systemd/system/dietpi-wifi-monitor.service [Unit] Description=Monitors loss of WiFi connection and automatically reconnects After=network.target network-online.target [Service] Type=simple ExecStart=/bin/bash -c /var/lib/dietpi/dietpi-wifi-monitor.sh [Install] WantedBy=multi-user.target """ > /etc/systemd/system/dietpi-wifi-monitor.service [Unit] Description=Monitors loss of WiFi connection and automatically reconnects After=network.target network-online.target [Service] Type=simple ExecStart=/bin/bash -c /var/lib/dietpi/dietpi-wifi-monitor.sh [Install] WantedBy=multi-user.target _EOF_ systemctl daemon-reload systemctl enable dietpi-wifi-monitor.service systemctl start dietpi-wifi-monitor.service } #TARGETMENUID=10 proc Menu_NetworkAdapters_Wifi { setvar TARGETMENUID = '8' local whip_options_total=0 local description_text='' local whiptail_menu_array=() #WiFi Hotspot Menu if (( $WIFI_HOTSPOT == 1 )) { setvar WHIP_TITLE = ''DietPi - WiFi Hotspot'' # - Load current details into global vars, once. if test $HOTSPOT_SSID = "" { setvar HOTSPOT_SSID = $(cat /etc/hostapd/hostapd.conf | grep -m1 '^ssid=' | sed 's/.*=//') setvar HOTSPOT_CHANNEL = $(cat /etc/hostapd/hostapd.conf | grep -m1 '^channel=' | sed 's/.*=//') setvar HOTSPOT_KEY = $(cat /etc/hostapd/hostapd.conf | grep -m1 '^wpa_passphrase=' | sed 's/.*=//') } # toggle local hotspot_active_state=$(systemctl is-active hostapd | grep -ci -m1 'active' ) local hotspot_status_text='Online' local hotspot_active_state_text=': Enabled, select to turn off hotspot' if (( ! $hotspot_active_state )) { setvar hotspot_active_state_text = '': Disabled, select to turn on hotspot'' setvar hotspot_status_text = ''Offline'' } setvar whiptail_menu_array = ''("SSID" "Change the wireless hotspot name"); ((whip_options_total++)) setvar whiptail_menu_array = ''("Channel" "Change the wireless channel"); ((whip_options_total++)) setvar whiptail_menu_array = ''("Key" "Change the access key required to connect"); ((whip_options_total++)) setvar whiptail_menu_array = ''("State" ": $hotspot_active_state_text"); ((whip_options_total++)) setvar description_text = ""SSID : $HOTSPOT_SSID\nChannel : $HOTSPOT_CHANNEL\nKey : $HOTSPOT_KEY\nStatus : $hotspot_status_text"" #WiFi Menu } else { setvar WHIP_TITLE = ''DietPi - Wireless Network Options'' # - Get current Mode details local mode_current='DHCP' if (( $WIFI_MODE == 0 )) { setvar mode_current = ''STATIC'' } # - Target Details local mode_target='DHCP' if (( $WIFI_MODE_TARGET == 0 )) { setvar mode_target = ''STATIC'' } setvar whiptail_menu_array = ''("Scan" "Scan and Connect"); ((whip_options_total++)) setvar whiptail_menu_array = ''("Manual" "Manually Set Wireless Details"); ((whip_options_total++)) if (( $WIFI_CONNECTED || $(systemctl is-active dietpi-wifi-monitor.service | grep -ci -m1 '^active') )) { local wifi_auto_reconnect_text='Disabled' setvar WIFI_AUTO_RECONNECT_ACTIVE = '0' if (( $(systemctl is-active dietpi-wifi-monitor.service | grep -ci -m1 '^active') )) { setvar WIFI_AUTO_RECONNECT_ACTIVE = '1' setvar wifi_auto_reconnect_text = ''Enabled'' } setvar whiptail_menu_array = ''("Auto Reconnect" ": $wifi_auto_reconnect_text"); ((whip_options_total++)) } setvar whiptail_menu_array = ''("Change Mode" ": $mode_target"); ((whip_options_total++)) # - show static options if (( $WIFI_MODE_TARGET == 0 )) { setvar whiptail_menu_array = ''("Copy" "Copy Current address to Static"); ((whip_options_total++)) setvar whiptail_menu_array = ''("Static Ip" ": $WIFI_IP_STATIC"); ((whip_options_total++)) setvar whiptail_menu_array = ''("Static Mask" ": $WIFI_MASK_STATIC"); ((whip_options_total++)) setvar whiptail_menu_array = ''("Static Gateway" ": $WIFI_GATEWAY_STATIC"); ((whip_options_total++)) setvar whiptail_menu_array = ''("Static DNS" ": $WIFI_DNS_STATIC"); ((whip_options_total++)) } setvar whiptail_menu_array = ''("Disable" "Disable WiFi adapter"); ((whip_options_total++)) setvar description_text = "" Current Details: \n - SSID = $WIFI_SSID | $WIFI_BITRATE Mbit | Strength: $WIFI_SIGNALSTRENGTH\n - KEY = $WIFI_KEY \n - Mode = $mode_current \n - Ip = $WIFI_IP\n - Mask = $WIFI_MASK\n - DNS = $WIFI_DNS"" } # - Unset country code? if test $WIFI_COUNTRYCODE = "00" { setvar whiptail_menu_array = ''("Country" "Not set, please configure ($WIFI_COUNTRYCODE)"); ((whip_options_total++)) } else { setvar whiptail_menu_array = ''("Country" ": $WIFI_COUNTRYCODE"); ((whip_options_total++)) } setvar whiptail_menu_array = ''("Apply" "Save Changes (Restart Networking)"); ((whip_options_total++)) if (( $whip_options_total > $WHIP_OPTIONS_MAX_DISPLAY )) { setvar whip_options_total = "$WHIP_OPTIONS_MAX_DISPLAY" } local description_line_count=$(( 7 + $(echo -e "$description_text" | wc -l) )) # 7 is the minimal height of whiptail with no data/entries setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu "$description_text" --cancel-button "$TEXT_MENU_BACK" --backtitle "$WHIP_BACKTITLE" --default-item "$WHIP_SELECTION_PREVIOUS" $(( $description_line_count + $whip_options_total )) 65 $whip_options_total "${whiptail_menu_array[@]}" 3>&1 1>&2 2>&3) #delete [] unset whiptail_menu_array setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar WHIP_SELECTION_PREVIOUS = "$OPTION" case (OPTION) { 'Auto Reconnect' { if (( ! $WIFI_AUTO_RECONNECT_ACTIVE )) { WiFi_Monitor_Enable } else { WiFi_Monitor_Disable } #Return to this menu setvar TARGETMENUID = '10' } Key { setvar OPTION = $(whiptail --inputbox "Please enter a key/password for the WiFi hotspot\n - NB: Minimum of 8 characters" 9 70 "$HOTSPOT_KEY" --title "Change Hotspot Access Key" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar HOTSPOT_KEY = "$OPTION" } #Return to this menu setvar TARGETMENUID = '10' } SSID { setvar OPTION = $(whiptail --inputbox "Please enter a SSID for the WiFi hotspot" 8 65 "$HOTSPOT_SSID" --title "Change Hotspot SSID" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar HOTSPOT_SSID = "$OPTION" } #Return to this menu setvar TARGETMENUID = '10' } Channel { #2.4ghz only atm local whiptail_menu_array=() local channel_mhz=2412 local channel_min=1 local channel_max=13 for ((i=$channel_min; i<=$channel_max; i++)) do whiptail_menu_array+=("$i " "$channel_mhz MHz") ((channel_mhz += 5 )) done setvar OPTION = $(whiptail --title "Change Hotspot Channel" --menu "Please select a WiFi channel for the hotspot." --cancel-button "$TEXT_MENU_BACK" --backtitle "$WHIP_BACKTITLE" 16 60 7 "${whiptail_menu_array[@]}" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? unset whiptail_menu_array if (( $CHOICE == 0 )) { setvar HOTSPOT_CHANNEL = "$OPTION" } #Return to this menu setvar TARGETMENUID = '10' } Country { Change_WifiCountryCode #Return to this Menu setvar TARGETMENUID = '10' } Disable { whiptail --title "WiFi is Enabled" --yesno "Would you like to disable the WiFi adapter?\n - (NOTICE) All WiFi connections will be dropped." --yes-button "Ok" --no-button "Back" --defaultno --backtitle $WHIP_BACKTITLE 10 60 setvar CHOICE = ""$? #Confirm action if (( $CHOICE == 0 )) { setvar WIFI_DISABLED = '1' WiFi_Monitor_Disable Network_ApplyChanges setvar TARGETMENUID = '8' } else { #Return to this Menu setvar TARGETMENUID = '10' } } Scan { Scan_Wifi #Return to this menu setvar TARGETMENUID = '10' } Manual { Change_WifiSsid Change_WifiKey Wifi_Reconnect #Return to this menu setvar TARGETMENUID = '10' } "Change Mode" { ((WIFI_MODE_TARGET++)) if (( $WIFI_MODE_TARGET >= 2 )) { setvar WIFI_MODE_TARGET = '0' } #Return to this menu setvar TARGETMENUID = '10' } Apply { if (( $WIFI_HOTSPOT == 1 )) { # - 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 } #Return to this menu setvar TARGETMENUID = '10' } Copy { Network_WIFI_CopyCurrentToStatic #Return to this menu setvar TARGETMENUID = '10' } "Static Ip" { Change_StaticIp 1 #Return to this menu setvar TARGETMENUID = '10' } "Static Gateway" { Change_StaticGateway 1 #Return to this menu setvar TARGETMENUID = '10' } "Static Mask" { Change_StaticMask 1 #Return to this menu setvar TARGETMENUID = '10' } "Static DNS" { Change_StaticDns 1 #Return to this menu setvar TARGETMENUID = '10' } State { if (( $hotspot_active_state )) { systemctl stop hostapd } else { systemctl start hostapd } #Return to this menu setvar TARGETMENUID = '10' } } } } #TARGETMENUID=11 proc Menu_Tools { setvar TARGETMENUID = '0' setvar WHIP_TITLE = ''DietPi - Tools'' setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu "Please select an option:" --cancel-button "$TEXT_MENU_BACK" --backtitle "$WHIP_BACKTITLE" 10 70 2 \ "Benchmarks" "Filesystem and RAM benchmarks." \ "Stress Test" "CPU Burn and system stability tests (CPU/IO/RAM)" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { case (OPTION) { Benchmarks { setvar TARGETMENUID = '12' } 'Stress Test' { setvar TARGETMENUID = '15' } } } } #Benchmark Scores setvar CPUBENCH_TIME = ''Not Tested'' setvar CPUBENCH_INT_MAX = '1000000' setvar SD_WRITE = ''Not Tested'' setvar SD_READ = ''Not Tested'' setvar USB_WRITE = ''Not Tested'' setvar USB_READ = ''Not Tested'' setvar RAM_WRITE = ''Not Tested'' setvar RAM_READ = ''Not Tested'' setvar CUSTOM_WRITE = ''Not Tested'' setvar CUSTOM_READ = ''Not Tested'' setvar FP_CUSTOM_MOUNT = '''' proc Run_FilesystemBenchmark { local device_index=$1 local benchmark_temp_file="" local read_speed=0 local write_speed=0 local run_benchmark=1 local benchmark_filesize=0 local benchmark_filesystem_freespace=0 local benchmark_filesystem_offset=10 local text_info_test_name="" local min_benchmark_size=10 clear #Define test locations / info and extras. if (( $device_index == 0 )) { setvar text_info_test_name = ''RootFS'' setvar benchmark_temp_file = ""$HOME/benchmark.file"" setvar benchmark_filesystem_freespace = $(( $(df -m | grep -m1 "$(sed -n 4p /DietPi/dietpi/.hw_model)" | awk '{print $4}') - $benchmark_filesystem_offset )) } elif (( $device_index == 1 )) { setvar text_info_test_name = ''USB harddrive'' setvar benchmark_temp_file = ""$(df -P | grep -m1 '^/dev/sda1' | awk '{print $6}')/benchmark.file"" setvar benchmark_filesystem_freespace = $(( $(df -m | grep -m1 '^/dev/sda1' | awk '{print $4}') - $benchmark_filesystem_offset )) } elif (( $device_index == 2 )) { setvar text_info_test_name = ''RAM'' setvar benchmark_temp_file = ''/tmp/benchmark.file'' setvar benchmark_filesystem_freespace = $(( $(df -m | grep -m1 '/tmp' | awk '{print $4}') - $benchmark_filesystem_offset )) } elif (( $device_index == 3 )) { setvar text_info_test_name = ''Custom'' setvar benchmark_temp_file = ""$FP_CUSTOM_MOUNT/benchmark.file"" setvar benchmark_filesystem_freespace = $(( $(df -m | grep -m1 "$FP_CUSTOM_MOUNT$" | awk '{print $4}') - $benchmark_filesystem_offset )) } #Not enough free space if (( $benchmark_filesystem_freespace < $min_benchmark_size )) { setvar run_benchmark = '0' echo -e "(EE): Insufficient space to run $text_info_test_name filesystem benchmark.\n - Available space: $benchmark_filesystem_freespace MB\n - Space required: $min_benchmark_size MB" echo -e "" read -p "Press any key to continue....." #Obtain user benchmark size. } else { setvar benchmark_filesize = $(whiptail --inputbox "Please enter a filesize test value (MB). A value of 100 is recommended.\n- Minimum value: $min_benchmark_size\n- Maximum possible value: $benchmark_filesystem_freespace" 10 70 "100" --title "Benchmark File Size (MB)" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { #Check for valid interger/entry if [[ $benchmark_filesize =~ ^-?[0-9]+$ ]] && (( $benchmark_filesize > 0 )) { #Disable test if not enough free space. if (( $benchmark_filesystem_freespace < $benchmark_filesize )) { setvar run_benchmark = '0' echo -e "(EE): Insufficient space to run $text_info_test_name filesystem benchmark.\n - Requested benchmark size: $benchmark_filesize MB\n - Available space for benchmark: $benchmark_filesystem_freespace MB" echo -e "" read -p "Press any key to continue....." #Value too small } elif (( $benchmark_filesize < $min_benchmark_size )) { setvar run_benchmark = '0' echo -e "(EE): Your requested benchmark size of $benchmark_filesize MB is too small." echo -e "" read -p "Press any key to continue....." } } else { #invalid value setvar run_benchmark = '0' } #User aborted. } else { setvar run_benchmark = '0' } } #Run benchmark if (( $run_benchmark == 1 )) { G_DIETPI-NOTIFY 2 "Performing $text_info_test_name benchmark, please wait..." G_DIETPI-NOTIFY 2 "Testing Seq Write Speed ($benchmark_filesize MB)" if (( $G_DISTRO == 3 )) { setvar write_speed = $(dd bs=4K count=$(( $benchmark_filesize * 1024 / 4 )) if=/dev/zero of=$benchmark_temp_file conv=fdatasync 2>&1 | grep 'MB' | awk '{print $8, $9}') } elif (( $G_DISTRO == 4 )) { setvar write_speed = $(dd bs=4K count=$(( $benchmark_filesize * 1024 / 4 )) if=/dev/zero of=$benchmark_temp_file conv=fdatasync 2>&1 | grep 'MB' | awk '{print $10, $11}') } # - Clear cache sync echo 3 > /proc/sys/vm/drop_caches G_DIETPI-NOTIFY 2 "Testing Seq Read Speed ($benchmark_filesize MB)" if (( $G_DISTRO == 3 )) { setvar read_speed = $(dd bs=4K count=$(( $benchmark_filesize * 1024 / 4 )) if=$benchmark_temp_file of=/dev/zero conv=fdatasync 2>&1 | grep 'MB' | awk '{print $8, $9}') } elif (( $G_DISTRO == 4 )) { setvar read_speed = $(dd bs=4K count=$(( $benchmark_filesize * 1024 / 4 )) if=$benchmark_temp_file of=/dev/zero conv=fdatasync 2>&1 | grep 'MB' | awk '{print $10, $11}') } # - Update global values. if (( $device_index == 0 )) { setvar SD_WRITE = "$write_speed" setvar SD_READ = "$read_speed" } elif (( $device_index == 1 )) { setvar USB_WRITE = "$write_speed" setvar USB_READ = "$read_speed" } elif (( $device_index == 2 )) { setvar RAM_WRITE = "$write_speed" setvar RAM_READ = "$read_speed" } elif (( $device_index == 3 )) { setvar CUSTOM_WRITE = "$write_speed" setvar CUSTOM_READ = "$read_speed" } } #Delete Test File rm $benchmark_temp_file &> /dev/null } proc Run_CPUBenchmark { # if (( ! $(dpkg --get-selections | grep -ci -m1 '^sysbench[[:space:]]') )); then # G_DIETPI-NOTIFY 2 "Installing Sysbench, please wait..." # G_AGI sysbench # fi /DietPi/dietpi/dietpi-services stop # G_DIETPI-NOTIFY 0 "Running Sysbench with max prime of $CPUBENCH_INT_MAX, please wait..." # local fp_log_sysbench='/tmp/.fp_log_sysbench' # sysbench --test=cpu --num-threads=$(nproc --all) --cpu-max-prime=$CPUBENCH_INT_MAX --validate=on run | tee -a "$fp_log_sysbench" # G_DIETPI-NOTIFY 0 "Sysbench completed" # CPUBENCH_TIME=$(grep -m1 'total time' "$fp_log_sysbench" | awk '{print $NF}') # rm "$fp_log_sysbench" G_DIETPI-NOTIFY 0 "Running DietPi-CPU Benchmark with max value of 1000000 over $(nproc --all) cores, please wait..." cat <<< """ > /tmp/dietpi-bench #!/bin/bash target_max_int=$CPUBENCH_INT_MAX cores='$'(nproc --all) int_split='$'(('$'target_max_int / '$'cores )) aStart_Int=() aEnd_Int=() #Split the max int target based on total cores for (( i=0; i<'$'cores; i++ )) do aEnd_Int['$'i]='$'(( ('$'i + 1) * '$'int_split )) aStart_Int['$'i]='$'(( '$'{aEnd_Int['$'i]} - '$'int_split )) echo '$'{aStart_Int['$'i]} '$'{aEnd_Int['$'i]} done Run_Bench() { while (( '$'{aStart_Int['$'1]} < '$'{aEnd_Int['$'1]} )) do ((aStart_Int['$'1]++)) done } #Launch benchmark threads for (( i=0; i<'$'cores; i++ )) do Run_Bench '$'i & done #Wait for jobs to finish for job in '`'jobs -p'`' do echo '$'job wait '$'job done #delete[] unset aStart_Int unset aEnd_Int """ > /tmp/dietpi-bench #!/bin/bash target_max_int=$CPUBENCH_INT_MAX cores=\$(nproc --all) int_split=\$((\$target_max_int / \$cores )) aStart_Int=() aEnd_Int=() #Split the max int target based on total cores for (( i=0; i<\$cores; i++ )) do aEnd_Int[\$i]=\$(( (\$i + 1) * \$int_split )) aStart_Int[\$i]=\$(( \${aEnd_Int[\$i]} - \$int_split )) echo \${aStart_Int[\$i]} \${aEnd_Int[\$i]} done Run_Bench() { while (( \${aStart_Int[\$1]} < \${aEnd_Int[\$1]} )) do ((aStart_Int[\$1]++)) done } #Launch benchmark threads for (( i=0; i<\$cores; i++ )) do Run_Bench \$i & done #Wait for jobs to finish for job in \`jobs -p\` do echo \$job wait \$job done #delete[] unset aStart_Int unset aEnd_Int _EOF_ chmod +x /tmp/dietpi-bench do { time -p /tmp/dietpi-bench; } 2> /tmp/dietpi-bench_result setvar CPUBENCH_TIME = $( grep -m1 'real' /tmp/dietpi-bench_result | awk '{print $2}' ) /DietPi/dietpi/dietpi-services start } #TARGETMENUID=12 proc Menu_FilesystemBenchmark { setvar TARGETMENUID = '11' setvar WHIP_TITLE = ''DietPi - Benchmarks'' setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu "\ CPU : Total time $CPUBENCH_INT_MAX int = $CPUBENCH_TIME seconds\n\ RAM : Write = $RAM_WRITE | Read = $RAM_READ\n\ RootFS : Write = $SD_WRITE | Read = $SD_READ \n\ USB Drive : Write = $USB_WRITE | Read = $USB_READ\n\ Custom : Write = $CUSTOM_WRITE | Read = $CUSTOM_READ\ " --cancel-button "$TEXT_MENU_BACK" --backtitle "$WHIP_BACKTITLE" 19 70 7 \ "" "─── Performance ─────────────────────────────" \ "CPU" "Benchmark CPU performance." \ "RAM" "Benchmark RAM performance." \ "" "─── Filesystem ──────────────────────────────" \ "RootFS" "Benchmark SD/EMMC IO performance." \ "USB Drive" "Benchmark USB drive IO performance." \ "Custom" "Benchmark from a selection of mounted devices." 3>&1 1>&2 2>&3) case (OPTION) { "CPU" { Run_CPUBenchmark #Return to this menu setvar TARGETMENUID = '12' } "RootFS" { Run_FilesystemBenchmark 0 #Return to this menu setvar TARGETMENUID = '12' } "USB Drive" { #Check USB is connected and mounted if (( $(df -P | grep -ci -m1 '^/dev/sda1') )) { Run_FilesystemBenchmark 1 #No Drive } else { whiptail --title "No USB Drive was found" --msgbox "No USB Drive was found, /dev/sda1 is not available.\nThe test has been aborted." --backtitle $WHIP_BACKTITLE 10 60 } #Return to this menu setvar TARGETMENUID = '12' } "Custom" { /DietPi/dietpi/dietpi-drive_manager 1 setvar FP_CUSTOM_MOUNT = "$(cat /tmp/dietpi-drive_manager_selmnt)" if test -n $FP_CUSTOM_MOUNT { Run_FilesystemBenchmark 3 } #Return to this menu setvar TARGETMENUID = '12' } "RAM" { #Check for /tmp as tmpfs, before running: https://github.com/Fourdee/DietPi/issues/1130#issuecomment-350348081 if (( $(df | grep '[[:space:]]/tmp' | grep -ci -m1 '^tmpfs[[:space:]]') )) { Run_FilesystemBenchmark 2 } else { whiptail --title $WHIP_TITLE --msgbox "Unable to run RAM benchmark, as /tmp is not mounted as tmpfs.\n\nThis mount is disabled automatically on <=512MB devices to prevent out of memory errors, please see here for more info:\n\n - https://github.com/Fourdee/DietPi/issues/1027" --backtitle $WHIP_BACKTITLE 12 70 } #Return to this menu setvar TARGETMENUID = '12' } } } proc Reset_Overclocking { sed -i '/over_voltage=/c\#over_voltage=0' /DietPi/config.txt if (( $G_HW_MODEL == 3 )) { sed -i '/arm_freq=/c\#arm_freq=1200' /DietPi/config.txt sed -i '/core_freq=/c\#core_freq=400' /DietPi/config.txt sed -i '/sdram_freq=/c\#sdram_freq=450' /DietPi/config.txt } elif (( $G_HW_MODEL == 2 )) { sed -i '/arm_freq=/c\#arm_freq=900' /DietPi/config.txt sed -i '/core_freq=/c\#core_freq=250' /DietPi/config.txt sed -i '/sdram_freq=/c\#sdram_freq=450' /DietPi/config.txt } elif (( $G_HW_MODEL <= 1 )) { sed -i '/arm_freq=/c\#arm_freq=700' /DietPi/config.txt sed -i '/core_freq=/c\#core_freq=250' /DietPi/config.txt sed -i '/sdram_freq=/c\#sdram_freq=400' /DietPi/config.txt #Zero , via name id if (( $(cat /DietPi/dietpi/.hw_model | tr '[:upper:]' '[:lower:]' | grep -ci -m1 'rpi zero') )) { sed -i '/arm_freq=/c\#arm_freq=1000' /DietPi/config.txt sed -i '/core_freq=/c\#core_freq=400' /DietPi/config.txt sed -i '/sdram_freq=/c\#sdram_freq=450' /DietPi/config.txt } } setvar REBOOT_REQUIRED = '1' } proc Warning_Overclocking { setvar WHIP_TITLE = ''Warning! Continue with overclocking?'' setvar WHIP_QUESTION = ''Your selected overclocking choice may void the warranty on this device. Do you wish to continue?\n\nUse of this tool is at your own risk. DietPi will not be held responsable for any damages due to overclocking.\n\nAlthough DietPi overclocks are tested for stability, results are not guaranteed and may differ from device.'' whiptail --title $WHIP_TITLE --yesno $WHIP_QUESTION --yes-button "Ok" --no-button "Back" --defaultno --backtitle $WHIP_BACKTITLE 14 70 } #TARGETMENUID=13 proc Menu_Overclock { setvar TARGETMENUID = '4' #Get Current Overclocking Settings local over_voltage_value=$(grep -m1 'over_voltage=' /DietPi/config.txt | tr -d '#over_voltage=') local arm_freq_value=$(grep -m1 'arm_freq=' /DietPi/config.txt | tr -d '#arm_freq=') local core_freq_value=$(grep -m1 'core_freq=' /DietPi/config.txt | tr -d '#core_freq=') local sdram_freq_value=$(grep -m1 'sdram_freq=' /DietPi/config.txt | tr -d '#sdram_freq=') setvar WHIP_TITLE = ''DietPi - Overclocking'' #Overclocking Pi1 # - Zero echo -e $G_HW_MODEL if (( $(cat /DietPi/dietpi/.hw_model | tr '[:upper:]' '[:lower:]' | grep -ci -m1 'rpi zero') )) { setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu " Hardware : $G_HW_MODEL_DESCRIPTION \n Current: $arm_freq_value MHz ARM | $core_freq_value MHz core | $sdram_freq_value MHz SDRAM | $over_voltage_value overvolt" --cancel-button "$TEXT_MENU_BACK" --backtitle "$WHIP_BACKTITLE" 13 75 4 \ "none" " 1000 MHz ARM | 400 MHz core | 450 MHz SDRAM | 0 overvolt" 3>&1 1>&2 2>&3) case (OPTION) { none { Reset_Overclocking #Return to this menu setvar TARGETMENUID = '13' } } } elif (( $G_HW_MODEL <= 1 )) { setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu " Hardware : $G_HW_MODEL_DESCRIPTION \n Current: $arm_freq_value MHz ARM | $core_freq_value MHz core | $sdram_freq_value MHz SDRAM | $over_voltage_value overvolt" --cancel-button "$TEXT_MENU_BACK" --backtitle "$WHIP_BACKTITLE" 14 70 4 \ "none" " 700 MHz ARM | 250 MHz core | 400 MHz SDRAM | 0 overvolt" \ "safe" " 900 MHz ARM | 250 MHz core | 400 MHz SDRAM | 2 overvolt" \ "high" " 900 MHz ARM | 500 MHz core | 400 MHz SDRAM | 4 overvolt" \ "extreme" "1025 MHz ARM | 500 MHz core | 400 MHz SDRAM | 6 overvolt" 3>&1 1>&2 2>&3) case (OPTION) { none { Reset_Overclocking #Return to this menu setvar TARGETMENUID = '13' } safe { Reset_Overclocking sed -i '/over_voltage=/c\over_voltage=2' /DietPi/config.txt sed -i '/arm_freq=/c\arm_freq=900' /DietPi/config.txt #Return to this menu setvar TARGETMENUID = '13' } high { Warning_Overclocking setvar CHOICE = ""$? if (( $CHOICE == 0 )) { Reset_Overclocking sed -i '/over_voltage=/c\over_voltage=4' /DietPi/config.txt sed -i '/arm_freq=/c\arm_freq=900' /DietPi/config.txt sed -i '/core_freq=/c\core_freq=500' /DietPi/config.txt } #Return to this menu setvar TARGETMENUID = '13' } extreme { Warning_Overclocking setvar CHOICE = ""$? if (( $CHOICE == 0 )) { Reset_Overclocking sed -i '/over_voltage=/c\over_voltage=6' /DietPi/config.txt sed -i '/arm_freq=/c\arm_freq=1025' /DietPi/config.txt sed -i '/core_freq=/c\core_freq=500' /DietPi/config.txt } #Return to this menu setvar TARGETMENUID = '13' } } #Overclocking Pi2 } elif (( $G_HW_MODEL == 2 )) { setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu " Hardware : $G_HW_MODEL_DESCRIPTION \n Current: $arm_freq_value MHz ARM | $core_freq_value MHz core | $sdram_freq_value MHz SDRAM | $over_voltage_value overvolt" --cancel-button "$TEXT_MENU_BACK" --backtitle "$WHIP_BACKTITLE" 13 75 4 \ "none" " 900 MHz ARM | 250 MHz core | 450 MHz SDRAM | 0 overvolt" \ "low" "1000 MHz ARM | 250 MHz core | 450 MHz SDRAM | 3 overvolt" \ "med" "1000 MHz ARM | 500 MHz core | 450 MHz SDRAM | 5 overvolt" \ "extreme" "1050 MHz ARM | 500 MHz core | 450 MHz SDRAM | 6 overvolt" 3>&1 1>&2 2>&3) case (OPTION) { none { Reset_Overclocking #Return to this menu setvar TARGETMENUID = '13' } low { Warning_Overclocking setvar CHOICE = ""$? if (( $CHOICE == 0 )) { Reset_Overclocking sed -i '/over_voltage=/c\over_voltage=3' /DietPi/config.txt sed -i '/arm_freq=/c\arm_freq=1000' /DietPi/config.txt } #Return to this menu setvar TARGETMENUID = '13' } med { Warning_Overclocking setvar CHOICE = ""$? if (( $CHOICE == 0 )) { Reset_Overclocking sed -i '/over_voltage=/c\over_voltage=5' /DietPi/config.txt sed -i '/arm_freq=/c\arm_freq=1000' /DietPi/config.txt sed -i '/core_freq=/c\core_freq=500' /DietPi/config.txt } #Return to this menu setvar TARGETMENUID = '13' } extreme { Warning_Overclocking setvar CHOICE = ""$? if (( $CHOICE == 0 )) { Reset_Overclocking sed -i '/over_voltage=/c\over_voltage=6' /DietPi/config.txt sed -i '/arm_freq=/c\arm_freq=1050' /DietPi/config.txt sed -i '/core_freq=/c\core_freq=500' /DietPi/config.txt } #Return to this menu setvar TARGETMENUID = '13' } } #Overclocking Pi3 } elif (( $G_HW_MODEL == 3 )) { setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu " Hardware : $G_HW_MODEL_DESCRIPTION \n Current: $arm_freq_value MHz ARM | $core_freq_value MHz core | $sdram_freq_value MHz SDRAM | $over_voltage_value overvolt" --cancel-button "$TEXT_MENU_BACK" --backtitle "$WHIP_BACKTITLE" 13 75 4 \ "none" "1200 MHz ARM | 400 MHz core | 450 MHz SDRAM | 0 overvolt" \ "low" "1300 MHz ARM | 400 MHz core | 450 MHz SDRAM | 3 overvolt" \ "med" "1325 MHz ARM | 400 MHz core | 450 MHz SDRAM | 4 overvolt" \ "high" "1350 MHz ARM | 400 MHz core | 450 MHz SDRAM | 5 overvolt" 3>&1 1>&2 2>&3) case (OPTION) { none { Reset_Overclocking #Return to this menu setvar TARGETMENUID = '13' } low { Warning_Overclocking setvar CHOICE = ""$? if (( $CHOICE == 0 )) { Reset_Overclocking sed -i '/arm_freq=/c\arm_freq=1300' /DietPi/config.txt sed -i '/over_voltage=/c\over_voltage=3' /DietPi/config.txt sed -i '/core_freq=/c\core_freq=400' /DietPi/config.txt } #Return to this menu setvar TARGETMENUID = '13' } med { Warning_Overclocking setvar CHOICE = ""$? if (( $CHOICE == 0 )) { Reset_Overclocking sed -i '/arm_freq=/c\arm_freq=1325' /DietPi/config.txt sed -i '/over_voltage=/c\over_voltage=4' /DietPi/config.txt sed -i '/core_freq=/c\core_freq=400' /DietPi/config.txt } #Return to this menu setvar TARGETMENUID = '13' } high { Warning_Overclocking setvar CHOICE = ""$? if (( $CHOICE == 0 )) { Reset_Overclocking sed -i '/over_voltage=/c\over_voltage=5' /DietPi/config.txt sed -i '/arm_freq=/c\arm_freq=1350' /DietPi/config.txt sed -i '/core_freq=/c\core_freq=400' /DietPi/config.txt } #Return to this menu setvar TARGETMENUID = '13' } } } } #TARGETMENUID=14 proc Menu_AudioOptions { setvar TARGETMENUID = '0' local soundcard_current=$(grep -m1 '^CONFIG_SOUNDCARD=' /DietPi/dietpi.txt | sed 's/.*=//') local whiptail_menu_array=() setvar whiptail_menu_array = ''("Soundcard" ": $soundcard_current") if (( $(dpkg --get-selections | grep -ci -m1 '^alsa-utils') )) { setvar whiptail_menu_array = ''("DietPi-JustBoom" ": Launches EQ and MPD audio options menu") } # - RPi, low power mode (PSU noise ripple reduction): https://github.com/Fourdee/DietPi/issues/757 if (( $G_HW_MODEL < 10 )) { local current_cpu_governor=$(cat /DietPi/dietpi.txt | grep -m1 '^CONFIG_CPU_GOVERNOR=' | sed 's/.*=//') local hdmi_output=$(cat /DietPi/dietpi.txt | grep -m1 'CONFIG_HDMI_OUTPUT=' | sed 's/.*=//') local psu_noise_reduction_enabled=0 if test $current_cpu_governor = "powersave" && (( ! $hdmi_output )) { setvar whiptail_menu_array = ''("PSU noise reduction" ": Enabled | Select now to disable") setvar psu_noise_reduction_enabled = '1' } else { setvar whiptail_menu_array = ''("PSU noise reduction" ": Disabled | Select now to enable") } } setvar WHIP_TITLE = ''DietPi - Audio Options'' setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu "Please select an option:" --cancel-button "$TEXT_MENU_BACK" 12 75 4 "${whiptail_menu_array[@]}" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? unset whiptail_menu_array if (( $CHOICE == 0 )) { if test $OPTION = "PSU noise reduction" { if (( ! $psu_noise_reduction_enabled )) { whiptail --title "PSU noise reduction" --msgbox "This 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" --backtitle $WHIP_BACKTITLE 14 70 sed -i "/CONFIG_CPU_GOVERNOR=/c\CONFIG_CPU_GOVERNOR=powersave" /DietPi/dietpi.txt /DietPi/dietpi/dietpi-cpu_set sed -i "/CONFIG_HDMI_OUTPUT=/c\CONFIG_HDMI_OUTPUT=0" /DietPi/dietpi.txt } else { sed -i "/CONFIG_CPU_GOVERNOR=/c\CONFIG_CPU_GOVERNOR=ondemand" /DietPi/dietpi.txt /DietPi/dietpi/dietpi-cpu_set sed -i "/CONFIG_HDMI_OUTPUT=/c\CONFIG_HDMI_OUTPUT=1" /DietPi/dietpi.txt } #Return to This Menu setvar TARGETMENUID = '14' } elif test $OPTION = "Soundcard" { setvar WHIP_TITLE = ''DietPi - Soundcards'' local whiptail_menu_array=() # - Global: # RPI, none disables HDMI aswell. if (( $G_HW_MODEL < 10 )) { setvar whiptail_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 )) { setvar whiptail_menu_array = ''("default" "3.5mm Analogue") # Native PC | List available } elif (( $G_HW_MODEL == 21 )) { setvar whiptail_menu_array = ''("default" "HW:0,0") # Install prereqs to allow for detection if (( ! $(dpkg --get-selections | grep -ci -m1 '^alsa-utils') )) { /DietPi/dietpi/func/dietpi-set_hardware soundcard default } for ((i=0; i<10; i++)) do if [ -f /proc/asound/card$i/id ]; then for ((j=0; j<10; j++)) do if [ -f /proc/asound/card$i/pcm${j}p/info ]; then local card_index=$(cat /proc/asound/card$i/pcm${j}p/info | grep -m1 '^card:' | awk '{print $2}') local device_index=$(cat /proc/asound/card$i/pcm${j}p/info | grep -m1 '^device:' | awk '{print $2}') local card_name=$(cat /proc/asound/card$i/id) card_name+=$(cat /proc/asound/card$i/pcm${j}p/info | grep -m1 '^name:' | sed 's/name://g') whiptail_menu_array+=( "hw:$card_index,$device_index" "$card_name" ) fi done fi done } else { setvar whiptail_menu_array = ''("default" "HDMI") } # - RPI if (( $G_HW_MODEL < 10 )) { setvar whiptail_menu_array = ''("rpi-bcm2835" "Onboard: HDMI (if plugged in, else 3.5mm)") setvar whiptail_menu_array = ''("rpi-bcm2835-3.5mm" "Onboard: 3.5mm forced output") setvar whiptail_menu_array = ''("rpi-bcm2835-ultrahq" "Onboard HQ: HDMI (if plugged in, else 3.5mm)") setvar whiptail_menu_array = ''("rpi-bcm2835-ultrahq-3.5mm" "Onboard HQ: 3.5mm forced output") setvar whiptail_menu_array = ''("allo-boss-dac-pcm512x-audio" "Allo Boss DAC") setvar whiptail_menu_array = ''("allo-boss-dac-pcm512x-audio" "Allo Mini Boss DAC") setvar whiptail_menu_array = ''("allo-digione" "Allo DigiOne") setvar whiptail_menu_array = ''("allo-piano-dac-pcm512x-audio" "Allo Piano DAC") setvar whiptail_menu_array = ''("allo-piano-dac-pcm512x-audio" "Allo Piano DAC") setvar whiptail_menu_array = ''("dionaudio-loco" "Dion Audio LOCO") setvar whiptail_menu_array = ''("dionaudio-loco-v2" "Dion Audio LOCO V2") setvar whiptail_menu_array = ''("googlevoicehat-soundcard" "Google AIY voice kit") setvar whiptail_menu_array = ''("hifiberry-amp" "HifiBerry AMP / AMP+") setvar whiptail_menu_array = ''("hifiberry-dac" "HifiBerry DAC / MiniAMP") setvar whiptail_menu_array = ''("hifiberry-dacplus" "HifiBerry DAC+ / DAC+ Pro") setvar whiptail_menu_array = ''("hifiberry-digi" "HifiBerry DIGI / DIGI+") setvar whiptail_menu_array = ''("hifiberry-digi-pro" "HifiBerry DIGI Pro") setvar whiptail_menu_array = ''("i-sabre-k2m" "AudioPhonics I-Sabre ES9028 Q2M") setvar whiptail_menu_array = ''("iqaudio-dacplus" "Pi-DAC+, Pi-DACZero, Pi-DAC Pro, Pi-DigiAMP+") setvar whiptail_menu_array = ''("iqaudio-digi-wm8804-audio" "Pi-DIGI+") setvar whiptail_menu_array = ''("iqaudio-dacplus,auto_mute_amp" "Pi-DigiAMP+") setvar whiptail_menu_array = ''("iqaudio-dacplus,unmute_amp" "Pi-DigiAMP+") setvar whiptail_menu_array = ''("justboom-dac" "JustBoom: DAC HAT, Amp HAT, DAC Zero and Amp Zero") setvar whiptail_menu_array = ''("justboom-digi" "JustBoom: Digi HAT and Digi Zero") setvar whiptail_menu_array = ''("rpi-dac" "Soekris DAM1021 (pcm1794a)") # - C1/C2 } elif (( $G_HW_MODEL == 10 || $G_HW_MODEL == 12 )) { setvar whiptail_menu_array = ''("odroid-hifishield-plus" "Odroid HiFi Shield 1/Plus") setvar whiptail_menu_array = ''("odroid-hifishield-2" "Odroid HiFi Shield 2") # - h2+ | OPi Zero } elif (( $G_HW_MODEL == 32 )) { setvar whiptail_menu_array = ''("h2-hdmi" "HDMI") # - Rock64 } elif (( $G_HW_MODEL == 43 )) { setvar whiptail_menu_array = ''("rock64-analogue" "3.5MM") # NanoPi M2/M3 } elif (( $G_HW_MODEL == 61 || $G_HW_MODEL == 62 )) { setvar whiptail_menu_array = ''("s5pxx18-hdmi" "HDMI") # - H3 } elif (( $G_HW_CPUID == 1 )) { setvar whiptail_menu_array = ''("H3-analogue" "3.5mm analogue") # - H5 # elif (( $G_HW_CPUID == 2 )); then # whiptail_menu_array+=("H5-analogue" "3.5mm analogue") # - Sparky } elif (( $G_HW_MODEL == 70 )) { setvar whiptail_menu_array = ''("snd-soc-allo-piano-dac" "Allo Piano DAC") setvar whiptail_menu_array = ''("snd-soc-allo-piano-dac-plus" "Allo Piano DAC 2.1") setvar whiptail_menu_array = ''("allo-cheapo-analogue" "Allo Cheapo (3.5mm / RCA output)") setvar whiptail_menu_array = ''("allo-cheapo-optical" "Allo Cheapo (Optical output)") # - Asus tb } elif (( $G_HW_MODEL == 52 )) { setvar whiptail_menu_array = ''("asus-tb-analogue" "3.5mm analogue") } # - Global usb-dac, prefer at bottom of list setvar whiptail_menu_array = ''("usb-dac" "USB Audio DAC (any)") setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu "Current : $soundcard_current" --default-item "$soundcard_current" --cancel-button "$TEXT_MENU_BACK" 18 90 10 "${whiptail_menu_array[@]}" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? unset whiptail_menu_array if (( $CHOICE == 0 )) { /DietPi/dietpi/func/dietpi-set_hardware soundcard $OPTION setvar REBOOT_REQUIRED = '1' } #Return to This Menu setvar TARGETMENUID = '14' } elif test $OPTION = "DietPi-JustBoom" { /DietPi/dietpi/misc/dietpi-justboom #Return to This Menu setvar TARGETMENUID = '14' } } } #TARGETMENUID=15 setvar STRESS_TEST_MODE = '0' #0=CPU only | 1=CPU/RAM 2=CPU/RAM/IO setvar STRESS_TEST_DURATION = '60' setvar STRESS_TEST_RESULTS_TEMP_MIN = '0' setvar STRESS_TEST_RESULTS_TEMP_MAX = '0' proc Menu_StressTest { setvar TARGETMENUID = '11' local stress_test_mode_text='CPU Burn: (CPU only)' if (( $STRESS_TEST_MODE == 1 )) { setvar stress_test_mode_text = ''CPU & RAM: (CPU, RAM)'' } elif (( $STRESS_TEST_MODE == 2 )) { setvar stress_test_mode_text = ''Full: (CPU, DISK, RAM)'' } setvar WHIP_TITLE = ''DietPi - Stress Test'' setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu "Please select an option:" --cancel-button "$TEXT_MENU_BACK" --backtitle "$WHIP_BACKTITLE" 11 60 3 \ "Mode" "$stress_test_mode_text" \ "Duration" "$(( $STRESS_TEST_DURATION / 60 )) Minutes" \ "Start" "Launch the stress test" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { if test $OPTION = "Duration" { setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu "Please select a duration for the test" --cancel-button "$TEXT_MENU_BACK" --default-item "$STRESS_TEST_DURATION" --backtitle "$WHIP_BACKTITLE" 13 60 5 \ "60" "1 Minute" \ "300" "5 Minutes" \ "1800" "30 Minutes" \ "3600" "1 Hour" \ "21600" "6 Hours" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar STRESS_TEST_DURATION = "$OPTION" setvar TARGETMENUID = '15' } } elif test $OPTION = "Mode" { setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu "Please select a stress test type" --cancel-button "$TEXT_MENU_BACK" --default-item "$STRESS_TEST_MODE" --backtitle "$WHIP_BACKTITLE" 12 60 3 \ "0" "CPU Burn: (CPU only)" \ "1" "CPU & RAM: (CPU, RAM)" \ "2" "Full: (CPU, DISK, RAM)" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar STRESS_TEST_MODE = "$OPTION" setvar TARGETMENUID = '15' } } elif test $OPTION = "Start" { G_AG_CHECK_INSTALL_PREREQ stress if (( $? != 0 )) { exit 1 } G_DIETPI-NOTIFY 3 Stress_Test "Running stress test for $STRESS_TEST_DURATION seconds" G_DIETPI-NOTIFY 2 'To terminate, type: killall -w stress' local start_time=$(date) local start_time_epoch=$(date +%s) local cores=$(nproc --all) # double up cpu threads, maximize overheads. local memory_per_thread=$(( $(free -m | awk '/^Mem:/{print $2}') / ( $cores * 2 ) )) local fp_log="$HOME/dietpi-config_stress.log" rm $fp_log &> /dev/null if (( $STRESS_TEST_MODE == 0 )) { stress -c $(( $cores * 2 )) -t "$STRESS_TEST_DURATION"s & } elif (( $STRESS_TEST_MODE == 1 )) { stress -c $(( $cores * 2 )) -i $cores -m $cores --vm-bytes "$memory_per_thread"M -t "$STRESS_TEST_DURATION"s & } elif (( $STRESS_TEST_MODE == 2 )) { stress -c $(( $cores * 2 )) -i $cores -m $cores --vm-bytes "$memory_per_thread"M -d 2 -t "$STRESS_TEST_DURATION"s & } # - Reset setvar STRESS_TEST_RESULTS_TEMP_MIN = '1000' setvar STRESS_TEST_RESULTS_TEMP_MAX = '0' # - Check if system supports temp readouts local cpu_supports_temp=0 local cpu_temp=$(G_OBTAIN_CPU_TEMP) if [[ $cpu_temp =~ ^-?[0-9]+$ ]] { setvar cpu_supports_temp = '1' } # - Loop until stress completed local remaning_time=0 while (( $(ps aux | grep -ci -m1 '[s]tress') == 1 )) { setvar cpu_temp = $(G_OBTAIN_CPU_TEMP) setvar 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 )) { if (( $cpu_temp > $STRESS_TEST_RESULTS_TEMP_MAX )) { setvar STRESS_TEST_RESULTS_TEMP_MAX = "$cpu_temp" } if (( $cpu_temp < $STRESS_TEST_RESULTS_TEMP_MIN )) { setvar STRESS_TEST_RESULTS_TEMP_MIN = "$cpu_temp" } } sleep 1 ((time_since_start++)) } 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 whiptail --title $WHIP_TITLE --msgbox "Stress test results:\n$output_string" --backtitle $WHIP_BACKTITLE 14 65 setvar TARGETMENUID = '15' } } } #TARGETMENUID=16 proc Menu_Network_Nas_Misc { setvar TARGETMENUID = '0' #Update installed software Load_Installed_Software #Samba Client local sambaclient_installed=0 local sambaclient_status="Not Installed" local sambaclient_menutext="Install now to access Windows shares and NAS devices" local sambaclient_mounted_size="unknown" local sambaclient_mounted_used="unknown" local sambaclient_mounted_free="unknown" if (( ${aSOFTWARE_INSTALL_STATE[1]:=0} == 2 )) { setvar sambaclient_installed = '1' setvar sambaclient_status = ""Unable to connect and/or incorrect details"" setvar sambaclient_menutext = ""Input/Modify Details"" #Check if mount exists and is valid if (( $(df -h | grep -ci -m1 '/mnt/samba') == 1 )) { #Get stats setvar sambaclient_mounted_size = $(df -h | grep -m1 '/mnt/samba' | awk '{print $(NF-4)}') setvar sambaclient_mounted_used = $(df -h | grep -m1 '/mnt/samba' | awk '{print $(NF-3)}') setvar sambaclient_mounted_free = $(df -h | grep -m1 '/mnt/samba' | awk '{print $(NF-2)}') setvar sambaclient_status = ""/mnt/samba | Size $sambaclient_mounted_size | Used $sambaclient_mounted_used | Free $sambaclient_mounted_free"" } } #ftp Client mount, curlftpfs local curlftpfs_installed=0 local curlftpfs_status="Not Installed" local curlftpfs_menutext="Install now to access FTP as filesystem mount" if (( ${aSOFTWARE_INSTALL_STATE[2]:=0} == 2 )) { setvar curlftpfs_installed = '1' setvar curlftpfs_status = ""Unable to connect and/or incorrect details"" setvar curlftpfs_menutext = ""Input/Modify Details"" #Check if mount exists and is valid if (( $(df -h | grep -ci -m1 '/mnt/ftp_client') == 1 )) { #Get stats setvar curlftpfs_status = ""/mnt/ftp_client | Connected"" } } #NoIp Client local noip_installed=0 local noip_status="Not Installed" local noip_menutext="Install No-Ip now" if (( ${aSOFTWARE_INSTALL_STATE[67]:=0} == 2 )) { setvar noip_installed = '1' setvar noip_status = ""Offline - Please Enter No-Ip Details"" setvar noip_menutext = ""Enter/Setup NoIp Details"" #Check if noip is running (indicates login details are valid) if (( $(ps aux | grep -ci -m1 '/usr/local/bin/[n]oip2') == 1 )) { setvar noip_status = ""Online / Active"" setvar noip_menutext = ""Change NoIp Details"" } } #NFS Client local nfsclient_installed=0 local nfsclient_status="Not Installed" local nfsclient_menutext="Install now to access NFS shares" local nfsclient_mounted_size="unknown" local nfsclient_mounted_used="unknown" local nfsclient_mounted_free="unknown" if (( ${aSOFTWARE_INSTALL_STATE[110]:=0} == 2 )) { setvar nfsclient_installed = '1' setvar nfsclient_status = ""Unable to connect and/or incorrect details"" setvar nfsclient_menutext = ""Input/Modify Details"" #Check if mount exists and is valid if (( $(df -h | grep -ci -m1 '/mnt/nfs_client') == 1 )) { #Get stats setvar nfsclient_mounted_size = $(df -h | grep -m1 '/mnt/nfs_client' | awk '{ print $2 }') setvar nfsclient_mounted_used = $(df -h | grep -m1 '/mnt/nfs_client' | awk '{ print $3 }') setvar nfsclient_mounted_free = $(df -h | grep -m1 '/mnt/nfs_client' | awk '{ print $4 }') setvar nfsclient_status = ""/mnt/nfs_client | Size $nfsclient_mounted_size | Used $nfsclient_mounted_used | Free $nfsclient_mounted_free"" } } #Apt mirror local apt_mirror_current=$(sed -n 1p /etc/apt/sources.list | awk '{print $2}') if test ! -n $apt_mirror_current { setvar apt_mirror_current = ''Unknown, no string from scrape'' } #NTPD mirror local ntpd_mirror_current=$(grep -m1 '^CONFIG_NTP_MIRROR=' /DietPi/dietpi.txt | sed 's/.*=//') if test ! -n $ntpd_mirror_current { setvar ntpd_mirror_current = ''Unknown, no string from scrape'' } #Network boot wait local boot_wait_for_network=$(cat /DietPi/dietpi.txt | grep -m1 '^CONFIG_BOOT_WAIT_FOR_NETWORK=' | sed 's/.*=//') local boot_wait_for_network_text=': ' if (( $boot_wait_for_network == 0 )) { setvar boot_wait_for_network_text = ''Disabled'' } elif (( $boot_wait_for_network == 1 )) { setvar boot_wait_for_network_text = ''10 Seconds MAX (default)'' } elif (( $boot_wait_for_network == 2 )) { setvar boot_wait_for_network_text = ''Infinite wait'' } setvar WHIP_TITLE = ''DietPi - Network Options: NAS/Misc'' setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu "\n Samba client : $sambaclient_status\n FTP client : $curlftpfs_status\n NFS client : $nfsclient_status\n NoIp status : $noip_status\n Apt mirror : $apt_mirror_current\n NTPD mirror : $ntpd_mirror_current" --cancel-button "$TEXT_MENU_BACK" --backtitle "$WHIP_BACKTITLE" 21 100 7 \ "Samba Client" "$sambaclient_menutext" \ "FTP Client" "$curlftpfs_menutext" \ "NFS Client" "$nfsclient_menutext" \ "NoIp" "$noip_menutext" \ "Apt Mirror" "Select a different Apt mirror for sources.list" \ "NTPD Mirror" "Select a different NTPD mirror" \ "Boot Net Wait" "$boot_wait_for_network_text" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { case (OPTION) { "Boot Net Wait" { #Create Menu List for Whiptail local whiptail_menu_array=() setvar whiptail_menu_array = ''('0' ': Disabled') setvar whiptail_menu_array = ''('1' ': Wait 10 Seconds MAX for network, before continuing boot (default)') setvar whiptail_menu_array = ''('2' ': Infinite wait for network, before continuing boot') setvar OPTION = $(whiptail --title "Wait for network during boot" --menu "The following options will allow you to delay boot, until a valid network connection is available:" --default-item "$boot_wait_for_network" --cancel-button "$TEXT_MENU_BACK" --backtitle "$WHIP_BACKTITLE" 12 80 3 "${whiptail_menu_array[@]}" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { sed -i "/^CONFIG_BOOT_WAIT_FOR_NETWORK=/c CONFIG_BOOT_WAIT_FOR_NETWORK=$OPTION" /DietPi/dietpi.txt #Return to this Menu setvar TARGETMENUID = '16' } #delete [] unset whiptail_menu_array } "Apt Mirror" { #Create Menu List for Whiptail local whiptail_menu_array=( "Custom" "Manually enter Apt mirror" ) # - Raspbian if (( $G_HW_MODEL < 10 )) { setvar whiptail_menu_array = ''("http://mirrordirector.raspbian.org/raspbian" "Global") setvar whiptail_menu_array = ''("https://www.mirrorservice.org/sites/archive.raspbian.org/raspbian" "Global (https)") setvar whiptail_menu_array = ''("http://mirror.ox.ac.uk/sites/archive.raspbian.org/archive/raspbian" "UK") setvar whiptail_menu_array = ''("ftp://ftp.fu-berlin.de/linux/raspbian/raspbian" "Germany") setvar whiptail_menu_array = ''("http://mirror.umd.edu/raspbian/raspbian" "US") setvar whiptail_menu_array = ''("http://mirrors.ustc.edu.cn/raspbian/raspbian" "China") setvar whiptail_menu_array = ''("http://raspbian.mirror.digitalpacific.com.au/raspbian" "Australia") # - Debian } else { setvar whiptail_menu_array = ''("http://ftp.debian.org/debian/" "Global") setvar whiptail_menu_array = ''("http://ftp.uk.debian.org/debian/" "UK") setvar whiptail_menu_array = ''("http://ftp.us.debian.org/debian/" "US") setvar whiptail_menu_array = ''("http://ftp.cn.debian.org/debian/" "China") setvar whiptail_menu_array = ''("http://ftp.au.debian.org/debian/" "Australia") } setvar OPTION = $(whiptail --title "Choose Apt Mirror" --menu "Please select a Apt mirror, or choose custom for manual entry." --default-item "$apt_mirror_current" --cancel-button "$TEXT_MENU_BACK" --backtitle "$WHIP_BACKTITLE" 15 100 7 "${whiptail_menu_array[@]}" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { case (OPTION) { Custom { setvar OPTION = $(whiptail --inputbox "Enter Your Apt Mirror\n - eg: http://ftp.debian.org/debian" 9 100 "$apt_mirror_current" --title "Set Apt Mirror" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar return_value = "$OPTION" } } * { setvar return_value = "$OPTION" } } /DietPi/dietpi/func/dietpi-set_software apt-mirror $OPTION # - test it G_DIETPI-NOTIFY 2 "Updating Apt, please wait..." G_AGUP local exit_code=$? if (( $exit_code != 0 )) { whiptail --title "Apt Error:" --msgbox "Failed to update apt, exit code: $exit_code\nPlease try another Apt mirror." --backtitle $WHIP_BACKTITLE 8 65 } } #Return to this Menu setvar TARGETMENUID = '16' #delete [] unset whiptail_menu_array } "NTPD Mirror" { #Create Menu List for Whiptail local whiptail_menu_array=( "Custom" "Manually enter NTPD mirror" ) setvar whiptail_menu_array = ''('debian.pool.ntp.org' 'Debian Global') setvar whiptail_menu_array = ''('pool.ntp.org' 'Global') setvar whiptail_menu_array = ''('europe.pool.ntp.org' 'Europe') setvar whiptail_menu_array = ''('north-america.pool.ntp.org' 'North America') setvar whiptail_menu_array = ''('south-america.pool.ntp.org' 'South America') setvar whiptail_menu_array = ''('africa.pool.ntp.org' 'Africa') setvar whiptail_menu_array = ''('asia.pool.ntp.org' 'Asia') setvar whiptail_menu_array = ''('oceania.pool.ntp.org' 'Oceania') setvar OPTION = $(whiptail --title "Choose NTPD Mirror" --menu "Please select a NTPD mirror, or choose custom for manual entry.\n - Further information: \"http://www.pool.ntp.org/zone/@\"" --default-item "$ntpd_mirror_current" --cancel-button "$TEXT_MENU_BACK" --backtitle "$WHIP_BACKTITLE" 16 100 7 "${whiptail_menu_array[@]}" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar return_value = "$OPTION" case (OPTION) { Custom { setvar OPTION = $(whiptail --inputbox "Enter Your NTPD Mirror\n - eg: debian.pool.ntp.org" 9 100 "$ntpd_mirror_current" --title "Set NTPD Mirror" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar return_value = "$OPTION" } } } sed -i "/CONFIG_NTP_MIRROR=/c\CONFIG_NTP_MIRROR=$OPTION" /DietPi/dietpi.txt /DietPi/dietpi/func/dietpi-set_software ntpd-mode $(grep -m1 '^CONFIG_NTP_MODE=' /DietPi/dietpi.txt | sed 's/.*=//') #Return to this Menu setvar TARGETMENUID = '16' } #delete [] unset whiptail_menu_array } "NFS Client" { #Installed? if (( ! $nfsclient_installed )) { whiptail --title "Install NFS Client?" --yesno "NFS Client is not installed, would you like to install it now?\n\nThis will allow you access NFS shares." --yes-button "Ok" --no-button "Back" --defaultno --backtitle $WHIP_BACKTITLE 12 65 setvar CHOICE = ""$? if (( $CHOICE == 0 )) { #install nfsclient /DietPi/dietpi/dietpi-software install 110 } } else { /DietPi/dietpi/func/dietpi-set_nfsclient } #Return to this Menu setvar TARGETMENUID = '16' } Samba* { #Installed? if (( ! $sambaclient_installed )) { whiptail --title "Install Samba Client?" --yesno "Samba Client is not installed, would you like to install it now?\n\nThis will allow you access Windows shared folders, NAS and CIFS capable devices." --yes-button "Ok" --no-button "Back" --defaultno --backtitle $WHIP_BACKTITLE 12 65 setvar CHOICE = ""$? if (( $CHOICE == 0 )) { #install smbclient /DietPi/dietpi/dietpi-software install 1 } } else { /DietPi/dietpi/func/dietpi-set_smbclient } #Return to this Menu setvar TARGETMENUID = '16' } FTP* { #Installed? if (( ! $curlftpfs_installed )) { whiptail --title "Install FTP Client?" --yesno "FTP Client (curlftpfs) is not installed, would you like to install it now? \n \n - This is required to mount an FTP connection to filesystem" --yes-button "Ok" --no-button "Back" --defaultno --backtitle $WHIP_BACKTITLE 12 65 setvar CHOICE = ""$? if (( $CHOICE == 0 )) { #install curlftpfs /DietPi/dietpi/dietpi-software install 2 } } else { /DietPi/dietpi/func/dietpi-set_curlftpfs } #Return to this Menu setvar TARGETMENUID = '16' } NoIp { #Installed? if (( ! $noip_installed )) { local noip_url_address='' whiptail --title "Install NoIp Client?" --yesno "NoIp Client is not installed, would you like to install it now?\n\n- NoIp will allow you to use a fixed web address, regardless of your internet IP\neg: MySuperDooperWebsite.noip2.biz would point to this device!" --yes-button "Ok" --no-button "Back" --defaultno --backtitle $WHIP_BACKTITLE 13 70 setvar CHOICE = ""$? if (( $CHOICE == 0 )) { #Install /DietPi/dietpi/dietpi-software install 67 } } else { clear service noip2 stop noip2 -C read -p "Press any key to continue....." service noip2 start } #Return to this Menu setvar TARGETMENUID = '16' } } #Cancel } else { #Exit DietPi-Config on back to previous menu? if (( $EXITONBACK == 1 )) { #Return to this menu setvar TARGETMENUID = '16' Menu_Exit } } } setvar PROXY_ENABLED = '-1' setvar PROXY_ADDRESS = '''' setvar PROXY_PORT = '''' setvar PROXY_USERNAME = '''' setvar PROXY_PASSWORD = '''' #So we can call this in other menus (eg: submenu of this) proc Load_Proxy_Vars { setvar PROXY_ENABLED = $(cat /DietPi/dietpi.txt | grep -m1 '^CONFIG_PROXY_ENABLED=' | sed 's/.*=//') setvar PROXY_ADDRESS = $(cat /DietPi/dietpi.txt | grep -m1 '^CONFIG_PROXY_ADDRESS=' | sed 's/.*=//') setvar PROXY_PORT = $(cat /DietPi/dietpi.txt | grep -m1 '^CONFIG_PROXY_PORT=' | sed 's/.*=//') setvar PROXY_USERNAME = $(cat /DietPi/dietpi.txt | grep -m1 '^CONFIG_PROXY_USERNAME=' | sed 's/.*=//') setvar PROXY_PASSWORD = $(cat /DietPi/dietpi.txt | grep -m1 '^CONFIG_PROXY_PASSWORD=' | sed 's/.*=//') } #TARGETMENUID=17 proc Menu_NetworkAdapters_Proxy { setvar TARGETMENUID = '8' #Get current details on first menu init (PROXY_ENABLED=-1) if (( $PROXY_ENABLED == -1 )) { Load_Proxy_Vars setvar proxy_state_text = ''Disabled'' if (( $PROXY_ENABLED == 1 )) { setvar proxy_state_text = ''Enabled'' } } setvar proxy_state_text_new = ''No'' if (( $PROXY_ENABLED == 1 )) { setvar proxy_state_text_new = ''Yes'' } setvar WHIP_TITLE = ''DietPi - Proxy Network Options'' setvar OPTION = $(whiptail --title "$WHIP_TITLE" --menu "\n Current Details:\n - Status: $proxy_state_text\n - Address: $PROXY_ADDRESS\n - Port: $PROXY_PORT\n - Username: $PROXY_USERNAME\n - Password: $PROXY_PASSWORD" --cancel-button "$TEXT_MENU_BACK" --backtitle "$WHIP_BACKTITLE" 21 60 6 \ "Toggle" "Use Proxy?: $proxy_state_text_new" \ "Address" "Enter Proxy server IP/URL" \ "Port" "Enter Proxy server port" \ "Username" "Enter Proxy server username" \ "Password" "Enter Proxy server password" \ "Apply" "Save Changes" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { case (OPTION) { Toggle { ((PROXY_ENABLED++)) if (( $PROXY_ENABLED >= 2 )) { setvar PROXY_ENABLED = '0' } #Return to this menu setvar TARGETMENUID = '17' } Address { setvar OPTION = $(whiptail --inputbox "Please enter the proxy URL or IP address\n - eg: MyProxy.com" 9 65 "$PROXY_ADDRESS" --title "$WHIP_BACKTITLE" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar PROXY_ADDRESS = "$OPTION" } #Return to this Menu setvar TARGETMENUID = '17' } Port { setvar OPTION = $(whiptail --inputbox "Please enter the proxy port number\n - eg: 1234" 9 65 "$PROXY_PORT" --title "$WHIP_BACKTITLE" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar PROXY_PORT = "$OPTION" } #Return to this Menu setvar TARGETMENUID = '17' } Username { setvar OPTION = $(whiptail --inputbox "Please enter the proxy username\n - eg: JoeBloggs\n - Leave blank if not required" 10 65 "$PROXY_USERNAME" --title "$WHIP_BACKTITLE" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar PROXY_USERNAME = "$OPTION" } #Return to this Menu setvar TARGETMENUID = '17' } Password { setvar OPTION = $(whiptail --inputbox "Please enter the proxy password\n - eg: LetMeIn\n - Leave blank if not required" 10 65 "$PROXY_PASSWORD" --title "$WHIP_BACKTITLE" 3>&1 1>&2 2>&3) setvar CHOICE = ""$? if (( $CHOICE == 0 )) { setvar PROXY_PASSWORD = "$OPTION" } #Return to this Menu setvar TARGETMENUID = '17' } Apply { # - Save settings to dietpi.txt sed -i "/^CONFIG_PROXY_ENABLED=/c\CONFIG_PROXY_ENABLED=$PROXY_ENABLED" /DietPi/dietpi.txt sed -i "/^CONFIG_PROXY_ADDRESS=/c\CONFIG_PROXY_ADDRESS=$PROXY_ADDRESS" /DietPi/dietpi.txt sed -i "/^CONFIG_PROXY_PORT=/c\CONFIG_PROXY_PORT=$PROXY_PORT" /DietPi/dietpi.txt sed -i "/^CONFIG_PROXY_USERNAME=/c\CONFIG_PROXY_USERNAME=$PROXY_USERNAME" /DietPi/dietpi.txt sed -i "/^CONFIG_PROXY_PASSWORD=/c\CONFIG_PROXY_PASSWORD=$PROXY_PASSWORD" /DietPi/dietpi.txt # - Delete active export vars #unset {http,https,ftp}_proxy #Does not apply to system when running from a bash script. # - Delete any existing export settings from /etc/bash.bashrc sed -i '/{http,https,ftp}_proxy=/d' /etc/bash.bashrc # - Add export settings if (( $PROXY_ENABLED == 1 )) { if test -n $PROXY_USERNAME && test -n $PROXY_PASSWORD { cat <<< """ >> /etc/bash.bashrc export {http,https,ftp}_proxy="http://$PROXY_USERNAME:$PROXY_PASSWORD@$PROXY_ADDRESS:$PROXY_PORT" """ >> /etc/bash.bashrc export {http,https,ftp}_proxy="http://$PROXY_USERNAME:$PROXY_PASSWORD@$PROXY_ADDRESS:$PROXY_PORT" _EOF_ } else { cat <<< """ >> /etc/bash.bashrc export {http,https,ftp}_proxy="http://$PROXY_ADDRESS:$PROXY_PORT" """ >> /etc/bash.bashrc export {http,https,ftp}_proxy="http://$PROXY_ADDRESS:$PROXY_PORT" _EOF_ } } # - Ask user for reboot now to activate/disable proxy setvar REBOOT_REQUIRED = '1' setvar WHIP_TITLE = ''Proxy: Reboot required'' setvar WHIP_QUESTION = ''Your proxy settings have been saved.\n\nNB: You must reboot your system, before the new proxy settings will take effect.\n\nReboot system now?'' whiptail --title $WHIP_TITLE --yesno $WHIP_QUESTION --yes-button "Ok" --no-button "Back" --defaultno --backtitle $WHIP_BACKTITLE 13 65 setvar CHOICE = ""$? if (( $CHOICE == 0 )) { reboot } # - Reset init flag to force a reload of setings next time this menu is run. setvar PROXY_ENABLED = '-1' #Return to this menu setvar TARGETMENUID = '17' } } #Reset init flag to force a reload of setings next time this menu is run. } else { setvar PROXY_ENABLED = '-1' } } #///////////////////////////////////////////////////////////////////////////////////// # Main Loop #///////////////////////////////////////////////////////////////////////////////////// if (( $G_DIETPI_INSTALL_STAGE >= 0 )) { { #Clear Screen buffer clear if (( $TARGETMENUID == 0 )) { Menu_Main } elif (( $TARGETMENUID == 1 )) { Menu_DisplayOptions } elif (( $TARGETMENUID == 2 )) { Menu_DisplayOptions_Driver_Resolution } elif (( $TARGETMENUID == 3 )) { Menu_AdvancedOptions } elif (( $TARGETMENUID == 4 )) { Menu_PerformanceOptions } elif (( $TARGETMENUID == 5 )) { Menu_SecurityOptions } elif (( $TARGETMENUID == 6 )) { Menu_GpumemoryOptions } elif (( $TARGETMENUID == 7 )) { Menu_LanguageOptions } elif (( $TARGETMENUID == 8 )) { Menu_NetworkAdapters } elif (( $TARGETMENUID == 9 )) { Menu_NetworkAdapters_Ethernet } elif (( $TARGETMENUID == 10 )) { Menu_NetworkAdapters_Wifi } elif (( $TARGETMENUID == 11 )) { Menu_Tools } elif (( $TARGETMENUID == 12 )) { Menu_FilesystemBenchmark } elif (( $TARGETMENUID == 13 )) { Menu_Overclock } elif (( $TARGETMENUID == 14 )) { Menu_AudioOptions } elif (( $TARGETMENUID == 15 )) { Menu_StressTest } elif (( $TARGETMENUID == 16 )) { Menu_Network_Nas_Misc } elif (( $TARGETMENUID == 17 )) { Menu_NetworkAdapters_Proxy } } } else { echo -e " >> Filesystem prep has not yet completed: \n Please wait for the system to reboot " } #----------------------------------------------------------------------------------- exit #----------------------------------------------------------------------------------- }