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