#!/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]+$ ]] { setglobal TARGETMENUID = $1 } # - Exit DietPi-Config when going back to previous menu? if [[ $2 =~ ^-?[0-9]+$ ]] { setglobal EXITONBACK = $2 setglobal 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 #///////////////////////////////////////////////////////////////////////////////////// setglobal HW_ONBOARD_WIFI = $[sed -n 10p /DietPi/dietpi/.hw_model] setglobal 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 #///////////////////////////////////////////////////////////////////////////////////// setglobal HW_MSG_NOTSUPPORTED = '"Not Supported'" proc Info_HW_OptionNotSupported{ setglobal 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 #///////////////////////////////////////////////////////////////////////////////////// setglobal TARGETMENUID = '0' setglobal EXITONBACK = '0' setglobal TEXT_MENU_BACK = '"Back'" setglobal WHIP_BACKTITLE = ''DietPi-Config'' setglobal WHIP_TITLE = ''DietPi-Config'' setglobal WHIP_QUESTION = ''DietPi-Config'' setglobal CHOICE = '0' setglobal OPTION = '0' setglobal WHIP_SELECTION_PREVIOUS = '''' # - Whiptail sizes setglobal WHIP_OPTIONS_MAX_DISPLAY = '9' setglobal REBOOT_REQUIRED = '0' #Interger min/max value holders setglobal MIN_VALUE = '0' setglobal MAX_VALUE = '0' #TARGETMENUID=0 proc Menu_Main{ setglobal WHIP_TITLE = ''DietPi-Config'' setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { if sh-expr ' $OPTION == 1 ' { setglobal TARGETMENUID = '1' if sh-expr ' $G_HW_MODEL == 20 ' { setglobal TARGETMENUID = '0' Info_HW_OptionNotSupported } } elif sh-expr ' $OPTION == 2 ' { setglobal TARGETMENUID = '14' if sh-expr ' $G_HW_MODEL == 20 ' { setglobal TARGETMENUID = '0' Info_HW_OptionNotSupported } } elif sh-expr ' $OPTION == 3 ' { setglobal TARGETMENUID = '4' if sh-expr ' $G_HW_MODEL == 20 ' { setglobal TARGETMENUID = '0' Info_HW_OptionNotSupported } } elif sh-expr ' $OPTION == 4 ' { setglobal TARGETMENUID = '3' } elif sh-expr ' $OPTION == 5 ' { setglobal TARGETMENUID = '7' } elif sh-expr ' $OPTION == 6 ' { setglobal TARGETMENUID = '5' } elif sh-expr ' $OPTION == 7 ' { setglobal TARGETMENUID = '8' } elif sh-expr ' $OPTION == 8 ' { setglobal TARGETMENUID = '16' } elif sh-expr ' $OPTION == 9 ' { /DietPi/dietpi/dietpi-autostart setglobal REBOOT_REQUIRED = '1' } elif sh-expr ' $OPTION == 10 ' { setglobal 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. setglobal WHIP_TITLE = '' Exit DietPi-Config? '' setglobal WHIP_QUESTION = '' Exit DietPi-Config? '' whiptail --title $WHIP_TITLE --yesno $WHIP_QUESTION --yes-button "Ok" --no-button "Back" --defaultno --backtitle $WHIP_BACKTITLE 10 50 setglobal CHOICE = $Status #Exit if sh-expr ' $CHOICE == 0 ' { setglobal TARGETMENUID = '-1' #Disable Reboot when run from dietpi-software if sh-expr ' $(ps aux | grep -ci -m1 '/DietPi/dietpi/[d]ietpi-software') == 1 ' { setglobal REBOOT_REQUIRED = '0' } # Reboot Required ifsh-expr ' $REBOOT_REQUIRED == 1 ' { setglobal WHIP_TITLE = ''Changes Made - Reboot Now?'' setglobal 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 setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { #Reboot reboot } } #Return to DietPiConfig main menu } elif sh-expr ' $EXITONBACK == 0 ' { setglobal TARGETMENUID = '0' } } proc Display_Rotation_Calc_XY_Invert{ var input = $1 if sh-expr ' $G_HW_MODEL < 10 ' { var framebuffer_x = $[cat /DietPi/config.txt | grep -m1 'framebuffer'_width= | sed 's/.*=//] var framebuffer_y = $[cat /DietPi/config.txt | grep -m1 'framebuffer'_height= | sed 's/.*=//] # 0/180 if sh-expr ' $input == 0 ' { if sh-expr ' $framebuffer_x < $framebuffer_y ' { var temp = $framebuffer_x set framebuffer_x = $framebuffer_y set 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 sh-expr ' $input == 1 ' { if sh-expr ' $framebuffer_x > $framebuffer_y ' { var temp = $framebuffer_x set framebuffer_x = $framebuffer_y set 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{ setglobal TARGETMENUID = '0' var whiptail_menu_array = ''() if sh-expr ' $G_HW_MODEL == 21 ' { set whiptail_menu_array = '('"1" "Display Driver") } else { set whiptail_menu_array = '('"1" "Change Resolution") set whiptail_menu_array = '('"2" "GPU/RAM Memory Split") var lcdpanel_text = $[cat /DietPi/dietpi.txt | grep -m1 '^CONFIG_LCDPANEL=' | sed 's/.*=//] set whiptail_menu_array = '('"3" "LCD Panel addon: $lcdpanel_text") } set whiptail_menu_array = '('"14" "LED Control") #RPi only if sh-expr ' $G_HW_MODEL < 10 ' { # - Get Current Settings var overscan_enabled = $[cat /DietPi/config.txt | grep -ci -m1 'disable_overscan=0] var overscan_text = ''Disabled'' if sh-expr ' $overscan_enabled ' { set overscan_text = ''Enabled'' } var hdmi_boost_disabled = $[cat /DietPi/config.txt | grep -ci -m1 '#config_hdmi_boost=] var hdmi_boost_text = ''Enabled'' if sh-expr ' $hdmi_boost_disabled ' { set hdmi_boost_text = ''Disabled'' } var rpi_camera_module_enabled = $[cat /DietPi/config.txt | grep -ci -m1 'start_x=1] var rpi_camera_module_text = ''Disabled'' if sh-expr ' $rpi_camera_module_enabled == 1 ' { set rpi_camera_module_text = ''Enabled'' } var rpi_camera_led_enabled = $[cat /DietPi/config.txt | grep -ci -m1 'disable_camera_led=0] var rpi_camera_led_text = ''Disabled'' if sh-expr ' $rpi_camera_led_enabled == 1 ' { set rpi_camera_led_text = ''Enabled'' } var rotation_hdmi_current = $[cat /DietPi/config.txt | grep -m1 '^display_rotate=' | sed 's/.*=//] var rotation_lcd_current = $[cat /DietPi/config.txt | grep -m1 '^lcd_rotate=' | sed 's/.*=//] var vc1_key_current = $[cat /DietPi/config.txt | grep -m1 '^decode_WVC1=' | sed 's/.*=//] var mpeg2_key_current = $[cat /DietPi/config.txt | grep -m1 '^decode_MPG2=' | sed 's/.*=//] #JustBoom IR Remote var justboom_ir_remote_text = ''Disabled'' var justboom_ir_remote_enabled = '0' if test -f /etc/systemd/system/justboom-ir-mpd.service { set justboom_ir_remote_text = ''Enabled'' set justboom_ir_remote_enabled = '1' } set whiptail_menu_array = '('"4" "Rotation (HDMI) : $rotation_hdmi_current") set whiptail_menu_array = '('"5" "Rotation (LCD) : $rotation_lcd_current") set whiptail_menu_array = '('"6" "Overscan : $overscan_text") if sh-expr ' $overscan_enabled ' { var overscan_options = '( ''overscan_left' 'overscan_right' 'overscan_top' 'overscan_bottom' ) var overscan_left = $[cat /DietPi/config.txt | grep -m1 'overscan_left=' | sed 's/.*=//] var overscan_right = $[cat /DietPi/config.txt | grep -m1 'overscan_right=' | sed 's/.*=//] var overscan_top = $[cat /DietPi/config.txt | grep -m1 'overscan_top=' | sed 's/.*=//] var overscan_bottom = $[cat /DietPi/config.txt | grep -m1 'overscan_bottom=' | sed 's/.*=//] set whiptail_menu_array = '('"15" "Overscan Compensation : L:$overscan_left R:$overscan_right T:$overscan_top B:$overscan_bottom") } set whiptail_menu_array = '('"7" "HDMI Boost : $hdmi_boost_text") set whiptail_menu_array = '('"8" "RPi Camera : $rpi_camera_module_text") set whiptail_menu_array = '('"9" "RPI Camera led : $rpi_camera_led_text") set whiptail_menu_array = '('"11" "JustBoom IR remote : $justboom_ir_remote_text") set whiptail_menu_array = '('"12" "VC1 Key : $vc1_key_current") set whiptail_menu_array = '('"13" "MPEG2 Key : $mpeg2_key_current") } #Odroid Remote if sh-expr ' $G_HW_MODEL >= 10 && $G_HW_MODEL <= 12 ' { var odroid_remote_text = ''Disabled'' var odroid_remote_enabled = '0' if test -f /etc/systemd/system/odroid-remote.service { set odroid_remote_text = ''Enabled'' set odroid_remote_enabled = '1' } set whiptail_menu_array = '('"10" "Odroid remote : $odroid_remote_text") } setglobal WHIP_TITLE = ''DietPi - Display Options'' setglobal 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] setglobal CHOICE = $Status unset whiptail_menu_array if sh-expr ' $CHOICE == 0 ' { setglobal WHIP_SELECTION_PREVIOUS = $OPTION if sh-expr ' $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 setglobal TARGETMENUID = '1' } elif sh-expr ' $OPTION == 1 ' { setglobal TARGETMENUID = '2' } elif sh-expr ' $OPTION == 3 ' { if sh-expr ' $G_HW_MODEL < 10 || $G_HW_MODEL == 10 || $G_HW_MODEL == 11 || $G_HW_MODEL == 12 ' { var whiptail_menu_array = ''() set whiptail_menu_array = '('"none" "Uninstall all panels") set whiptail_menu_array = '('"waveshare32" "320x240 panel with touch input") if sh-expr ' $G_HW_MODEL == 11 ' { set whiptail_menu_array = '('"odroid-cloudshell" "320x240 panel") } if sh-expr ' $G_HW_MODEL >= 10 && $G_HW_MODEL < 20 ' { set whiptail_menu_array = '('"odroid-lcd35" "480x320 panel with touch input") } setglobal WHIP_TITLE = ''DietPi - LCD Panel'' setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { /DietPi/dietpi/func/dietpi-set_hardware lcdpanel $OPTION setglobal REBOOT_REQUIRED = '1' } unset whiptail_menu_array } else { Info_HW_OptionNotSupported } #Return to this menu setglobal TARGETMENUID = '1' } elif sh-expr ' $OPTION == 2 ' { if sh-expr ' $G_HW_MODEL < 10 || $G_HW_MODEL == 10 || $G_HW_MODEL == 12 ' { setglobal 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 setglobal TARGETMENUID = '6' } else { Info_HW_OptionNotSupported #Return to this menu setglobal TARGETMENUID = '1' } } elif sh-expr ' $OPTION == 6 ' { #RPI only if sh-expr ' $G_HW_MODEL < 10 ' { if sh-expr ' $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 setglobal REBOOT_REQUIRED = '1' } elif sh-expr ' ! $overscan_enabled ' { sed -i '/disable_overscan=/c\disable_overscan=0' /DietPi/config.txt setglobal REBOOT_REQUIRED = '1' } } else { Info_HW_OptionNotSupported } #Return to This Menu setglobal TARGETMENUID = '1' } elif sh-expr ' $OPTION == 7 ' { #RPI only if sh-expr ' $G_HW_MODEL < 10 ' { #Enabled if test $hdmi_boost_disabled = 0 { setglobal 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 setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { sed -i '/config_hdmi_boost=/c\#config_hdmi_boost=4' /DietPi/config.txt setglobal REBOOT_REQUIRED = '1' } #Disabled } elif test $hdmi_boost_disabled = 1 { setglobal 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 setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { sed -i '/config_hdmi_boost=/c\config_hdmi_boost=4' /DietPi/config.txt setglobal REBOOT_REQUIRED = '1' } } } else { Info_HW_OptionNotSupported } #Return to This Menu setglobal TARGETMENUID = '1' } elif sh-expr ' $OPTION == 8 ' { #RPI only if sh-expr ' $G_HW_MODEL < 10 ' { if sh-expr ' ! $rpi_camera_module_enabled ' { /DietPi/dietpi/func/dietpi-set_hardware rpi-camera enable setglobal REBOOT_REQUIRED = '1' } else { /DietPi/dietpi/func/dietpi-set_hardware rpi-camera disable setglobal REBOOT_REQUIRED = '1' } } else { Info_HW_OptionNotSupported } #Return to This Menu setglobal TARGETMENUID = '1' } elif sh-expr ' $OPTION == 9 ' { #RPI only if sh-expr ' $G_HW_MODEL < 10 ' { if sh-expr ' ! $rpi_camera_led_enabled ' { #enable sed -i '/disable_camera_led=/c\disable_camera_led=0' /DietPi/config.txt setglobal REBOOT_REQUIRED = '1' } else { #disable sed -i '/disable_camera_led=/c\disable_camera_led=1' /DietPi/config.txt setglobal REBOOT_REQUIRED = '1' } } else { Info_HW_OptionNotSupported } #Return to This Menu setglobal TARGETMENUID = '1' } elif sh-expr ' $OPTION == 10 ' { # - Enable if sh-expr ' ! $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 setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { /DietPi/dietpi/func/dietpi-set_hardware remoteir odroid_remote } } else { /DietPi/dietpi/func/dietpi-set_hardware remoteir none } setglobal REBOOT_REQUIRED = '1' #Return to This Menu setglobal TARGETMENUID = '1' } elif sh-expr ' $OPTION == 11 ' { # - Enable if sh-expr ' ! $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 setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { /DietPi/dietpi/func/dietpi-set_hardware remoteir justboom_ir_remote } } else { /DietPi/dietpi/func/dietpi-set_hardware remoteir none } setglobal REBOOT_REQUIRED = '1' #Return to This Menu setglobal TARGETMENUID = '1' } elif sh-expr ' $OPTION == 12 ' { setglobal WHIP_TITLE = ''DietPi - VC1 Key'' setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { if sh-expr ' ! $(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 setglobal REBOOT_REQUIRED = '1' } #Return to This Menu setglobal TARGETMENUID = '1' } elif sh-expr ' $OPTION == 13 ' { setglobal WHIP_TITLE = ''DietPi - MPEG2 Key'' setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { if sh-expr ' ! $(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 setglobal REBOOT_REQUIRED = '1' } setglobal REBOOT_REQUIRED = '1' #Return to This Menu setglobal TARGETMENUID = '1' } elif sh-expr ' $OPTION == 4 ' { var whiptail_menu_array = ''() set whiptail_menu_array = '('"0" "Disabled (default)") set whiptail_menu_array = '('"1" "90 degrees") set whiptail_menu_array = '('"2" "180 degrees") set whiptail_menu_array = '('"3" "270 degrees") set whiptail_menu_array = '('"0x10000" "Horizontal flip") set whiptail_menu_array = '('"0x20000" "Vertical flip") setglobal WHIP_TITLE = ''DietPi - Display Rotation (HDMI)'' setglobal 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] setglobal CHOICE = $Status if sh-expr ' $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 } setglobal REBOOT_REQUIRED = '1' } unset whiptail_menu_array setglobal REBOOT_REQUIRED = '1' #Return to This Menu setglobal TARGETMENUID = '1' } elif sh-expr ' $OPTION == 5 ' { var whiptail_menu_array = ''() set whiptail_menu_array = '('"0" "Disabled (default)") set whiptail_menu_array = '('"2" "180 degrees") setglobal WHIP_TITLE = ''DietPi - Display Rotation (LCD)'' setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { sed -i "/lcd_rotate=/c\lcd_rotate=$OPTION" /DietPi/config.txt setglobal REBOOT_REQUIRED = '1' } unset whiptail_menu_array setglobal REBOOT_REQUIRED = '1' #Return to This Menu setglobal TARGETMENUID = '1' } elif sh-expr ' $OPTION == 14 ' { /DietPi/dietpi/func/dietpi-led_control setglobal TARGETMENUID = '1' } } unset overscan_options } #TARGETMENUID=2 proc Menu_DisplayOptions_Driver_Resolution{ #Return to Display Options Menu setglobal TARGETMENUID = '1' #Native PC if sh-expr ' $G_HW_MODEL == 21 ' { var whiptail_menu_array = ''() var nvidia_installed = '0' var nvidia_text = ''Install GPU driver'' if sh-expr ' $(dpkg --get-selections | grep -ci -m1 '^nvidia-driver') ' { set nvidia_installed = '1' set nvidia_text = ''Uninstall GPU driver'' } set whiptail_menu_array = '(''Nvidia' " : $nvidia_text") var radeon_installed = '0' var 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 setglobal WHIP_TITLE = ''DietPi - Display Driver'' setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal TARGETMENUID = '2' if test $OPTION = 'Nvidia' { if sh-expr ' ! $nvidia_installed ' { /DietPi/dietpi/dietpi-software install 151 } else { /DietPi/dietpi/dietpi-software uninstall 151 } setglobal 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 sh-expr ' $G_HW_MODEL < 10 ' { #Get Current Values var framebuffer_x = $[cat /DietPi/config.txt | grep -m1 'framebuffer'_width= | sed 's/.*=//] var framebuffer_y = $[cat /DietPi/config.txt | grep -m1 'framebuffer'_height= | sed 's/.*=//] var display_output_text = ""$framebuffer_x X $framebuffer_y"" # - openGL detection if sh-expr ' $(cat /DietPi/config.txt | grep -ci -m1 '^dtoverlay=vc4-kms-v3d') ' { set display_output_text = ''OpenGL 1080p'' } #check for headless if sh-expr '$(cat /DietPi/dietpi.txt | grep -ci -m1 'CONFIG_HDMI_OUTPUT=0') == 1' { set display_output_text = '"Headless'" } setglobal WHIP_TITLE = ''DietPi - Resolution'' setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal REBOOT_REQUIRED = '1' #Return to This Menu setglobal 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 { match $OPTION { with "DietPi-Cloudshell" sed -i '/framebuffer_width=/c\framebuffer_width=320' /DietPi/config.txt sed -i '/framebuffer_height=/c\framebuffer_height=240' /DietPi/config.txt with 1080p sed -i '/framebuffer_width=/c\framebuffer_width=1920' /DietPi/config.txt sed -i '/framebuffer_height=/c\framebuffer_height=1080' /DietPi/config.txt with 720p sed -i '/framebuffer_width=/c\framebuffer_width=1280' /DietPi/config.txt sed -i '/framebuffer_height=/c\framebuffer_height=720' /DietPi/config.txt with 480p sed -i '/framebuffer_width=/c\framebuffer_width=854' /DietPi/config.txt sed -i '/framebuffer_height=/c\framebuffer_height=480' /DietPi/config.txt with "RPi Touchscreen" sed -i '/framebuffer_width=/c\framebuffer_width=800' /DietPi/config.txt sed -i '/framebuffer_height=/c\framebuffer_height=480' /DietPi/config.txt with PC1 sed -i '/framebuffer_width=/c\framebuffer_width=1024' /DietPi/config.txt sed -i '/framebuffer_height=/c\framebuffer_height=768' /DietPi/config.txt with PC2 sed -i '/framebuffer_width=/c\framebuffer_width=800' /DietPi/config.txt sed -i '/framebuffer_height=/c\framebuffer_height=640' /DietPi/config.txt with PC3 sed -i '/framebuffer_width=/c\framebuffer_width=640' /DietPi/config.txt sed -i '/framebuffer_height=/c\framebuffer_height=480' /DietPi/config.txt with 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 sh-expr ' $G_HW_MODEL == 10 ' { #Get Current Values var current_resolution = $[cat /DietPi/boot.ini | grep -m1 'setenv m "' | awk -F '"' '{print $2}] setglobal WHIP_TITLE = ''DietPi - Resolution'' setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal REBOOT_REQUIRED = '1' #Return to This Menu setglobal TARGETMENUID = '2' # - Always reset to HDMI sed -i '/setenv vout_mode /c\setenv vout_mode "hdmi"' /DietPi/boot.ini match $OPTION { with 1080p sed -i '/setenv m /c\setenv m "1080p"' /DietPi/boot.ini with 720p sed -i '/setenv m /c\setenv m "720p"' /DietPi/boot.ini with 480p sed -i '/setenv m /c\setenv m "480p"' /DietPi/boot.ini with PC1 sed -i '/setenv m /c\setenv m "1024x768"' /DietPi/boot.ini with "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 sh-expr ' $G_HW_MODEL == 11 ' { #Get Current Values var current_resolution = ''"" if sh-expr ' $(cat /DietPi/boot.ini | grep -m1 'setenv videoconfig "' | grep -ci -m1 1920x1080) == 1 ' { set current_resolution = '"1080p'" } elif sh-expr ' $(cat /DietPi/boot.ini | grep -m1 'setenv videoconfig "' | grep -ci -m1 1280x720) == 1 ' { set current_resolution = '"720p'" } elif sh-expr ' $(cat /DietPi/boot.ini | grep -m1 'setenv videoconfig "' | grep -ci -m1 720x480) == 1 ' { set current_resolution = '"480p'" } setglobal WHIP_TITLE = ''DietPi - Resolution'' setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal REBOOT_REQUIRED = '1' #Return to This Menu setglobal TARGETMENUID = '2' # - Always reset to hdmi sed -i '/setenv vout /c\setenv vout "hdmi"' /DietPi/boot.ini match $OPTION { with 1080p sed -i '/setenv videoconfig /c\setenv videoconfig "drm_kms_helper.edid_firmware=edid/1920x1080.bin"' /DietPi/boot.ini with 720p sed -i '/setenv videoconfig /c\setenv videoconfig "drm_kms_helper.edid_firmware=edid/1280x720.bin"' /DietPi/boot.ini with 480p sed -i '/setenv videoconfig /c\setenv videoconfig "drm_kms_helper.edid_firmware=edid/720x480.bin"' /DietPi/boot.ini with "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 sh-expr ' $G_HW_MODEL == 12 ' { #Get Current Values var 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. setglobal WHIP_TITLE = ''DietPi - Resolution'' setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { if test $current_resolution != $OPTION { setglobal 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 setglobal OPTION = $[echo -e $OPTION | tr -d '[:blank:]] sed -i "/setenv m /c\setenv m \"$OPTION\"" /DietPi/boot.ini #Return to This Menu setglobal TARGETMENUID = '2' } #Pine a64 } elif sh-expr ' $G_HW_MODEL == 40 ' { #Get Current Values var current_resolution = $[cat /DietPi/uEnv.txt | grep -m1 'optargs=disp.screen0_output_mode=' | sed 's/.*=//] setglobal WHIP_TITLE = ''DietPi - Resolution'' setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { if test $current_resolution != $OPTION { sed -i "/^optargs=disp.screen0_output_mode=/c\optargs=disp.screen0_output_mode=$OPTION" /DietPi/uEnv.txt setglobal REBOOT_REQUIRED = '1' } #Return to This Menu setglobal TARGETMENUID = '2' } } else { Info_HW_OptionNotSupported } } #TARGETMENUID=3 proc Menu_AdvancedOptions{ setglobal TARGETMENUID = '0' var whiptail_menu_array = ''() #Get Current Settings var swap_size = $[grep -m1 '^CONF_SWAPSIZE=' /etc/dphys-swapfile | sed 's/.*=//] var swap_text = ""$swap_size MB"" if sh-expr ' $swap_size == 0 ' { set swap_text = '"Disabled'" } set whiptail_menu_array = '('"Swapfile size" ": $swap_text") #NTPD var ntpd_mode_current = $[grep -m1 '^CONFIG_NTP_MODE=' /DietPi/dietpi.txt | sed 's/.*=//] var ntpd_mode_text = ''"" if sh-expr ' $ntpd_mode_current == 0 ' { set ntpd_mode_text = '"Disabled'" } elif sh-expr ' $ntpd_mode_current == 1 ' { set ntpd_mode_text = '"Boot Only'" } elif sh-expr ' $ntpd_mode_current == 2 ' { set ntpd_mode_text = '"Boot + Daily'" } elif sh-expr ' $ntpd_mode_current == 3 ' { set ntpd_mode_text = '"Boot + Hourly'" } elif sh-expr ' $ntpd_mode_current == 4 ' { set ntpd_mode_text = '"Daemon + Drift'" } set whiptail_menu_array = '('"Time sync mode" ": $ntpd_mode_text") setglobal serialconsole_state = $[cat /DietPi/dietpi.txt | grep -m1 '^CONFIG_SERIAL_CONSOLE_ENABLE=' | sed 's/.*=//] setglobal serialconsole_text = ''Disabled'' if sh-expr ' $serialconsole_state == 1 ' { setglobal serialconsole_text = ''Enabled'' } set whiptail_menu_array = '('"Update firmware" "") var bluetooth_state_text = ''Enabled'' var bluetooth_state = '1' if test -f /etc/modprobe.d/disable_bt.conf { set bluetooth_state = '0' set bluetooth_state_text = ''Disabled'' } # - No bluetooth for VM if sh-expr ' $G_HW_MODEL != 20 ' { set whiptail_menu_array = '('"Bluetooth" ": $bluetooth_state_text") } # - No serial console for VM if sh-expr ' $G_HW_MODEL != 20 ' { set whiptail_menu_array = '('"Serial console" ": $serialconsole_text") } #RPi Specific if sh-expr ' $G_HW_MODEL < 10 ' { var rpi_i2c_enabled = $[cat /DietPi/config.txt | grep -ci -m1 'dtparam=i2c_arm=on] var rpi_i2c_text = ''Disabled'' if sh-expr ' $rpi_i2c_enabled == 1 ' { set rpi_i2c_text = ''Enabled'' } var rpi_i2cbaudrate_hz = ""$shExpr(' $(cat /DietPi/config.txt | grep -m1 'i2c_arm_baudrate=' | sed 's/.*=//') / 1000 ') kHz"" var usb_max_current_enabled = $[cat /DietPi/config.txt | grep -ci -m1 'max_usb_current=1] var rpi_usbmaxcurrent_text = ''Disabled'' if test $usb_max_current_enabled = 1 { set rpi_usbmaxcurrent_text = ''Enabled'' } if sh-expr ' $G_HW_MODEL == 3 ' { var rpi3_usb_boot_bit_enabled = $[vcgencmd otp_dump | grep -m1 '17:' | grep -ci -m1 '3020000a] var rpi3_usb_boot_bit_enabled_text = ''Disabled'' if sh-expr ' $rpi3_usb_boot_bit_enabled ' { set rpi3_usb_boot_bit_enabled_text = ''Enabled'' } set whiptail_menu_array = '('"USB boot support" ": $rpi3_usb_boot_bit_enabled_text") } set whiptail_menu_array = '('"Max USB current" ": $rpi_usbmaxcurrent_text") set whiptail_menu_array = '('"I2c state" ": $rpi_i2c_text") set whiptail_menu_array = '('"I2c frequency" ": $rpi_i2cbaudrate_hz") } setglobal WHIP_TITLE = ''DietPi - Advanced Options'' setglobal 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] setglobal CHOICE = $Status unset whiptail_menu_array if sh-expr ' $CHOICE == 0 ' { if test $OPTION = "Swapfile size" { setglobal MIN_VALUE = '0' setglobal MAX_VALUE = '2000' setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { if [[ $OPTION =~ ^-?[0-9]+$ ]] && sh-expr ' $OPTION >= $MIN_VALUE ' && sh-expr ' $OPTION <= $MAX_VALUE ' { #Generate swapfile with new size if sh-expr ' $OPTION != $swap_size ' { /DietPi/dietpi/func/dietpi-set_dphys-swapfile $OPTION } } else { Info_Input_Not_Valid_Integer } } #Return to This Menu setglobal TARGETMENUID = '3' } elif test $OPTION = "Time sync mode" { setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { /DietPi/dietpi/func/dietpi-set_software ntpd-mode $OPTION } #Return to This Menu setglobal TARGETMENUID = '3' } elif test $OPTION = "Update firmware" { #RPI if sh-expr ' $G_HW_MODEL < 10 ' { setglobal 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 setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { G_RPI_UPDATE setglobal REBOOT_REQUIRED = '1' } #PineA64 } elif sh-expr ' $G_HW_MODEL == 40 ' { setglobal 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 setglobal CHOICE = $Status if sh-expr ' $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 { setglobal 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 setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { G_AGUP G_AGDUG } } #Return to This Menu setglobal TARGETMENUID = '3' } elif test $OPTION = "Max USB current" { #Enabled if sh-expr ' $usb_max_current_enabled == 1 ' { setglobal 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 setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { sed -i '/max_usb_current=/c\max_usb_current=0' /DietPi/config.txt setglobal REBOOT_REQUIRED = '1' } #Disabled } elif sh-expr ' $usb_max_current_enabled == 0 ' { setglobal 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 setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { sed -i '/max_usb_current=/c\max_usb_current=1' /DietPi/config.txt setglobal REBOOT_REQUIRED = '1' } } #Return to This Menu setglobal TARGETMENUID = '3' } elif test $OPTION = "I2c state" { if sh-expr ' $rpi_i2c_enabled == 0 ' { /DietPi/dietpi/func/dietpi-set_hardware i2c enable setglobal REBOOT_REQUIRED = '1' } else { /DietPi/dietpi/func/dietpi-set_hardware i2c disable setglobal REBOOT_REQUIRED = '1' } #Return to This Menu setglobal TARGETMENUID = '3' } elif test $OPTION = "I2c frequency" { #remove kHz from current set rpi_i2cbaudrate_hz = $[echo -e $rpi_i2cbaudrate_hz | tr -d ' kHz] setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { #check valid int if [[ $OPTION =~ ^-?[0-9]+$ ]] { /DietPi/dietpi/func/dietpi-set_hardware i2c $OPTION setglobal REBOOT_REQUIRED = '1' } else { Info_Input_Not_Valid_Integer } } #Return to This Menu setglobal TARGETMENUID = '3' } elif test $OPTION = "Serial console" { if sh-expr ' $serialconsole_state == 0 ' { /DietPi/dietpi/func/dietpi-set_hardware serialconsole enable setglobal REBOOT_REQUIRED = '1' } else { /DietPi/dietpi/func/dietpi-set_hardware serialconsole disable setglobal REBOOT_REQUIRED = '1' } #Return to This Menu setglobal TARGETMENUID = '3' } elif test $OPTION = "Bluetooth" { if sh-expr ' $bluetooth_state ' { /DietPi/dietpi/func/dietpi-set_hardware bluetooth disable } else { /DietPi/dietpi/func/dietpi-set_hardware bluetooth enable } #Return to This Menu setglobal TARGETMENUID = '3' } elif test $OPTION = "USB boot support" { if sh-expr ' ! $rpi3_usb_boot_bit_enabled ' { setglobal 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 setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { /DietPi/dietpi/func/dietpi-set_hardware rpi3_usb_boot enable setglobal REBOOT_REQUIRED = '1' # Reboot now? setglobal 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 setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { reboot } } } #Return to This Menu setglobal TARGETMENUID = '3' } } } #TARGETMENUID=4 proc Menu_PerformanceOptions{ setglobal TARGETMENUID = '0' #All devices var current_cpu_governor = $[grep -m1 '^CONFIG_CPU_GOVERNOR=' /DietPi/dietpi.txt | sed 's/.*=//] var frequency_min_cpu_governor = '1' var fp_frequency_min_cpu_governor = ''/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq'' if test -f $fp_frequency_min_cpu_governor { set frequency_min_cpu_governor = $shExpr(' $(cat "$fp_frequency_min_cpu_governor") / 1000 ') } var frequency_max_cpu_governor = '2' var fp_frequency_max_cpu_governor = ''/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq'' if test -f $fp_frequency_max_cpu_governor { set frequency_max_cpu_governor = $shExpr(' $(cat "$fp_frequency_max_cpu_governor") / 1000 ') } var arm_temp = $[G_OBTAIN_CPU_TEMP] var arm_temp_f = ''Unknown'' if [[ $arm_temp =~ ^-?[0-9]+$ ]] { set arm_temp_f = ""$shExpr(' ( $arm_temp * 9 / 5 ) + 32 ')'f"" set arm_temp = '"'c'" } var memory_total = $shExpr(' $(cat /proc/meminfo | grep -m1 'MemTotal:' | awk '{print $2}') / 1000 ') var memory_free = $shExpr(' $(cat /proc/meminfo | grep -m1 'MemFree:' | awk '{print $2}') / 1000 ') var memory_usage = $shExpr('$memory_total - $memory_free') #Create Menu List for Whiptail # - this will list the menu options available for each device. var whiptail_menu_array = ''() #Overclocking if sh-expr ' $G_HW_MODEL < 10 ' { set whiptail_menu_array = '('"Overclocking" "Set Profile") } #CPU GOV set 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" { var current_cpu_throttle_up = $[cat /DietPi/dietpi.txt | grep -m1 '^CONFIG_CPU_USAGE_THROTTLE_UP=' | sed 's/.*=//] set whiptail_menu_array = '('"CPU Throttle Up" ": $current_cpu_throttle_up%") } #Ondemand extras if test $current_cpu_governor = ondemand { var current_cpu_sample_rate = $shExpr(' $(cat /DietPi/dietpi.txt | grep -m1 '^CONFIG_CPU_ONDEMAND_SAMPLE_RATE=' | sed 's/.*=//') / 1000 ') #convert to ms set whiptail_menu_array = '('"Ondemand Sample Rate" ": $current_cpu_sample_rate ms") var current_cpu_down_factor = $[grep -m1 '^CONFIG_CPU_ONDEMAND_SAMPLE_DOWNFACTOR=' /DietPi/dietpi.txt | sed 's/.*=//] var current_cpu_down_factor_ms = $shExpr(' $current_cpu_down_factor * $current_cpu_sample_rate ') set whiptail_menu_array = '('"Ondemand Down Factor" ": $current_cpu_down_factor ($current_cpu_down_factor_ms ms)") } # User Scaling Max Freq limit. var user_frequency_max_current = $[cat /DietPi/dietpi.txt | grep -m1 '^CONFIG_CPU_MAX_FREQ=' | sed 's/.*=//] var user_frequency_max_text = ""$user_frequency_max_current MHz"" if sh-expr ' ! $user_frequency_max_current ' { set user_frequency_max_text = '"Disabled'" } set whiptail_menu_array = '('"CPU Max Freq Limit" ": $user_frequency_max_text") # User Scaling Min Freq limit. var user_frequency_min_current = $[cat /DietPi/dietpi.txt | grep -m1 '^CONFIG_CPU_MIN_FREQ=' | sed 's/.*=//] var user_frequency_min_text = ""$user_frequency_min_current MHz"" if sh-expr ' ! $user_frequency_min_current ' { set user_frequency_min_text = '"Disabled'" } set whiptail_menu_array = '('"CPU Min Freq Limit" ": $user_frequency_min_text") #RPi extras if sh-expr ' $G_HW_MODEL < 10 ' { var current_arm_temp_limit = $[cat /DietPi/config.txt | grep -m1 'temp_limit' | sed 's/.*=//] var current_initial_turbo = $[cat /DietPi/config.txt | grep -m1 'initial_turbo' | sed 's/.*=//] var text_current_initial_turbo = ""$current_initial_turbo seconds"" if sh-expr ' $current_initial_turbo == 0 ' { set text_current_initial_turbo = '"Disabled'" } set whiptail_menu_array = '('"ARM Initial Turbo" ": $text_current_initial_turbo") set whiptail_menu_array = '('"ARM Temp Limit " ": $current_arm_temp_limit 'c") #Min freqs var rpi_freq_min_enabled = '1' var rpi_freq_min_text = '"Enabled'" if sh-expr ' $(cat /DietPi/config.txt | grep -ci -m1 '#arm_freq_min=') == 1 ' { set rpi_freq_min_enabled = '0' set 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") } setglobal WHIP_TITLE = ''DietPi - Performance Options'' setglobal 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] setglobal CHOICE = $Status #delete[] array unset whiptail_menu_array if sh-expr ' $CHOICE == 0 ' { match $OPTION { with "Ondemand Down Factor"* setglobal MIN_VALUE = '1' setglobal MAX_VALUE = '200' setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { if [[ $OPTION =~ ^-?[0-9]+$ ]] && sh-expr '$OPTION <= $MAX_VALUE' && sh-expr '$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 setglobal TARGETMENUID = '4' with "Ondemand Sample Rate"* var index = '0' var 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 setglobal MIN_VALUE = $shExpr(' $(cat "${input_fp[$index]}") / 1000 ') setglobal MAX_VALUE = '300' setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { if [[ $OPTION =~ ^-?[0-9]+$ ]] && sh-expr '$OPTION <= $MAX_VALUE' && sh-expr '$OPTION >= $MIN_VALUE' { sed -i "/CONFIG_CPU_ONDEMAND_SAMPLE_RATE=/c\CONFIG_CPU_ONDEMAND_SAMPLE_RATE=$shExpr('$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 setglobal TARGETMENUID = '4' with "Lower Idle Frequencies"* setglobal 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."" var whiptail_menu_array = ''() set whiptail_menu_array = '('"Enable" "Lowers the idle frequencies for CPU, CORE, RAM.") set whiptail_menu_array = '('"Disable" "Returns the idle frequencies to defaults.") setglobal 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] setglobal CHOICE = $Status #delete[] array unset whiptail_menu_array if sh-expr ' $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 } setglobal REBOOT_REQUIRED = '1' } #Return to This Menu setglobal TARGETMENUID = '4' with "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 { var whiptail_menu_list = ''() var max_clock = '0' var 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 set whiptail_menu_list = '('"Disabled" "Returns clocks to default") #Run menu setglobal 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] setglobal CHOICE = $Status if sh-expr ' $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 setglobal TARGETMENUID = '4' with "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 { var whiptail_menu_list = ''() var min_clock = '0' var 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 set min_clock = $shExpr(' ${available_frequency_array[0]} / 1000 ') #Add disable option set whiptail_menu_list = '('"Disabled" "Returns clocks to default") #Run menu setglobal 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] setglobal CHOICE = $Status if sh-expr ' $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 setglobal TARGETMENUID = '4' with "Overclocking"* setglobal TARGETMENUID = '13' with "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 { var Description = '"Change CPU Governor:'" var whiptail_menu_array = ''() if sh-expr ' $(cat "$FP_CPU_SCALING_GOV" | grep -ci -m1 'ondemand') == 1 ' { set whiptail_menu_array = '('"ondemand" "Scales CPU frequency between $frequency_min_cpu_governor MHz and $frequency_max_cpu_governor MHz.") set Description = '"\nOndemand | Dynamic CPU frequency based on usage (recommended).'" } if sh-expr ' $(cat "$FP_CPU_SCALING_GOV" | grep -ci -m1 'interactive') == 1 ' { set whiptail_menu_array = '('"interactive" "Scales CPU frequency between $frequency_min_cpu_governor MHz and $frequency_max_cpu_governor MHz.") set Description = '"\nInteractive | Dynamic CPU frequency based on usage.'" } if sh-expr ' $(cat "$FP_CPU_SCALING_GOV" | grep -ci -m1 'conservative') == 1 ' { set whiptail_menu_array = '('"conservative" "Scales CPU frequency between $frequency_min_cpu_governor MHz and $frequency_max_cpu_governor MHz.") set Description = '"\nConservative | Same as ondemand. Bias towards powersaving, slower scaling. '" } if sh-expr ' $(cat "$FP_CPU_SCALING_GOV" | grep -ci -m1 'powersave') == 1 ' { set whiptail_menu_array = '('"powersave" "Limits CPU frequency to $frequency_min_cpu_governor MHz.") set Description = '"\nPowersave | Static. Reduces energy consumption, heat, performance.'" } if sh-expr ' $(cat "$FP_CPU_SCALING_GOV" | grep -ci -m1 'performance') == 1 ' { set whiptail_menu_array = '('"performance" "Forces CPU frequency to $frequency_max_cpu_governor MHz.") set Description = '"\nPerformance | Static. Increases energy consumption, heat, performance.'" } setglobal 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] setglobal CHOICE = $Status #delete[] array unset whiptail_menu_array if sh-expr ' $CHOICE == 0 ' { sed -i "/CONFIG_CPU_GOVERNOR=/c\CONFIG_CPU_GOVERNOR=$OPTION" /DietPi/dietpi.txt /DietPi/dietpi/dietpi-cpu_set } } #Return to This Menu setglobal TARGETMENUID = '4' with "CPU Throttle Up"* setglobal MIN_VALUE = '30' setglobal MAX_VALUE = '95' setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { if [[ $OPTION =~ ^-?[0-9]+$ ]] && sh-expr '$OPTION <= $MAX_VALUE' && sh-expr '$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 setglobal TARGETMENUID = '4' with "ARM Initial Turbo"* setglobal MIN_VALUE = '0' setglobal MAX_VALUE = '60' setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { if [[ $OPTION =~ ^-?[0-9]+$ ]] && sh-expr '$OPTION <= $MAX_VALUE' && sh-expr '$OPTION >= $MIN_VALUE' { sed -i "/initial_turbo=/c\initial_turbo=$OPTION" /DietPi/config.txt setglobal REBOOT_REQUIRED = '1' } else { Info_Input_Not_Valid_Integer } } #Return to this menu setglobal TARGETMENUID = '4' with "ARM Temp Limit"* setglobal MIN_VALUE = '45' setglobal MAX_VALUE = '85' setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { if [[ $OPTION =~ ^-?[0-9]+$ ]] && sh-expr '$OPTION <= $MAX_VALUE' && sh-expr '$OPTION >= $MIN_VALUE' { if sh-expr ' $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 setglobal REBOOT_REQUIRED = '1' } else { Info_Input_Not_Valid_Integer } } #Return to this menu setglobal TARGETMENUID = '4' } } } proc Change_Password{ var PasswordRecieved = '0' #1st input var passw1 = $[whiptail --passwordbox "Please Enter Your New Password" 8 60 --title "Change PW" !3 > !1 !1 > !2 !2 > !3] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { sh-expr 'PasswordRecieved++' } #2nd input (confirm) var passw2 = $[whiptail --passwordbox "Please Confirm Your New Password" 8 60 --title "Confirm PW" !3 > !1 !1 > !2 !2 > !3] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { sh-expr 'PasswordRecieved++' } #Password Mismatch if test $passw1 != $passw2 { setglobal 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 sh-expr ' $PasswordRecieved == 2 ' { echo -e "$passw1\n$passw1" | passwd -q root setglobal WHIP_TITLE = ''Password Applied'' whiptail --title $WHIP_TITLE --msgbox " Your new password has successfully been applied." 8 60 #Aborted } else { setglobal 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 var hostname_existing = $[cat /etc/hostname] setglobal OPTION = $[whiptail --inputbox "Enter Your New Hostname" 8 60 $hostname_existing --title "Change Hostname" --backtitle $WHIP_BACKTITLE !3 > !1 !1 > !2 !2 > !3] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' && test $hostname_existing != $OPTION { /DietPi/dietpi/func/change_hostname $OPTION setglobal REBOOT_REQUIRED = '1' setglobal 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 setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { reboot } #Aborted } else { setglobal 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{ setglobal TARGETMENUID = '0' setglobal WHIP_TITLE = ''DietPi - Security Options'' setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { if sh-expr ' $OPTION == 1 ' { Change_Password setglobal TARGETMENUID = '5' } elif sh-expr ' $OPTION == 2 ' { Change_Hostname setglobal TARGETMENUID = '5' } } } #TARGETMENUID=6 proc Menu_GpumemoryOptions{ setglobal TARGETMENUID = '1' #Get Current MemorySplit Settings and Data var gpu_mem_current = '0' var ram_mem_current = '0' var ram_mem_total = '0' if sh-expr ' $G_HW_MODEL == 0 ' { set gpu_mem_current = $[grep -m1 'gpu_mem_256=' /DietPi/config.txt | sed 's/.*=//] set ram_mem_current = $shExpr('256-gpu_mem_current') set ram_mem_total = '256' } elif sh-expr ' $G_HW_MODEL == 1 ' { set gpu_mem_current = $[grep -m1 'gpu_mem_512=' /DietPi/config.txt | sed 's/.*=//] set ram_mem_current = $shExpr('512-gpu_mem_current') set ram_mem_total = '512' } elif sh-expr ' $G_HW_MODEL == 2 ' || sh-expr ' $G_HW_MODEL == 3 ' { set gpu_mem_current = $[grep -m1 'gpu_mem_1024=' /DietPi/config.txt | sed 's/.*=//] set ram_mem_current = $shExpr('1024-gpu_mem_current') set ram_mem_total = '1024' } elif sh-expr ' $G_HW_MODEL == 10 ' { set ram_mem_current = $[free -m | grep -m1 'Mem:' | awk '{print $2}] set gpu_mem_current = $shExpr('1024-ram_mem_current') } elif sh-expr ' $G_HW_MODEL == 12 ' { set ram_mem_current = $[free -m | grep -m1 'Mem:' | awk '{print $2}] set gpu_mem_current = $shExpr('2048-ram_mem_current') } setglobal WHIP_TITLE = ''DietPi - GPU/RAM Split'' #RPi's if sh-expr ' $G_HW_MODEL < 10 ' { #Create array for storing menu selectable options. var -a option_name = '( '"Server" "Desktop" "Kodi" "Gaming" ) #Create array for storing available GPU values var -i available_gpu_values = '( '16 64 128 128 ) if sh-expr ' $G_HW_MODEL == 0 ' { echo -e "As above, array is defaulted to RPi1 - 256mb" &> /dev/null } elif sh-expr ' $G_HW_MODEL == 1 ' { compat array-assign available_gpu_values '2' '128' compat array-assign available_gpu_values '3' '192' } elif sh-expr ' $G_HW_MODEL == 2 ' || sh-expr ' $G_HW_MODEL == 3 ' { compat array-assign available_gpu_values '1' '128' compat array-assign available_gpu_values '2' '192' compat array-assign available_gpu_values '3' '256' } #Generate text array list for whiptail var 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 setglobal 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] setglobal CHOICE = $Status if sh-expr ' $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]) setglobal REBOOT_REQUIRED = '1' #Return to this menu setglobal TARGETMENUID = '6' } #delete [] array unset option_output_text unset option_name unset available_gpu_values #Odroid C1 } elif sh-expr ' $G_HW_MODEL == 10 ' { #Odroid HDMI/headless extra data var display_output_enabled = $[cat /DietPi/boot.ini | grep -ci -m1 '^setenv hdmioutput "1"] var display_vpu_enabled = $[cat /DietPi/boot.ini | grep -ci -m1 '^setenv vpu "1"] var display_output_text = '"Enabled'" var display_vpu_text = '"Enabled'" if sh-expr ' $display_output_enabled == 0 ' { set display_output_text = '"Disabled'" } if sh-expr ' $display_vpu_enabled == 0 ' { set display_vpu_text = '"Disabled'" } setglobal 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] match $OPTION { with Headless sed -i '/setenv hdmioutput /c\setenv hdmioutput "0"' /DietPi/boot.ini sed -i '/setenv vpu /c\setenv vpu "0"' /DietPi/boot.ini setglobal REBOOT_REQUIRED = '1' #Return to this menu setglobal TARGETMENUID = '6' with Server sed -i '/setenv hdmioutput /c\setenv hdmioutput "1"' /DietPi/boot.ini sed -i '/setenv vpu /c\setenv vpu "0"' /DietPi/boot.ini setglobal REBOOT_REQUIRED = '1' #Return to this menu setglobal TARGETMENUID = '6' with Desktop sed -i '/setenv hdmioutput /c\setenv hdmioutput "1"' /DietPi/boot.ini sed -i '/setenv vpu /c\setenv vpu "1"' /DietPi/boot.ini setglobal REBOOT_REQUIRED = '1' #Return to this menu setglobal TARGETMENUID = '6' } #C2 } elif sh-expr ' $G_HW_MODEL == 12 ' { #Odroid HDMI/headless extra data var display_output_enabled = $[cat /DietPi/boot.ini | grep -ci -m1 '^setenv nographics "0"] var display_output_text = '"Enabled'" if sh-expr ' $display_output_enabled == 0 ' { set display_output_text = '"Disabled'" } setglobal 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] match $OPTION { with Headless sed -i '/setenv nographics /c\setenv nographics "1"' /DietPi/boot.ini setglobal REBOOT_REQUIRED = '1' #Return to this menu setglobal TARGETMENUID = '6' with Default sed -i '/setenv nographics /c\setenv nographics "0"' /DietPi/boot.ini setglobal REBOOT_REQUIRED = '1' #Return to this menu setglobal TARGETMENUID = '6' } } else { Info_HW_OptionNotSupported } } #TARGETMENUID=7 proc Menu_LanguageOptions{ setglobal TARGETMENUID = '0' setglobal WHIP_TITLE = ''DietPi - Language and Regional Options'' setglobal 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] match $OPTION { with Locale setglobal REBOOT_REQUIRED = '1' dpkg-reconfigure locales var locale_new = $[grep -m1 '^LANG=' /etc/default/locale | sed 's/.*=//] # Sanity, No result, revert back to default if test -z $locale_new { set 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 setglobal TARGETMENUID = '7' with Timezone setglobal REBOOT_REQUIRED = '1' dpkg-reconfigure tzdata #Return to this menu setglobal TARGETMENUID = '7' with Keyboard setglobal 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 setglobal TARGETMENUID = '7' } } setglobal ETH_IP_STATIC = '"0.0.0.0'" setglobal ETH_GATEWAY_STATIC = '"0.0.0.0'" setglobal ETH_MASK_STATIC = '"0.0.0.0'" setglobal ETH_DNS_STATIC = '"0.0.0.0'" setglobal ETH_INDEX = '0' setglobal ETH_DISABLED = '0' setglobal ETH_HARDWARE = '0' setglobal ETH_CONNECTED = '0' setglobal ETH_IP = '"0.0.0.0'" setglobal ETH_GATEWAY = '"0.0.0.0'" setglobal ETH_MASK = '"0.0.0.0'" setglobal ETH_DNS = '"0.0.0.0'" setglobal ETH_MODE = '1' #0=static 1=dhcp setglobal ETH_MODE_TARGET = '0' setglobal WIFI_IP_STATIC = '"0.0.0.0'" setglobal WIFI_GATEWAY_STATIC = '"0.0.0.0'" setglobal WIFI_MASK_STATIC = '"0.0.0.0'" setglobal WIFI_DNS_STATIC = '"0.0.0.0'" setglobal WIFI_INDEX = '0' setglobal WIFI_DISABLED = '0' setglobal WIFI_HARDWARE = '0' setglobal WIFI_CONNECTED = '0' setglobal WIFI_IP = '"0.0.0.0'" setglobal WIFI_GATEWAY = '"0.0.0.0'" setglobal WIFI_MASK = '"0.0.0.0'" setglobal WIFI_DNS = '"0.0.0.0'" setglobal WIFI_MODE = '1' #0=static 1=dhcp setglobal WIFI_MODE_TARGET = '0' setglobal WIFI_SSID = '"WifiSSID'" setglobal WIFI_KEY = '"WifiKey'" setglobal WIFI_BITRATE = '0' setglobal WIFI_SIGNALSTRENGTH = '0' setglobal WIFI_HOTSPOT = '0' setglobal WIFI_COUNTRYCODE = '"Unknown'" setglobal WIFI_AUTO_RECONNECT_ACTIVE = '0' proc Network_ETH_CopyCurrentToStatic{ #Apply, Only if we have a connection if sh-expr ' $ETH_CONNECTED == 1 ' { setglobal ETH_IP_STATIC = $ETH_IP setglobal ETH_GATEWAY_STATIC = $ETH_GATEWAY setglobal ETH_MASK_STATIC = $ETH_MASK setglobal ETH_DNS_STATIC = $ETH_DNS } } proc Network_WIFI_CopyCurrentToStatic{ #Apply, Only if we have a connection if sh-expr ' $WIFI_CONNECTED == 1 ' { setglobal WIFI_IP_STATIC = $WIFI_IP setglobal WIFI_GATEWAY_STATIC = $WIFI_GATEWAY setglobal WIFI_MASK_STATIC = $WIFI_MASK setglobal 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 sh-expr ' $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 sh-expr ' $ETH_DISABLED == 0 ' { ifup eth$ETH_INDEX } if sh-expr ' $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 sh-expr ' $ETH_DISABLED == 0 ' { sed -i "/allow-hotplug eth/c\allow-hotplug eth$ETH_INDEX" /etc/network/interfaces } if sh-expr ' $WIFI_DISABLED == 0 ' { sed -i "/allow-hotplug wlan/c\allow-hotplug wlan$WIFI_INDEX" /etc/network/interfaces } #Save STATIC/DHCP # - eth if sh-expr ' $ETH_MODE_TARGET == 0 ' { #Change to STATIC sed -i "/iface eth/c\iface eth$ETH_INDEX inet static" /etc/network/interfaces } elif sh-expr ' $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 setglobal ETH_MODE = $ETH_MODE_TARGET # - Wifi if sh-expr ' $WIFI_MODE_TARGET == 0 ' { #Change to STATIC sed -i "/iface wlan/c\iface wlan$WIFI_INDEX inet static" /etc/network/interfaces } elif sh-expr ' $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 setglobal 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 sh-expr ' $ETH_DISABLED == 0 ' && sh-expr ' $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 sh-expr ' ! $WIFI_DISABLED ' && sh-expr ' $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 sh-expr ' $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 sh-expr ' $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 sh-expr ' $1 == 0 ' { setglobal OPTION = $[whiptail --inputbox "Enter Your New Ip Address" 8 60 $ETH_IP_STATIC --title "Set Static Ip Address" !3 > !1 !1 > !2 !2 > !3] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal ETH_IP_STATIC = $OPTION } #wifi } elif sh-expr ' $1 == 1 ' { setglobal OPTION = $[whiptail --inputbox "Enter Your New Ip Address" 8 60 $WIFI_IP_STATIC --title "Set Static Ip Address" !3 > !1 !1 > !2 !2 > !3] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal WIFI_IP_STATIC = $OPTION } } } proc Change_StaticGateway{ #Ethernet if sh-expr ' $1 == 0 ' { setglobal OPTION = $[whiptail --inputbox "Enter Your New Gateway Address" 8 60 $ETH_GATEWAY_STATIC --title "Set Static Gateway Address" !3 > !1 !1 > !2 !2 > !3] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal ETH_GATEWAY_STATIC = $OPTION } #wifi } elif sh-expr ' $1 == 1 ' { setglobal OPTION = $[whiptail --inputbox "Enter Your New Gateway Address" 8 60 $WIFI_GATEWAY_STATIC --title "Set Static Gateway Address" !3 > !1 !1 > !2 !2 > !3] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal WIFI_GATEWAY_STATIC = $OPTION } } } proc Change_StaticMask{ #Ethernet if sh-expr ' $1 == 0 ' { setglobal OPTION = $[whiptail --inputbox "Enter Your New Mask Address" 8 60 $ETH_MASK_STATIC --title "Set Static Mask Address" !3 > !1 !1 > !2 !2 > !3] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal ETH_MASK_STATIC = $OPTION } #wifi } elif sh-expr ' $1 == 1 ' { setglobal OPTION = $[whiptail --inputbox "Enter Your New Mask Address" 8 60 $WIFI_MASK_STATIC --title "Set Static Mask Address" !3 > !1 !1 > !2 !2 > !3] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal WIFI_MASK_STATIC = $OPTION } } } proc Change_StaticDns{ #$1 = Adapater type | 0=Eth, 1=WiFi #Store current into var var current_value = '0' # - Ethernet if sh-expr ' $1 == 0 ' { set current_value = $ETH_DNS_STATIC # - WiFi } elif sh-expr ' $1 == 1 ' { set current_value = $WIFI_DNS_STATIC } var return_value = $current_value #Create Menu List for Whiptail var 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" ) setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { match $OPTION { with Custom setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { set return_value = $OPTION } with * set return_value = $OPTION } } #delete [] unset whiptail_menu_array #Apply new value # - Ethernet if sh-expr ' $1 == 0 ' { setglobal ETH_DNS_STATIC = $return_value # - WiFi } elif sh-expr ' $1 == 1 ' { setglobal WIFI_DNS_STATIC = $return_value } } proc Change_WifiSsid{ setglobal OPTION = $[whiptail --inputbox "Enter the SSID name to connect to." 8 60 $WIFI_SSID --title "Set Your SSID" !3 > !1 !1 > !2 !2 > !3] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal WIFI_SSID = $OPTION } } proc Change_WifiKey{ setglobal OPTION = $[whiptail --inputbox "Enter the Access Key (WPA/WEP)." 8 60 $WIFI_KEY --title "Set Your Access Key" !3 > !1 !1 > !2 !2 > !3] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal WIFI_KEY = $OPTION } } proc Change_WifiCountryCode{ var wifi_country_code_target = $WIFI_COUNTRYCODE var whiptail_menu_array = ''() set whiptail_menu_array = '('"GB" "Europe / Great Britain") set whiptail_menu_array = '('"US" "United States") set whiptail_menu_array = '('"JP" "Japan") set whiptail_menu_array = '('"CN" "China") set whiptail_menu_array = '('"Manual" "Enter a custom country code") var description_text = '"Choose a country, to enable WiFi channels and power ratings allowed in your country.'" setglobal WHIP_TITLE = ''Change WiFi country code'' setglobal 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] setglobal CHOICE = $Status #delete [] unset whiptail_menu_array if sh-expr ' $CHOICE == 0 ' { match $OPTION { with Manual setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { set wifi_country_code_target = $OPTION } with * set 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 setglobal 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 var wifi_ssid_list = ''() for ((i=0; i<${#wifi_ssid_array[@]}; i++)) do wifi_ssid_list+=("$i" "${wifi_ssid_array[$i]}") done setglobal WHIP_TITLE = ''DietPi-Config - Wifi SSID Scan'' setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal 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{ setglobal 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 setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { #Apply Changes clear echo -e "Connecting to $WIFI_SSID , please wait" Network_ApplyChanges } } proc Ethernet_Reconnect{ setglobal 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 setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { #Apply Changes clear echo -e "Reconnecting Ethernet , please wait" Network_ApplyChanges } } setglobal INTERNET_ONLINE = '0' # 0=not tested, 1=failed, 2=online setglobal INTERNET_URL = ''http://mirrordirector.raspbian.org'' proc Network_CheckInternetConnection{ setglobal INTERNET_ONLINE = '0' #Not tested #Check for connection wget --spider --timeout=10 --tries=2 $INTERNET_URL if sh-expr ' $? == 0 ' { setglobal INTERNET_ONLINE = '2' #Online } else { setglobal 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 setglobal ETH_IP_STATIC = $[cat -n /tmp/net_interfaces | grep 'address ' | sed -n 1p | awk '{print $3}] setglobal ETH_GATEWAY_STATIC = $[cat -n /tmp/net_interfaces | grep 'gateway ' | sed -n 1p | awk '{print $3}] setglobal ETH_MASK_STATIC = $[cat -n /tmp/net_interfaces | grep 'netmask ' | sed -n 1p | awk '{print $3}] setglobal ETH_DNS_STATIC = $[cat -n /tmp/net_interfaces | grep 'dns-nameservers ' | sed -n 1p | awk '{print $3,$4}] setglobal ETH_INDEX = $[sed -n 1p /DietPi/dietpi/.network] setglobal ETH_DISABLED = $[cat /tmp/net_interfaces | grep -ci -m1 "#allow-hotplug eth$ETH_INDEX] setglobal ETH_HARDWARE = '0' setglobal ETH_CONNECTED = '0' setglobal ETH_IP = ''0.0.0.0'' setglobal ETH_GATEWAY = ''0.0.0.0'' setglobal ETH_MASK = ''0.0.0.0'' setglobal ETH_DNS = ''0.0.0.0'' setglobal ETH_MODE = '1' setglobal ETH_MODE_TARGET = $ETH_MODE setglobal WIFI_IP_STATIC = $[cat -n /tmp/net_interfaces | grep 'address ' | sed -n 2p | awk '{print $3}] setglobal WIFI_GATEWAY_STATIC = $[cat -n /tmp/net_interfaces | grep 'gateway ' | sed -n 2p | awk '{print $3}] setglobal WIFI_MASK_STATIC = $[cat -n /tmp/net_interfaces | grep 'netmask ' | sed -n 2p | awk '{print $3}] setglobal WIFI_DNS_STATIC = $[cat -n /tmp/net_interfaces | grep 'dns-nameservers ' | sed -n 2p | awk '{print $3,$4}] setglobal WIFI_INDEX = $[sed -n 2p /DietPi/dietpi/.network] setglobal WIFI_DISABLED = $[cat /tmp/net_interfaces | grep -ci -m1 "#allow-hotplug wlan$WIFI_INDEX] setglobal WIFI_HARDWARE = '0' setglobal WIFI_CONNECTED = '0' setglobal WIFI_IP = ''0.0.0.0'' setglobal WIFI_GATEWAY = ''0.0.0.0'' setglobal WIFI_MASK = ''0.0.0.0'' setglobal WIFI_DNS = ''0.0.0.0'' setglobal WIFI_MODE = '1' setglobal WIFI_MODE_TARGET = $WIFI_MODE setglobal WIFI_SSID = ''MySuperDooperWiFi'' setglobal WIFI_KEY = ''0123456789'' #Get extra wifi stats setglobal WIFI_BITRATE = '0' setglobal WIFI_SIGNALSTRENGTH = '0' # - Hotspot enabled? setglobal WIFI_HOTSPOT = '0' if test -f /usr/sbin/hostapd { setglobal 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 setglobal WIFI_COUNTRYCODE = ''GB'' if test -n $[which iw] { setglobal WIFI_COUNTRYCODE = $[iw reg get | grep -m1 'country' | awk '{print $2}' | tr -d ':] } #?????????????????????????????????????????????????????? #eth if test -d /sys/class/net/eth$ETH_INDEX { #Hardware setglobal ETH_HARDWARE = '1' #Static or Dhcp? setglobal ETH_MODE = $[cat /tmp/net_interfaces | grep -ci -m1 "iface eth$ETH_INDEX inet dhcp] setglobal ETH_MODE_TARGET = $ETH_MODE #Connected and Valid IP? setglobal ETH_CONNECTED = $[ip r | grep -ci -m1 "eth$ETH_INDEX] #Enabled and Connected if sh-expr ' $ETH_DISABLED == 0 ' && sh-expr ' $ETH_CONNECTED == 1 ' { setglobal ETH_IP = $[ifconfig eth$ETH_INDEX | grep -m1 'inet' | awk '{ print $2 }' | sed 's/addr://g] setglobal ETH_GATEWAY = $[ip r | grep -m1 'default' | awk '{ print $3 }] setglobal ETH_MASK = $[ifconfig eth$ETH_INDEX | grep -m1 'inet' | awk '{ print $4 }' | sed 's/Mask://g] setglobal ETH_DNS = $[grep -m1 'nameserver' /etc/resolv.conf | awk '{print $2}] } } if test -d /sys/class/net/wlan$WIFI_INDEX { #Hardware setglobal WIFI_HARDWARE = '1' #Static or Dhcp? setglobal WIFI_MODE = $[cat /tmp/net_interfaces | grep -ci -m1 "iface wlan$WIFI_INDEX inet dhcp] setglobal WIFI_MODE_TARGET = $WIFI_MODE #Connected and Valid IP? setglobal WIFI_CONNECTED = $[ip r | grep -ci -m1 "wlan$WIFI_INDEX] #Wifi Extras setglobal WIFI_SSID = $[grep -m1 '^AUTO_SETUP_NET_WIFI_SSID=' /DietPi/dietpi.txt | sed 's/.*=//] setglobal WIFI_KEY = $[grep -m1 '^AUTO_SETUP_NET_WIFI_KEY=' /DietPi/dietpi.txt | sed 's/.*=//] #Enabled and Connected if sh-expr ' $WIFI_DISABLED == 0 ' && sh-expr ' $WIFI_CONNECTED == 1 ' { setglobal WIFI_IP = $[ifconfig wlan$WIFI_INDEX | grep -m1 'inet' | awk '{ print $2 }' | sed 's/addr://g] setglobal WIFI_GATEWAY = $[ip r | grep -m1 'default' | awk '{ print $3 }] setglobal WIFI_MASK = $[ifconfig wlan$WIFI_INDEX | grep -m1 'inet' | awk '{ print $4 }' | sed 's/Mask://g] setglobal WIFI_DNS = $[cat /etc/resolv.conf | grep -m1 nameserver | awk '{print $2}] #Get extra wifi stats setglobal WIFI_BITRATE = $[iwconfig wlan$WIFI_INDEX | grep -m1 'Bit Rate' | awk '{ print $2 }' | sed 's/Rate[:=]//g] setglobal 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]+$ ]] && sh-expr ' $WIFI_SIGNALSTRENGTH < 0 ' { setglobal WIFI_SIGNALSTRENGTH = ""$WIFI_SIGNALSTRENGTH dBm"" } else { setglobal WIFI_SIGNALSTRENGTH = ""$WIFI_SIGNALSTRENGTH %"" } } } #cleanup tmp rm /tmp/net_interfaces &> /dev/null } #TARGETMENUID=8 proc Menu_NetworkAdapters{ setglobal TARGETMENUID = '0' #Check Network Network_GetData var whiptail_menu_array = ''() #Obtain enabled/disabled status var eth_disabled_text = ''Enabled'' if sh-expr ' $ETH_DISABLED == 1 ' { set eth_disabled_text = ''Disabled'' } var wlan_disabled_text = ''Enabled'' if sh-expr ' $WIFI_DISABLED == 1 ' { set wlan_disabled_text = ''Disabled'' } #Obtain Hardware Status var eth_hardware_text = ''Available'' if sh-expr ' ! $ETH_HARDWARE ' { set eth_hardware_text = ''Not Found'' } var wlan_hardware_text = ''Available'' if sh-expr ' ! $WIFI_HARDWARE ' { set wlan_hardware_text = ''Not Found'' } #Obtain Connected/Carrier Status var eth_connected_text = ''Disconnected'' if sh-expr ' $ETH_CONNECTED == 1 ' { set eth_connected_text = ''Connected'' } var wlan_connected_text = ''Disconnected'' if sh-expr ' $WIFI_CONNECTED == 1 ' { set wlan_connected_text = ''Connected'' if sh-expr ' $WIFI_HOTSPOT == 1 ' { set wlan_connected_text = '"Wifi Hotspot Mode'" } } #Internet Connection Status var Internet_connected_text = ''Please run Internet Test'' if sh-expr ' $INTERNET_ONLINE == 2 ' { set Internet_connected_text = ''Online'' } elif sh-expr ' $INTERNET_ONLINE == 1 ' { set Internet_connected_text = ''Offline / Failed'' } #Set to Not Tested for next loop setglobal INTERNET_ONLINE = '0' #IPv6 status var ipv6_enabled = '1' var ipv6_status_text = ''Enabled'' if test ! -d /proc/sys/net/ipv6 { set ipv6_enabled = '0' set ipv6_status_text = ''Disabled'' } #Proxy settings (global vars, force an int to obtain current values stored in dietpi.txt) Load_Proxy_Vars var proxy_state_text = ''Disabled'' if sh-expr ' $PROXY_ENABLED == 1 ' { set proxy_state_text = ""Enabled | $PROXY_ADDRESS:$PROXY_PORT"" } # - Reset init flag. Ensures Menu_Proxy() reloads current settings. setglobal PROXY_ENABLED = '-1' set whiptail_menu_array = '('"Ethernet" "Change Wired Network Settings") set whiptail_menu_array = '('"WiFi" "Change Wireless Network Settings") # - Onboard WiFi var onboard_wifi_enabled = '1' # RPi 3/ZeroW if sh-expr ' $HW_ONBOARD_WIFI == 1 ' { if test -f /etc/modprobe.d/disable_wifi_rpi3_onboard.conf { set onboard_wifi_enabled = '0' set whiptail_menu_array = '('"Onboard WiFi" "Disabled | select to toggle") } else { set whiptail_menu_array = '('"Onboard WiFi" "Enabled | select to toggle") } } set whiptail_menu_array = '('"IPv6" "Toggle IPv6 Support") set whiptail_menu_array = '('"Test" "Run the Internet Connection Test") set whiptail_menu_array = '('"Proxy" "Configure proxy settings") setglobal WHIP_TITLE = ''DietPi - Network Options: Adapters'' setglobal 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] setglobal CHOICE = $Status unset whiptail_menu_array if sh-expr ' $CHOICE == 0 ' { match $OPTION { with "Onboard WiFi" if sh-expr ' $onboard_wifi_enabled ' { /DietPi/dietpi/func/dietpi-set_hardware wifimodules onboard_disable } else { /DietPi/dietpi/func/dietpi-set_hardware wifimodules onboard_enable } setglobal 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 setglobal TARGETMENUID = '8' with IPv6 #Disable if sh-expr ' $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 setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { if sh-expr ' 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 sh-expr ' ! $(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 setglobal 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 setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { if sh-expr ' 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 setglobal REBOOT_REQUIRED = '1' } } #Return to this Menu setglobal TARGETMENUID = '8' with Ethernet #No hardware found if sh-expr ' ! $ETH_HARDWARE ' { setglobal WHIP_TITLE = '' Error: No Ethernet Hardware was found.'' setglobal 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 setglobal TARGETMENUID = '8' #Disabled } elif sh-expr ' $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 setglobal CHOICE = $Status #Confirm action if sh-expr ' $CHOICE == 0 ' { setglobal ETH_DISABLED = '0' Network_ApplyChanges setglobal TARGETMENUID = '9' } else { #Return to this Menu setglobal TARGETMENUID = '8' } } else { setglobal TARGETMENUID = '9' } with WiFi #Disabled | Offer chance to enable (also enables wifi modules) if sh-expr ' $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 setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal WIFI_DISABLED = '0' Network_ApplyChanges } # Return to this Menu setglobal TARGETMENUID = '8' # - No hardware found } elif sh-expr ' ! $WIFI_HARDWARE ' { setglobal 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 setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal WIFI_DISABLED = '1' Network_ApplyChanges } #Return to this Menu setglobal TARGETMENUID = '8' } else { setglobal TARGETMENUID = '10' } with Test #Request URL to test setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal INTERNET_URL = $OPTION Network_CheckInternetConnection } #Return to this Menu setglobal TARGETMENUID = '8' with Proxy setglobal TARGETMENUID = '17' } #Cancel } else { #Exit DietPi-Config on back to previous menu? if sh-expr ' $EXITONBACK == 1 ' { #Return to this menu setglobal TARGETMENUID = '8' Menu_Exit } } } #TARGETMENUID=9 proc Menu_NetworkAdapters_Ethernet{ setglobal TARGETMENUID = '8' # - Get current Mode details var mode_current = ''DHCP'' if sh-expr ' $ETH_MODE == 0 ' { set mode_current = ''STATIC'' } # - Target Details var mode_target = ''DHCP'' if sh-expr ' $ETH_MODE_TARGET == 0 ' { set mode_target = ''STATIC'' } var whip_options_total = '0' var description_text = '''' var whiptail_menu_array = ''() setglobal WHIP_TITLE = ''DietPi - Ethernet Network Options'' set whiptail_menu_array = '('"Change Mode" "$mode_target"); sh-expr 'whip_options_total++' # - show static options if sh-expr ' $ETH_MODE_TARGET == 0 ' { set whiptail_menu_array = '('"Copy" "Copy Current address to Static"); sh-expr 'whip_options_total++' set whiptail_menu_array = '('"Static Ip" "$ETH_IP_STATIC"); sh-expr 'whip_options_total++' set whiptail_menu_array = '('"Static Mask" "$ETH_MASK_STATIC"); sh-expr 'whip_options_total++' set whiptail_menu_array = '('"Static Gateway" "$ETH_GATEWAY_STATIC"); sh-expr 'whip_options_total++' set whiptail_menu_array = '('"Static DNS" "$ETH_DNS_STATIC"); sh-expr 'whip_options_total++' } set whiptail_menu_array = '('"Disable" "Disable Ethernet adapter"); sh-expr 'whip_options_total++' set whiptail_menu_array = '('"Apply" "Save Changes (Restart Networking)"); sh-expr 'whip_options_total++' set 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 sh-expr ' $whip_options_total > $WHIP_OPTIONS_MAX_DISPLAY ' { set whip_options_total = $WHIP_OPTIONS_MAX_DISPLAY } var description_line_count = $shExpr(' 7 + $(echo -e "$description_text" | wc -l) ') # 7 is the minimal height of whiptail with no data/entries setglobal OPTION = $[whiptail --title $WHIP_TITLE --menu $description_text --cancel-button $TEXT_MENU_BACK --backtitle $WHIP_BACKTITLE --default-item $WHIP_SELECTION_PREVIOUS $shExpr(' $description_line_count + $whip_options_total ') 65 $whip_options_total $(whiptail_menu_array[@]) !3 > !1 !1 > !2 !2 > !3] #delete [] unset whiptail_menu_array setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal WHIP_SELECTION_PREVIOUS = $OPTION match $OPTION { with "Change Mode" sh-expr 'ETH_MODE_TARGET++' if sh-expr ' $ETH_MODE_TARGET >= 2 ' { setglobal ETH_MODE_TARGET = '0' } #Return to this menu setglobal TARGETMENUID = '9' with 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 setglobal CHOICE = $Status #Confirm action if sh-expr ' $CHOICE == 0 ' { setglobal ETH_DISABLED = '1' Network_ApplyChanges setglobal TARGETMENUID = '8' } else { #Return to this Menu setglobal TARGETMENUID = '9' } with Apply Ethernet_Reconnect #Return to this menu setglobal TARGETMENUID = '9' with Copy Network_ETH_CopyCurrentToStatic #Return to this menu setglobal TARGETMENUID = '9' with "Static Ip" Change_StaticIp 0 #Return to this menu setglobal TARGETMENUID = '9' with "Static Gateway" Change_StaticGateway 0 #Return to this menu setglobal TARGETMENUID = '9' with "Static Mask" Change_StaticMask 0 #Return to this menu setglobal TARGETMENUID = '9' with "Static DNS" Change_StaticDns 0 #Return to this menu setglobal TARGETMENUID = '9' } } } setglobal HOTSPOT_SSID = ''"" setglobal HOTSPOT_CHANNEL = ''"" setglobal 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{ setglobal TARGETMENUID = '8' var whip_options_total = '0' var description_text = '''' var whiptail_menu_array = ''() #WiFi Hotspot Menu if sh-expr ' $WIFI_HOTSPOT == 1 ' { setglobal WHIP_TITLE = ''DietPi - WiFi Hotspot'' # - Load current details into global vars, once. if test $HOTSPOT_SSID = "" { setglobal HOTSPOT_SSID = $[cat /etc/hostapd/hostapd.conf | grep -m1 '^ssid=' | sed 's/.*=//] setglobal HOTSPOT_CHANNEL = $[cat /etc/hostapd/hostapd.conf | grep -m1 '^channel=' | sed 's/.*=//] setglobal HOTSPOT_KEY = $[cat /etc/hostapd/hostapd.conf | grep -m1 '^wpa_passphrase=' | sed 's/.*=//] } # toggle var hotspot_active_state = $[systemctl is-active hostapd | grep -ci -m1 'active] var hotspot_status_text = ''Online'' var hotspot_active_state_text = '': Enabled, select to turn off hotspot'' if sh-expr ' ! $hotspot_active_state ' { set hotspot_active_state_text = '': Disabled, select to turn on hotspot'' set hotspot_status_text = ''Offline'' } set whiptail_menu_array = '('"SSID" "Change the wireless hotspot name"); sh-expr 'whip_options_total++' set whiptail_menu_array = '('"Channel" "Change the wireless channel"); sh-expr 'whip_options_total++' set whiptail_menu_array = '('"Key" "Change the access key required to connect"); sh-expr 'whip_options_total++' set whiptail_menu_array = '('"State" ": $hotspot_active_state_text"); sh-expr 'whip_options_total++' set description_text = ""SSID : $HOTSPOT_SSID\nChannel : $HOTSPOT_CHANNEL\nKey : $HOTSPOT_KEY\nStatus : $hotspot_status_text"" #WiFi Menu } else { setglobal WHIP_TITLE = ''DietPi - Wireless Network Options'' # - Get current Mode details var mode_current = ''DHCP'' if sh-expr ' $WIFI_MODE == 0 ' { set mode_current = ''STATIC'' } # - Target Details var mode_target = ''DHCP'' if sh-expr ' $WIFI_MODE_TARGET == 0 ' { set mode_target = ''STATIC'' } set whiptail_menu_array = '('"Scan" "Scan and Connect"); sh-expr 'whip_options_total++' set whiptail_menu_array = '('"Manual" "Manually Set Wireless Details"); sh-expr 'whip_options_total++' if sh-expr ' $WIFI_CONNECTED || $(systemctl is-active dietpi-wifi-monitor.service | grep -ci -m1 '^active') ' { var wifi_auto_reconnect_text = ''Disabled'' setglobal WIFI_AUTO_RECONNECT_ACTIVE = '0' if sh-expr ' $(systemctl is-active dietpi-wifi-monitor.service | grep -ci -m1 '^active') ' { setglobal WIFI_AUTO_RECONNECT_ACTIVE = '1' set wifi_auto_reconnect_text = ''Enabled'' } set whiptail_menu_array = '('"Auto Reconnect" ": $wifi_auto_reconnect_text"); sh-expr 'whip_options_total++' } set whiptail_menu_array = '('"Change Mode" ": $mode_target"); sh-expr 'whip_options_total++' # - show static options if sh-expr ' $WIFI_MODE_TARGET == 0 ' { set whiptail_menu_array = '('"Copy" "Copy Current address to Static"); sh-expr 'whip_options_total++' set whiptail_menu_array = '('"Static Ip" ": $WIFI_IP_STATIC"); sh-expr 'whip_options_total++' set whiptail_menu_array = '('"Static Mask" ": $WIFI_MASK_STATIC"); sh-expr 'whip_options_total++' set whiptail_menu_array = '('"Static Gateway" ": $WIFI_GATEWAY_STATIC"); sh-expr 'whip_options_total++' set whiptail_menu_array = '('"Static DNS" ": $WIFI_DNS_STATIC"); sh-expr 'whip_options_total++' } set whiptail_menu_array = '('"Disable" "Disable WiFi adapter"); sh-expr 'whip_options_total++' set 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" { set whiptail_menu_array = '('"Country" "Not set, please configure ($WIFI_COUNTRYCODE)"); sh-expr 'whip_options_total++' } else { set whiptail_menu_array = '('"Country" ": $WIFI_COUNTRYCODE"); sh-expr 'whip_options_total++' } set whiptail_menu_array = '('"Apply" "Save Changes (Restart Networking)"); sh-expr 'whip_options_total++' if sh-expr ' $whip_options_total > $WHIP_OPTIONS_MAX_DISPLAY ' { set whip_options_total = $WHIP_OPTIONS_MAX_DISPLAY } var description_line_count = $shExpr(' 7 + $(echo -e "$description_text" | wc -l) ') # 7 is the minimal height of whiptail with no data/entries setglobal OPTION = $[whiptail --title $WHIP_TITLE --menu $description_text --cancel-button $TEXT_MENU_BACK --backtitle $WHIP_BACKTITLE --default-item $WHIP_SELECTION_PREVIOUS $shExpr(' $description_line_count + $whip_options_total ') 65 $whip_options_total $(whiptail_menu_array[@]) !3 > !1 !1 > !2 !2 > !3] #delete [] unset whiptail_menu_array setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal WHIP_SELECTION_PREVIOUS = $OPTION match $OPTION { with 'Auto Reconnect' if sh-expr ' ! $WIFI_AUTO_RECONNECT_ACTIVE ' { WiFi_Monitor_Enable } else { WiFi_Monitor_Disable } #Return to this menu setglobal TARGETMENUID = '10' with Key setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal HOTSPOT_KEY = $OPTION } #Return to this menu setglobal TARGETMENUID = '10' with SSID setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal HOTSPOT_SSID = $OPTION } #Return to this menu setglobal TARGETMENUID = '10' with Channel #2.4ghz only atm var whiptail_menu_array = ''() var channel_mhz = '2412' var channel_min = '1' var channel_max = '13' for ((i=$channel_min; i<=$channel_max; i++)) do whiptail_menu_array+=("$i " "$channel_mhz MHz") ((channel_mhz += 5 )) done setglobal 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] setglobal CHOICE = $Status unset whiptail_menu_array if sh-expr ' $CHOICE == 0 ' { setglobal HOTSPOT_CHANNEL = $OPTION } #Return to this menu setglobal TARGETMENUID = '10' with Country Change_WifiCountryCode #Return to this Menu setglobal TARGETMENUID = '10' with 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 setglobal CHOICE = $Status #Confirm action if sh-expr ' $CHOICE == 0 ' { setglobal WIFI_DISABLED = '1' WiFi_Monitor_Disable Network_ApplyChanges setglobal TARGETMENUID = '8' } else { #Return to this Menu setglobal TARGETMENUID = '10' } with Scan Scan_Wifi #Return to this menu setglobal TARGETMENUID = '10' with Manual Change_WifiSsid Change_WifiKey Wifi_Reconnect #Return to this menu setglobal TARGETMENUID = '10' with "Change Mode" sh-expr 'WIFI_MODE_TARGET++' if sh-expr ' $WIFI_MODE_TARGET >= 2 ' { setglobal WIFI_MODE_TARGET = '0' } #Return to this menu setglobal TARGETMENUID = '10' with Apply if sh-expr ' $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 setglobal TARGETMENUID = '10' with Copy Network_WIFI_CopyCurrentToStatic #Return to this menu setglobal TARGETMENUID = '10' with "Static Ip" Change_StaticIp 1 #Return to this menu setglobal TARGETMENUID = '10' with "Static Gateway" Change_StaticGateway 1 #Return to this menu setglobal TARGETMENUID = '10' with "Static Mask" Change_StaticMask 1 #Return to this menu setglobal TARGETMENUID = '10' with "Static DNS" Change_StaticDns 1 #Return to this menu setglobal TARGETMENUID = '10' with State if sh-expr ' $hotspot_active_state ' { systemctl stop hostapd } else { systemctl start hostapd } #Return to this menu setglobal TARGETMENUID = '10' } } } #TARGETMENUID=11 proc Menu_Tools{ setglobal TARGETMENUID = '0' setglobal WHIP_TITLE = ''DietPi - Tools'' setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { match $OPTION { with Benchmarks setglobal TARGETMENUID = '12' with 'Stress Test' setglobal TARGETMENUID = '15' } } } #Benchmark Scores setglobal CPUBENCH_TIME = ''Not Tested'' setglobal CPUBENCH_INT_MAX = '1000000' setglobal SD_WRITE = ''Not Tested'' setglobal SD_READ = ''Not Tested'' setglobal USB_WRITE = ''Not Tested'' setglobal USB_READ = ''Not Tested'' setglobal RAM_WRITE = ''Not Tested'' setglobal RAM_READ = ''Not Tested'' setglobal CUSTOM_WRITE = ''Not Tested'' setglobal CUSTOM_READ = ''Not Tested'' setglobal FP_CUSTOM_MOUNT = '''' proc Run_FilesystemBenchmark{ var device_index = $1 var benchmark_temp_file = ''"" var read_speed = '0' var write_speed = '0' var run_benchmark = '1' var benchmark_filesize = '0' var benchmark_filesystem_freespace = '0' var benchmark_filesystem_offset = '10' var text_info_test_name = ''"" var min_benchmark_size = '10' clear #Define test locations / info and extras. if sh-expr ' $device_index == 0 ' { set text_info_test_name = ''RootFS'' set benchmark_temp_file = ""$HOME/benchmark.file"" set benchmark_filesystem_freespace = $shExpr(' $(df -m | grep -m1 "$(sed -n 4p /DietPi/dietpi/.hw_model)" | awk '{print $4}') - $benchmark_filesystem_offset ') } elif sh-expr ' $device_index == 1 ' { set text_info_test_name = ''USB harddrive'' set benchmark_temp_file = ""$[df -P | grep -m1 '^/dev/sda1' | awk '{print $6}]/benchmark.file"" set benchmark_filesystem_freespace = $shExpr(' $(df -m | grep -m1 '^/dev/sda1' | awk '{print $4}') - $benchmark_filesystem_offset ') } elif sh-expr ' $device_index == 2 ' { set text_info_test_name = ''RAM'' set benchmark_temp_file = ''/tmp/benchmark.file'' set benchmark_filesystem_freespace = $shExpr(' $(df -m | grep -m1 '/tmp' | awk '{print $4}') - $benchmark_filesystem_offset ') } elif sh-expr ' $device_index == 3 ' { set text_info_test_name = ''Custom'' set benchmark_temp_file = ""$FP_CUSTOM_MOUNT/benchmark.file"" set benchmark_filesystem_freespace = $shExpr(' $(df -m | grep -m1 "$FP_CUSTOM_MOUNT$" | awk '{print $4}') - $benchmark_filesystem_offset ') } #Not enough free space if sh-expr ' $benchmark_filesystem_freespace < $min_benchmark_size ' { set 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 { set 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { #Check for valid interger/entry if [[ $benchmark_filesize =~ ^-?[0-9]+$ ]] && sh-expr ' $benchmark_filesize > 0 ' { #Disable test if not enough free space. if sh-expr ' $benchmark_filesystem_freespace < $benchmark_filesize ' { set 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 sh-expr ' $benchmark_filesize < $min_benchmark_size ' { set 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 set run_benchmark = '0' } #User aborted. } else { set run_benchmark = '0' } } #Run benchmark if sh-expr ' $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 sh-expr ' $G_DISTRO == 3 ' { set write_speed = $[dd bs=4K count=$shExpr(' $benchmark_filesize * 1024 / 4 ') if=/dev/zero of=$benchmark_temp_file conv=fdatasync !2 > !1 | grep 'MB' | awk '{print $8, $9}] } elif sh-expr ' $G_DISTRO == 4 ' { set write_speed = $[dd bs=4K count=$shExpr(' $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 sh-expr ' $G_DISTRO == 3 ' { set read_speed = $[dd bs=4K count=$shExpr(' $benchmark_filesize * 1024 / 4 ') if=$benchmark_temp_file of=/dev/zero conv=fdatasync !2 > !1 | grep 'MB' | awk '{print $8, $9}] } elif sh-expr ' $G_DISTRO == 4 ' { set read_speed = $[dd bs=4K count=$shExpr(' $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 sh-expr ' $device_index == 0 ' { setglobal SD_WRITE = $write_speed setglobal SD_READ = $read_speed } elif sh-expr ' $device_index == 1 ' { setglobal USB_WRITE = $write_speed setglobal USB_READ = $read_speed } elif sh-expr ' $device_index == 2 ' { setglobal RAM_WRITE = $write_speed setglobal RAM_READ = $read_speed } elif sh-expr ' $device_index == 3 ' { setglobal CUSTOM_WRITE = $write_speed setglobal 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 setglobal CPUBENCH_TIME = $[ grep -m1 'real' /tmp/dietpi-bench_result | awk '{print $2}] /DietPi/dietpi/dietpi-services start } #TARGETMENUID=12 proc Menu_FilesystemBenchmark{ setglobal TARGETMENUID = '11' setglobal WHIP_TITLE = ''DietPi - Benchmarks'' setglobal 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] match $OPTION { with "CPU" Run_CPUBenchmark #Return to this menu setglobal TARGETMENUID = '12' with "RootFS" Run_FilesystemBenchmark 0 #Return to this menu setglobal TARGETMENUID = '12' with "USB Drive" #Check USB is connected and mounted if sh-expr ' $(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 setglobal TARGETMENUID = '12' with "Custom" /DietPi/dietpi/dietpi-drive_manager 1 setglobal FP_CUSTOM_MOUNT = $[cat /tmp/dietpi-drive_manager_selmnt] if test -n $FP_CUSTOM_MOUNT { Run_FilesystemBenchmark 3 } #Return to this menu setglobal TARGETMENUID = '12' with "RAM" #Check for /tmp as tmpfs, before running: https://github.com/Fourdee/DietPi/issues/1130#issuecomment-350348081 if sh-expr ' $(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 setglobal TARGETMENUID = '12' } } proc Reset_Overclocking{ sed -i '/over_voltage=/c\#over_voltage=0' /DietPi/config.txt if sh-expr ' $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 sh-expr ' $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 sh-expr ' $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 sh-expr ' $(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 } } setglobal REBOOT_REQUIRED = '1' } proc Warning_Overclocking{ setglobal WHIP_TITLE = ''Warning! Continue with overclocking?'' setglobal 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{ setglobal TARGETMENUID = '4' #Get Current Overclocking Settings var over_voltage_value = $[grep -m1 'over_voltage=' /DietPi/config.txt | tr -d '#over_voltage=] var arm_freq_value = $[grep -m1 'arm_freq=' /DietPi/config.txt | tr -d '#arm_freq=] var core_freq_value = $[grep -m1 'core_freq=' /DietPi/config.txt | tr -d '#core_freq=] var sdram_freq_value = $[grep -m1 'sdram_freq=' /DietPi/config.txt | tr -d '#sdram_freq=] setglobal WHIP_TITLE = ''DietPi - Overclocking'' #Overclocking Pi1 # - Zero echo -e $G_HW_MODEL if sh-expr ' $(cat /DietPi/dietpi/.hw_model | tr '[:upper:]' '[:lower:]' | grep -ci -m1 'rpi zero') ' { setglobal 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] match $OPTION { with none Reset_Overclocking #Return to this menu setglobal TARGETMENUID = '13' } } elif sh-expr ' $G_HW_MODEL <= 1 ' { setglobal 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] match $OPTION { with none Reset_Overclocking #Return to this menu setglobal TARGETMENUID = '13' with 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 setglobal TARGETMENUID = '13' with high Warning_Overclocking setglobal CHOICE = $Status if sh-expr ' $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 setglobal TARGETMENUID = '13' with extreme Warning_Overclocking setglobal CHOICE = $Status if sh-expr ' $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 setglobal TARGETMENUID = '13' } #Overclocking Pi2 } elif sh-expr ' $G_HW_MODEL == 2 ' { setglobal 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] match $OPTION { with none Reset_Overclocking #Return to this menu setglobal TARGETMENUID = '13' with low Warning_Overclocking setglobal CHOICE = $Status if sh-expr ' $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 setglobal TARGETMENUID = '13' with med Warning_Overclocking setglobal CHOICE = $Status if sh-expr ' $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 setglobal TARGETMENUID = '13' with extreme Warning_Overclocking setglobal CHOICE = $Status if sh-expr ' $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 setglobal TARGETMENUID = '13' } #Overclocking Pi3 } elif sh-expr ' $G_HW_MODEL == 3 ' { setglobal 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] match $OPTION { with none Reset_Overclocking #Return to this menu setglobal TARGETMENUID = '13' with low Warning_Overclocking setglobal CHOICE = $Status if sh-expr ' $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 setglobal TARGETMENUID = '13' with med Warning_Overclocking setglobal CHOICE = $Status if sh-expr ' $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 setglobal TARGETMENUID = '13' with high Warning_Overclocking setglobal CHOICE = $Status if sh-expr ' $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 setglobal TARGETMENUID = '13' } } } #TARGETMENUID=14 proc Menu_AudioOptions{ setglobal TARGETMENUID = '0' var soundcard_current = $[grep -m1 '^CONFIG_SOUNDCARD=' /DietPi/dietpi.txt | sed 's/.*=//] var whiptail_menu_array = ''() set whiptail_menu_array = '('"Soundcard" ": $soundcard_current") if sh-expr ' $(dpkg --get-selections | grep -ci -m1 '^alsa-utils') ' { set 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 sh-expr ' $G_HW_MODEL < 10 ' { var current_cpu_governor = $[cat /DietPi/dietpi.txt | grep -m1 '^CONFIG_CPU_GOVERNOR=' | sed 's/.*=//] var hdmi_output = $[cat /DietPi/dietpi.txt | grep -m1 'CONFIG_HDMI_OUTPUT=' | sed 's/.*=//] var psu_noise_reduction_enabled = '0' if test $current_cpu_governor = "powersave" && sh-expr ' ! $hdmi_output ' { set whiptail_menu_array = '('"PSU noise reduction" ": Enabled | Select now to disable") set psu_noise_reduction_enabled = '1' } else { set whiptail_menu_array = '('"PSU noise reduction" ": Disabled | Select now to enable") } } setglobal WHIP_TITLE = ''DietPi - Audio Options'' setglobal 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] setglobal CHOICE = $Status unset whiptail_menu_array if sh-expr ' $CHOICE == 0 ' { if test $OPTION = "PSU noise reduction" { if sh-expr ' ! $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 setglobal TARGETMENUID = '14' } elif test $OPTION = "Soundcard" { setglobal WHIP_TITLE = ''DietPi - Soundcards'' var whiptail_menu_array = ''() # - Global: # RPI, none disables HDMI aswell. if sh-expr ' $G_HW_MODEL < 10 ' { set whiptail_menu_array = '('"none" "Disables HDMI + 3.5mm Analogue") # NanoPi M2/M3, BPi Pro, OPi Zero } elif sh-expr ' $G_HW_MODEL == 32 || $G_HW_MODEL == 51 || $G_HW_MODEL == 61 || $G_HW_MODEL == 62 ' { set whiptail_menu_array = '('"default" "3.5mm Analogue") # Native PC | List available } elif sh-expr ' $G_HW_MODEL == 21 ' { set whiptail_menu_array = '('"default" "HW:0,0") # Install prereqs to allow for detection if sh-expr ' ! $(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 { set whiptail_menu_array = '('"default" "HDMI") } # - RPI if sh-expr ' $G_HW_MODEL < 10 ' { set whiptail_menu_array = '('"rpi-bcm2835" "Onboard: HDMI (if plugged in, else 3.5mm)") set whiptail_menu_array = '('"rpi-bcm2835-3.5mm" "Onboard: 3.5mm forced output") set whiptail_menu_array = '('"rpi-bcm2835-ultrahq" "Onboard HQ: HDMI (if plugged in, else 3.5mm)") set whiptail_menu_array = '('"rpi-bcm2835-ultrahq-3.5mm" "Onboard HQ: 3.5mm forced output") set whiptail_menu_array = '('"allo-boss-dac-pcm512x-audio" "Allo Boss DAC") set whiptail_menu_array = '('"allo-boss-dac-pcm512x-audio" "Allo Mini Boss DAC") set whiptail_menu_array = '('"allo-digione" "Allo DigiOne") set whiptail_menu_array = '('"allo-piano-dac-pcm512x-audio" "Allo Piano DAC") set whiptail_menu_array = '('"allo-piano-dac-pcm512x-audio" "Allo Piano DAC") set whiptail_menu_array = '('"dionaudio-loco" "Dion Audio LOCO") set whiptail_menu_array = '('"dionaudio-loco-v2" "Dion Audio LOCO V2") set whiptail_menu_array = '('"googlevoicehat-soundcard" "Google AIY voice kit") set whiptail_menu_array = '('"hifiberry-amp" "HifiBerry AMP / AMP+") set whiptail_menu_array = '('"hifiberry-dac" "HifiBerry DAC / MiniAMP") set whiptail_menu_array = '('"hifiberry-dacplus" "HifiBerry DAC+ / DAC+ Pro") set whiptail_menu_array = '('"hifiberry-digi" "HifiBerry DIGI / DIGI+") set whiptail_menu_array = '('"hifiberry-digi-pro" "HifiBerry DIGI Pro") set whiptail_menu_array = '('"i-sabre-k2m" "AudioPhonics I-Sabre ES9028 Q2M") set whiptail_menu_array = '('"iqaudio-dacplus" "Pi-DAC+, Pi-DACZero, Pi-DAC Pro, Pi-DigiAMP+") set whiptail_menu_array = '('"iqaudio-digi-wm8804-audio" "Pi-DIGI+") set whiptail_menu_array = '('"iqaudio-dacplus,auto_mute_amp" "Pi-DigiAMP+") set whiptail_menu_array = '('"iqaudio-dacplus,unmute_amp" "Pi-DigiAMP+") set whiptail_menu_array = '('"justboom-dac" "JustBoom: DAC HAT, Amp HAT, DAC Zero and Amp Zero") set whiptail_menu_array = '('"justboom-digi" "JustBoom: Digi HAT and Digi Zero") set whiptail_menu_array = '('"rpi-dac" "Soekris DAM1021 (pcm1794a)") # - C1/C2 } elif sh-expr ' $G_HW_MODEL == 10 || $G_HW_MODEL == 12 ' { set whiptail_menu_array = '('"odroid-hifishield-plus" "Odroid HiFi Shield 1/Plus") set whiptail_menu_array = '('"odroid-hifishield-2" "Odroid HiFi Shield 2") # - h2+ | OPi Zero } elif sh-expr ' $G_HW_MODEL == 32 ' { set whiptail_menu_array = '('"h2-hdmi" "HDMI") # - Rock64 } elif sh-expr ' $G_HW_MODEL == 43 ' { set whiptail_menu_array = '('"rock64-analogue" "3.5MM") # NanoPi M2/M3 } elif sh-expr ' $G_HW_MODEL == 61 || $G_HW_MODEL == 62 ' { set whiptail_menu_array = '('"s5pxx18-hdmi" "HDMI") # - H3 } elif sh-expr ' $G_HW_CPUID == 1 ' { set 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 sh-expr ' $G_HW_MODEL == 70 ' { set whiptail_menu_array = '('"snd-soc-allo-piano-dac" "Allo Piano DAC") set whiptail_menu_array = '('"snd-soc-allo-piano-dac-plus" "Allo Piano DAC 2.1") set whiptail_menu_array = '('"allo-cheapo-analogue" "Allo Cheapo (3.5mm / RCA output)") set whiptail_menu_array = '('"allo-cheapo-optical" "Allo Cheapo (Optical output)") # - Asus tb } elif sh-expr ' $G_HW_MODEL == 52 ' { set whiptail_menu_array = '('"asus-tb-analogue" "3.5mm analogue") } # - Global usb-dac, prefer at bottom of list set whiptail_menu_array = '('"usb-dac" "USB Audio DAC (any)") setglobal 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] setglobal CHOICE = $Status unset whiptail_menu_array if sh-expr ' $CHOICE == 0 ' { /DietPi/dietpi/func/dietpi-set_hardware soundcard $OPTION setglobal REBOOT_REQUIRED = '1' } #Return to This Menu setglobal TARGETMENUID = '14' } elif test $OPTION = "DietPi-JustBoom" { /DietPi/dietpi/misc/dietpi-justboom #Return to This Menu setglobal TARGETMENUID = '14' } } } #TARGETMENUID=15 setglobal STRESS_TEST_MODE = '0' #0=CPU only | 1=CPU/RAM 2=CPU/RAM/IO setglobal STRESS_TEST_DURATION = '60' setglobal STRESS_TEST_RESULTS_TEMP_MIN = '0' setglobal STRESS_TEST_RESULTS_TEMP_MAX = '0' proc Menu_StressTest{ setglobal TARGETMENUID = '11' var stress_test_mode_text = ''CPU Burn: (CPU only)'' if sh-expr ' $STRESS_TEST_MODE == 1 ' { set stress_test_mode_text = ''CPU & RAM: (CPU, RAM)'' } elif sh-expr ' $STRESS_TEST_MODE == 2 ' { set stress_test_mode_text = ''Full: (CPU, DISK, RAM)'' } setglobal WHIP_TITLE = ''DietPi - Stress Test'' setglobal 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" "$shExpr(' $STRESS_TEST_DURATION / 60 ') Minutes" \ "Start" "Launch the stress test" !3 > !1 !1 > !2 !2 > !3] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { if test $OPTION = "Duration" { setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal STRESS_TEST_DURATION = $OPTION setglobal TARGETMENUID = '15' } } elif test $OPTION = "Mode" { setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal STRESS_TEST_MODE = $OPTION setglobal TARGETMENUID = '15' } } elif test $OPTION = "Start" { G_AG_CHECK_INSTALL_PREREQ stress if sh-expr ' $? != 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' var start_time = $[date] var start_time_epoch = $[date +%s] var cores = $[nproc --all] # double up cpu threads, maximize overheads. var memory_per_thread = $shExpr(' $(free -m | awk '/^Mem:/{print $2}') / ( $cores * 2 ) ') var fp_log = ""$HOME/dietpi-config_stress.log"" rm $fp_log &> /dev/null if sh-expr ' $STRESS_TEST_MODE == 0 ' { stress -c $shExpr(' $cores * 2 ') -t "$STRESS_TEST_DURATION"s & } elif sh-expr ' $STRESS_TEST_MODE == 1 ' { stress -c $shExpr(' $cores * 2 ') -i $cores -m $cores --vm-bytes "$memory_per_thread"M -t "$STRESS_TEST_DURATION"s & } elif sh-expr ' $STRESS_TEST_MODE == 2 ' { stress -c $shExpr(' $cores * 2 ') -i $cores -m $cores --vm-bytes "$memory_per_thread"M -d 2 -t "$STRESS_TEST_DURATION"s & } # - Reset setglobal STRESS_TEST_RESULTS_TEMP_MIN = '1000' setglobal STRESS_TEST_RESULTS_TEMP_MAX = '0' # - Check if system supports temp readouts var cpu_supports_temp = '0' var cpu_temp = $[G_OBTAIN_CPU_TEMP] if [[ $cpu_temp =~ ^-?[0-9]+$ ]] { set cpu_supports_temp = '1' } # - Loop until stress completed var remaning_time = '0' while (( $(ps aux | grep -ci -m1 '[s]tress') == 1 )) { set cpu_temp = $[G_OBTAIN_CPU_TEMP] set remaning_time = $shExpr(' $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 sh-expr ' $cpu_supports_temp ' { if sh-expr ' $cpu_temp > $STRESS_TEST_RESULTS_TEMP_MAX ' { setglobal STRESS_TEST_RESULTS_TEMP_MAX = $cpu_temp } if sh-expr ' $cpu_temp < $STRESS_TEST_RESULTS_TEMP_MIN ' { setglobal STRESS_TEST_RESULTS_TEMP_MIN = $cpu_temp } } sleep 1 sh-expr 'time_since_start++' } var end_time = $[date] var end_time_epoch = $[date +%s] var duration_seconds = $shExpr(' $end_time_epoch - $start_time_epoch ') var 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 setglobal TARGETMENUID = '15' } } } #TARGETMENUID=16 proc Menu_Network_Nas_Misc{ setglobal TARGETMENUID = '0' #Update installed software Load_Installed_Software #Samba Client var sambaclient_installed = '0' var sambaclient_status = '"Not Installed'" var sambaclient_menutext = '"Install now to access Windows shares and NAS devices'" var sambaclient_mounted_size = '"unknown'" var sambaclient_mounted_used = '"unknown'" var sambaclient_mounted_free = '"unknown'" if sh-expr ' ${aSOFTWARE_INSTALL_STATE[1]:=0} == 2 ' { set sambaclient_installed = '1' set sambaclient_status = '"Unable to connect and/or incorrect details'" set sambaclient_menutext = '"Input/Modify Details'" #Check if mount exists and is valid if sh-expr ' $(df -h | grep -ci -m1 '/mnt/samba') == 1 ' { #Get stats set sambaclient_mounted_size = $[df -h | grep -m1 '/mnt/samba' | awk '{print $(NF-4)}] set sambaclient_mounted_used = $[df -h | grep -m1 '/mnt/samba' | awk '{print $(NF-3)}] set sambaclient_mounted_free = $[df -h | grep -m1 '/mnt/samba' | awk '{print $(NF-2)}] set sambaclient_status = ""/mnt/samba | Size $sambaclient_mounted_size | Used $sambaclient_mounted_used | Free $sambaclient_mounted_free"" } } #ftp Client mount, curlftpfs var curlftpfs_installed = '0' var curlftpfs_status = '"Not Installed'" var curlftpfs_menutext = '"Install now to access FTP as filesystem mount'" if sh-expr ' ${aSOFTWARE_INSTALL_STATE[2]:=0} == 2 ' { set curlftpfs_installed = '1' set curlftpfs_status = '"Unable to connect and/or incorrect details'" set curlftpfs_menutext = '"Input/Modify Details'" #Check if mount exists and is valid if sh-expr ' $(df -h | grep -ci -m1 '/mnt/ftp_client') == 1 ' { #Get stats set curlftpfs_status = '"/mnt/ftp_client | Connected'" } } #NoIp Client var noip_installed = '0' var noip_status = '"Not Installed'" var noip_menutext = '"Install No-Ip now'" if sh-expr ' ${aSOFTWARE_INSTALL_STATE[67]:=0} == 2 ' { set noip_installed = '1' set noip_status = '"Offline - Please Enter No-Ip Details'" set noip_menutext = '"Enter/Setup NoIp Details'" #Check if noip is running (indicates login details are valid) if sh-expr ' $(ps aux | grep -ci -m1 '/usr/local/bin/[n]oip2') == 1 ' { set noip_status = '"Online / Active'" set noip_menutext = '"Change NoIp Details'" } } #NFS Client var nfsclient_installed = '0' var nfsclient_status = '"Not Installed'" var nfsclient_menutext = '"Install now to access NFS shares'" var nfsclient_mounted_size = '"unknown'" var nfsclient_mounted_used = '"unknown'" var nfsclient_mounted_free = '"unknown'" if sh-expr ' ${aSOFTWARE_INSTALL_STATE[110]:=0} == 2 ' { set nfsclient_installed = '1' set nfsclient_status = '"Unable to connect and/or incorrect details'" set nfsclient_menutext = '"Input/Modify Details'" #Check if mount exists and is valid if sh-expr ' $(df -h | grep -ci -m1 '/mnt/nfs_client') == 1 ' { #Get stats set nfsclient_mounted_size = $[df -h | grep -m1 '/mnt/nfs_client' | awk '{ print $2 }] set nfsclient_mounted_used = $[df -h | grep -m1 '/mnt/nfs_client' | awk '{ print $3 }] set nfsclient_mounted_free = $[df -h | grep -m1 '/mnt/nfs_client' | awk '{ print $4 }] set nfsclient_status = ""/mnt/nfs_client | Size $nfsclient_mounted_size | Used $nfsclient_mounted_used | Free $nfsclient_mounted_free"" } } #Apt mirror var apt_mirror_current = $[sed -n 1p /etc/apt/sources.list | awk '{print $2}] if test ! -n $apt_mirror_current { set apt_mirror_current = ''Unknown, no string from scrape'' } #NTPD mirror var ntpd_mirror_current = $[grep -m1 '^CONFIG_NTP_MIRROR=' /DietPi/dietpi.txt | sed 's/.*=//] if test ! -n $ntpd_mirror_current { set ntpd_mirror_current = ''Unknown, no string from scrape'' } #Network boot wait var boot_wait_for_network = $[cat /DietPi/dietpi.txt | grep -m1 '^CONFIG_BOOT_WAIT_FOR_NETWORK=' | sed 's/.*=//] var boot_wait_for_network_text = '': '' if sh-expr ' $boot_wait_for_network == 0 ' { set boot_wait_for_network_text = ''Disabled'' } elif sh-expr ' $boot_wait_for_network == 1 ' { set boot_wait_for_network_text = ''10 Seconds MAX (default)'' } elif sh-expr ' $boot_wait_for_network == 2 ' { set boot_wait_for_network_text = ''Infinite wait'' } setglobal WHIP_TITLE = ''DietPi - Network Options: NAS/Misc'' setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { match $OPTION { with "Boot Net Wait" #Create Menu List for Whiptail var whiptail_menu_array = ''() set whiptail_menu_array = '(''0' ': Disabled') set whiptail_menu_array = '(''1' ': Wait 10 Seconds MAX for network, before continuing boot (default)') set whiptail_menu_array = '(''2' ': Infinite wait for network, before continuing boot') setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { sed -i "/^CONFIG_BOOT_WAIT_FOR_NETWORK=/c CONFIG_BOOT_WAIT_FOR_NETWORK=$OPTION" /DietPi/dietpi.txt #Return to this Menu setglobal TARGETMENUID = '16' } #delete [] unset whiptail_menu_array with "Apt Mirror" #Create Menu List for Whiptail var whiptail_menu_array = '( '"Custom" "Manually enter Apt mirror" ) # - Raspbian if sh-expr ' $G_HW_MODEL < 10 ' { set whiptail_menu_array = '('"http://mirrordirector.raspbian.org/raspbian" "Global") set whiptail_menu_array = '('"https://www.mirrorservice.org/sites/archive.raspbian.org/raspbian" "Global (https)") set whiptail_menu_array = '('"http://mirror.ox.ac.uk/sites/archive.raspbian.org/archive/raspbian" "UK") set whiptail_menu_array = '('"ftp://ftp.fu-berlin.de/linux/raspbian/raspbian" "Germany") set whiptail_menu_array = '('"http://mirror.umd.edu/raspbian/raspbian" "US") set whiptail_menu_array = '('"http://mirrors.ustc.edu.cn/raspbian/raspbian" "China") set whiptail_menu_array = '('"http://raspbian.mirror.digitalpacific.com.au/raspbian" "Australia") # - Debian } else { set whiptail_menu_array = '('"http://ftp.debian.org/debian/" "Global") set whiptail_menu_array = '('"http://ftp.uk.debian.org/debian/" "UK") set whiptail_menu_array = '('"http://ftp.us.debian.org/debian/" "US") set whiptail_menu_array = '('"http://ftp.cn.debian.org/debian/" "China") set whiptail_menu_array = '('"http://ftp.au.debian.org/debian/" "Australia") } setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { match $OPTION { with Custom setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal return_value = $OPTION } with * setglobal return_value = $OPTION } /DietPi/dietpi/func/dietpi-set_software apt-mirror $OPTION # - test it G_DIETPI-NOTIFY 2 "Updating Apt, please wait..." G_AGUP var exit_code = $Status if sh-expr ' $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 setglobal TARGETMENUID = '16' #delete [] unset whiptail_menu_array with "NTPD Mirror" #Create Menu List for Whiptail var whiptail_menu_array = '( '"Custom" "Manually enter NTPD mirror" ) set whiptail_menu_array = '(''debian.pool.ntp.org' 'Debian Global') set whiptail_menu_array = '(''pool.ntp.org' 'Global') set whiptail_menu_array = '(''europe.pool.ntp.org' 'Europe') set whiptail_menu_array = '(''north-america.pool.ntp.org' 'North America') set whiptail_menu_array = '(''south-america.pool.ntp.org' 'South America') set whiptail_menu_array = '(''africa.pool.ntp.org' 'Africa') set whiptail_menu_array = '(''asia.pool.ntp.org' 'Asia') set whiptail_menu_array = '(''oceania.pool.ntp.org' 'Oceania') setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal return_value = $OPTION match $OPTION { with Custom setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal 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 setglobal TARGETMENUID = '16' } #delete [] unset whiptail_menu_array with "NFS Client" #Installed? if sh-expr ' ! $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 setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { #install nfsclient /DietPi/dietpi/dietpi-software install 110 } } else { /DietPi/dietpi/func/dietpi-set_nfsclient } #Return to this Menu setglobal TARGETMENUID = '16' with Samba* #Installed? if sh-expr ' ! $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 setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { #install smbclient /DietPi/dietpi/dietpi-software install 1 } } else { /DietPi/dietpi/func/dietpi-set_smbclient } #Return to this Menu setglobal TARGETMENUID = '16' with FTP* #Installed? if sh-expr ' ! $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 setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { #install curlftpfs /DietPi/dietpi/dietpi-software install 2 } } else { /DietPi/dietpi/func/dietpi-set_curlftpfs } #Return to this Menu setglobal TARGETMENUID = '16' with NoIp #Installed? if sh-expr ' ! $noip_installed ' { var 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 setglobal CHOICE = $Status if sh-expr ' $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 setglobal TARGETMENUID = '16' } #Cancel } else { #Exit DietPi-Config on back to previous menu? if sh-expr ' $EXITONBACK == 1 ' { #Return to this menu setglobal TARGETMENUID = '16' Menu_Exit } } } setglobal PROXY_ENABLED = '-1' setglobal PROXY_ADDRESS = '''' setglobal PROXY_PORT = '''' setglobal PROXY_USERNAME = '''' setglobal PROXY_PASSWORD = '''' #So we can call this in other menus (eg: submenu of this) proc Load_Proxy_Vars{ setglobal PROXY_ENABLED = $[cat /DietPi/dietpi.txt | grep -m1 '^CONFIG_PROXY_ENABLED=' | sed 's/.*=//] setglobal PROXY_ADDRESS = $[cat /DietPi/dietpi.txt | grep -m1 '^CONFIG_PROXY_ADDRESS=' | sed 's/.*=//] setglobal PROXY_PORT = $[cat /DietPi/dietpi.txt | grep -m1 '^CONFIG_PROXY_PORT=' | sed 's/.*=//] setglobal PROXY_USERNAME = $[cat /DietPi/dietpi.txt | grep -m1 '^CONFIG_PROXY_USERNAME=' | sed 's/.*=//] setglobal PROXY_PASSWORD = $[cat /DietPi/dietpi.txt | grep -m1 '^CONFIG_PROXY_PASSWORD=' | sed 's/.*=//] } #TARGETMENUID=17 proc Menu_NetworkAdapters_Proxy{ setglobal TARGETMENUID = '8' #Get current details on first menu init (PROXY_ENABLED=-1) if sh-expr ' $PROXY_ENABLED == -1 ' { Load_Proxy_Vars setglobal proxy_state_text = ''Disabled'' if sh-expr ' $PROXY_ENABLED == 1 ' { setglobal proxy_state_text = ''Enabled'' } } setglobal proxy_state_text_new = ''No'' if sh-expr ' $PROXY_ENABLED == 1 ' { setglobal proxy_state_text_new = ''Yes'' } setglobal WHIP_TITLE = ''DietPi - Proxy Network Options'' setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { match $OPTION { with Toggle sh-expr 'PROXY_ENABLED++' if sh-expr ' $PROXY_ENABLED >= 2 ' { setglobal PROXY_ENABLED = '0' } #Return to this menu setglobal TARGETMENUID = '17' with Address setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal PROXY_ADDRESS = $OPTION } #Return to this Menu setglobal TARGETMENUID = '17' with Port setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal PROXY_PORT = $OPTION } #Return to this Menu setglobal TARGETMENUID = '17' with Username setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal PROXY_USERNAME = $OPTION } #Return to this Menu setglobal TARGETMENUID = '17' with Password setglobal 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] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { setglobal PROXY_PASSWORD = $OPTION } #Return to this Menu setglobal TARGETMENUID = '17' with 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 sh-expr ' $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 setglobal REBOOT_REQUIRED = '1' setglobal WHIP_TITLE = ''Proxy: Reboot required'' setglobal 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 setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { reboot } # - Reset init flag to force a reload of setings next time this menu is run. setglobal PROXY_ENABLED = '-1' #Return to this menu setglobal TARGETMENUID = '17' } #Reset init flag to force a reload of setings next time this menu is run. } else { setglobal PROXY_ENABLED = '-1' } } #///////////////////////////////////////////////////////////////////////////////////// # Main Loop #///////////////////////////////////////////////////////////////////////////////////// if sh-expr ' $G_DIETPI_INSTALL_STAGE >= 0 ' { #Start DietPi-Config while sh-expr ' $TARGETMENUID > -1 ' { #Clear Screen buffer clear if sh-expr ' $TARGETMENUID == 0 ' { Menu_Main } elif sh-expr ' $TARGETMENUID == 1 ' { Menu_DisplayOptions } elif sh-expr ' $TARGETMENUID == 2 ' { Menu_DisplayOptions_Driver_Resolution } elif sh-expr ' $TARGETMENUID == 3 ' { Menu_AdvancedOptions } elif sh-expr ' $TARGETMENUID == 4 ' { Menu_PerformanceOptions } elif sh-expr ' $TARGETMENUID == 5 ' { Menu_SecurityOptions } elif sh-expr ' $TARGETMENUID == 6 ' { Menu_GpumemoryOptions } elif sh-expr ' $TARGETMENUID == 7 ' { Menu_LanguageOptions } elif sh-expr ' $TARGETMENUID == 8 ' { Menu_NetworkAdapters } elif sh-expr ' $TARGETMENUID == 9 ' { Menu_NetworkAdapters_Ethernet } elif sh-expr ' $TARGETMENUID == 10 ' { Menu_NetworkAdapters_Wifi } elif sh-expr ' $TARGETMENUID == 11 ' { Menu_Tools } elif sh-expr ' $TARGETMENUID == 12 ' { Menu_FilesystemBenchmark } elif sh-expr ' $TARGETMENUID == 13 ' { Menu_Overclock } elif sh-expr ' $TARGETMENUID == 14 ' { Menu_AudioOptions } elif sh-expr ' $TARGETMENUID == 15 ' { Menu_StressTest } elif sh-expr ' $TARGETMENUID == 16 ' { Menu_Network_Nas_Misc } elif sh-expr ' $TARGETMENUID == 17 ' { Menu_NetworkAdapters_Proxy } } } else { echo -e " >> Filesystem prep has not yet completed: \n Please wait for the system to reboot " } #----------------------------------------------------------------------------------- exit #----------------------------------------------------------------------------------- }