diff --git a/.meta/survey_report b/.meta/survey_report index d7da777841..d76fe6a737 100644 --- a/.meta/survey_report +++ b/.meta/survey_report @@ -126,13 +126,13 @@ aSOFTWARE_NAME=( [73]='Fail2Ban' [74]='InfluxDB' [75]='LASP' - [76]='LAAP' + [76]='LAMP' [77]='Grafana' [78]='LESP' - [79]='LEAP' + [79]='LEMP' [80]='NULL' [81]='LLSP' - [82]='LLAP' + [82]='LLMP' [83]='Apache2' [84]='Lighttpd' [85]='Nginx' @@ -256,13 +256,34 @@ done aSOFTWARE_NAME6_12[2]='NULL' # CurlTMPFS aSOFTWARE_NAME6_12[148]='NULL' # JRiver -# - v6.13 testing +# - v6.13 aSOFTWARE_NAME6_13=() for i in ${!aSOFTWARE_NAME6_12[@]} do aSOFTWARE_NAME6_13[$i]="${aSOFTWARE_NAME6_12[$i]}" +done +aSOFTWARE_NAME6_13[2]='Folding@Home' +aSOFTWARE_NAME6_13[106]='Lidarr' + +# - v6.14 +aSOFTWARE_NAME6_14=() +for i in ${!aSOFTWARE_NAME6_13[@]} +do + + aSOFTWARE_NAME6_14[$i]="${aSOFTWARE_NAME6_13[$i]}" + +done +aSOFTWARE_NAME6_14[38]='FreshRSS' + +# - v6.15 testing +aSOFTWARE_NAME6_15=() +for i in ${!aSOFTWARE_NAME6_14[@]} +do + + aSOFTWARE_NAME6_15[$i]="${aSOFTWARE_NAME6_14[$i]}" + done # Copy files to RAM to speed up grep diff --git a/CHANGELOG.txt b/CHANGELOG.txt index abf21895c0..efa2defb58 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,4 +1,43 @@ +v6.15 +(12/09/18) + +Many thanks to PINE64, for becoming our 1st Patreon Legend and supporting our project! As one of their rewards, you will see PINE64 displayed on login via the DietPi-Banner. + +Known issues / In progress: +DietPi-Software | Open Bazaar: Installation updated to server version 2, which now runs via go language. At the current state, client OB connections are failing, still under investigation: https://github.com/Fourdee/DietPi/issues/1090#issuecomment-419613346 + +Changes / Improvements / Optimizations: +General | Changed Survey and Bugreport uploads to use ssh.dietpi.com (previously IP): https://github.com/Fourdee/DietPi/issues/2022#issuecomment-415470064 +General | 1st run setup and dietpi-update logs are now created in RAM, then copied to disk once completed '/var/tmp/dietpi/logs/dietpi-firstrun-setup.log'. This will speed up 1st run setup installation for slow SBCs and/or rootFS. +General | PineA64: Image updated to v6.14, also contains the latest kernel/uboot by Ayufan (0.6.2): https://github.com/Fourdee/DietPi/issues/2026 +General | Resolved an isssue where the initial 1st run connection test would fail, if timesync had not yet completed, and, the SSL cert of the connection test site is not valid for current date on system: https://github.com/Fourdee/DietPi/issues/2039 +General| SparkySBC: Support for native DSD playback on iFi Pro iDSD. Many thanks @sudeep: https://github.com/sparky-sbc/sparky-test/tree/master/dsd-marantz +DietPi-Backup/Sync | rsync transfer: Now shows progress information during the transfer: https://github.com/Fourdee/DietPi/issues/2044#issuecomment-417779406 +DietPi-Backup | Added an option to delete the currently selected backup, if it exists. +DietPi-Config | Advanced Options: You can now toggle if a real RTC is installed. This adds/removes 'fake-hwclock' package installation as requested: https://github.com/Fourdee/DietPi/issues/2041 +DietPi-Config | Added support for setting CPU min/max frequencies on Intel based CPUs. NB: 'cpu' command will always list the min/max frequencies read from kernel values, Intel CPUs do not update these values, however, you can gauge CPU frequency range by running 'cpu' to monitor the current CPU freq (use of stress test in 'dietpi-config' may also help). +DietPi-Drive_Manager | Added support to set a global idle duration, before drives are powered down. This feature uses hdparm. Not all drives will support this feature, however, its the best we can do, considering the lack of any standardised system across all drives, compatible with hdparm and visa versa: https://github.com/Fourdee/DietPi/issues/2001 +DietPi-Drive_Manager | When mounting drives to existing directories, if the directory is empty, you will given an option to mount regardless. If the directory contains any files or data, mounting will be denied: https://github.com/Fourdee/DietPi/issues/2056 +DietPi-Software | MPD: Updated to 0.20.21 and now includes SQL (sticker) support by default: https://github.com/Fourdee/DietPi/issues/2032#issuecomment-415559451 +DietPi-Software | myMPD: Now available for installation. A recent fork of YMPD with additional features: https://github.com/Fourdee/DietPi/issues/2032#issuecomment-415559451 +DietPi-Software | Emby: Reworked the installation to use standalone .debs, for fresh installations only. Now supports ARMv8 devices. ARMv6 devices are not supported: https://github.com/Fourdee/DietPi/issues/534#issuecomment-416405968 + +Bug Fixes: +General | fake-hwclock: is now installed for all systems, due to 'hwclock' detection reporting incorrect results, for those devices without a RTC attached: https://github.com/Fourdee/DietPi/issues/2035#issuecomment-416345155 +General | Resolved an issue where enabling the RPi camera (dietpi-config or installed via dietpi-software), would result in concurrent execution error: https://github.com/Fourdee/DietPi/issues/2008#issuecomment-414846353 +General | Resolved an issue with RK based network devices, where enabling offloading would cause stability issues. Many thanks to @carlosedp for this fix!: https://github.com/Fourdee/DietPi/issues/2028#issue-352323603 +General | Resolved an issue where automatic swapfile generation, would not run a freespace check prior: https://github.com/Fourdee/DietPi/issues/2048#issuecomment-417855645 +DietPi-Automation | Resolved an issue where 'AUTO_SETUP_INSTALL_SOFTWARE_ID' would include numbers contained within comments: https://github.com/Fourdee/DietPi/issues/2036#issuecomment-416613903 +DietPi-Cloudshell | Resolved incorrect RAM usage readout, and, inability to run from menu on same screen: https://github.com/Fourdee/DietPi/issues/2066 +DietPi-Config | Resolved an issue with PineA64 resolution changes, due to updated uEnv.txt on the latest PineA64 image. NB: for this feature to work, you must have an installation of the latest PineA64 v6.14 image from the DietPi site: https://dietpi.com/phpbb/viewtopic.php?f=11&t=4431&p=14010#p14010 +DietPi-Drive_Manager | Correctly handles bind mounts, contained within '/etc/fstab': https://github.com/Fourdee/DietPi/issues/2013 +DietPi-Process_Tool | Resolved an issue with PIDs no longer existing, causing an apply to fail: https://github.com/Fourdee/DietPi/issues/2059 +DietPi-Software | PlexPy/Tautulli: Resolved an issue with recent pre-req changes for this application, required for start functionality: https://github.com/Fourdee/DietPi/issues/2047 +DietPi-Update | Resolved an issue where all required EMR patches, would not be applied, in the 1st pass of the patch_file. + +----------------------------------------------------------------------------------------------------------- + v6.14 (21/08/18) diff --git a/PREP_SYSTEM_FOR_DIETPI.sh b/PREP_SYSTEM_FOR_DIETPI.sh index 9f3b0ce821..0e56718ae6 100644 --- a/PREP_SYSTEM_FOR_DIETPI.sh +++ b/PREP_SYSTEM_FOR_DIETPI.sh @@ -1041,6 +1041,7 @@ _EOF_ G_RUN_CMD systemctl enable dietpi-ramlog G_RUN_CMD systemctl enable dietpi-boot + G_RUN_CMD systemctl enable dietpi-preboot G_RUN_CMD systemctl enable dietpi-postboot G_RUN_CMD systemctl enable kill-ssh-user-sessions-before-network @@ -1174,6 +1175,14 @@ _EOF_ /DietPi/dietpi/func/dietpi-set_hardware serialconsole enable # - Disable for post-1st run setup: sed -i '/^[[:blank:]]*CONFIG_SERIAL_CONSOLE_ENABLE=/c\CONFIG_SERIAL_CONSOLE_ENABLE=0' /DietPi/dietpi.txt + # - must be enabled for the following: + # XU4: https://github.com/Fourdee/DietPi/issues/2038#issuecomment-416089875 + # RockPro64: Fails to boot into kernel without serial enabled + if (( $G_HW_MODEL == 11 || $G_HW_MODEL == 42 )); then + + sed -i '/^[[:blank:]]*CONFIG_SERIAL_CONSOLE_ENABLE=/c\CONFIG_SERIAL_CONSOLE_ENABLE=1' /DietPi/dietpi.txt + + fi G_DIETPI-NOTIFY 2 'Reducing getty count and resource usage:' @@ -1238,7 +1247,7 @@ _EOF_ spindown_time = 120 # - apm = 254 + apm = 127 } _EOF_ export G_ERROR_HANDLER_EXITCODE=$? @@ -1395,18 +1404,25 @@ _EOF_ /DietPi/dietpi/func/dietpi-set_hardware wificreds set - G_DIETPI-NOTIFY 2 'Disabling generic WiFi/BT by default' + G_DIETPI-NOTIFY 2 'Disabling generic BT by default' /DietPi/dietpi/func/dietpi-set_hardware bluetooth disable - /DietPi/dietpi/func/dietpi-set_hardware wifimodules disable - G_DIETPI-NOTIFY 2 'Enabling onboard WiFi modules by default' + # - Set WiFi + local tmp_info='Disabling' + local tmp_mode='disable' + if (( $WIFI_REQUIRED )); then + + tmp_info='Enabling' + tmp_mode='enable' - /DietPi/dietpi/func/dietpi-set_hardware wifimodules onboard_enable + fi - #G_DIETPI-NOTIFY 2 'Configuring IP version preferences' + G_DIETPI-NOTIFY 2 "$tmp_info onboard WiFi modules by default" + /DietPi/dietpi/func/dietpi-set_hardware wifimodules onboard_$tmp_mode - #/DietPi/dietpi/func/dietpi-set_hardware preferipversion ipv4 #Already done at top of script, and now default in dietpi.txt + G_DIETPI-NOTIFY 2 "$tmp_info generic WiFi by default" + /DietPi/dietpi/func/dietpi-set_hardware wifimodules $tmp_mode # x86_64: kernel cmd line with GRUB if (( $G_HW_ARCH == 10 )); then diff --git a/README.md b/README.md index 7fc984868f..22d13fcb22 100644 --- a/README.md +++ b/README.md @@ -219,3 +219,6 @@ FreshRSS Folding@Home - https://github.com/FoldingAtHome + +OpenBazaar +- https://github.com/OpenBazaar/openbazaar-go diff --git a/dietpi.txt b/dietpi.txt index 983e1c0b54..68411f55c7 100644 --- a/dietpi.txt +++ b/dietpi.txt @@ -128,7 +128,12 @@ AUTO_SETUP_LOCALE=en_GB.UTF-8 # Keyboard Layout eg: gb us de fr AUTO_SETUP_KEYBOARD_LAYOUT=gb -# Custom Script | Requires AUTO_SETUP_AUTOMATED=1 +# Custom Script (pre-networking and pre-DietPi install) | Runs before DietPi installation and networking +# Allows you to automatically execute a custom script before networking and DietPi installation is started +# Option 1 = Copy your script to /boot/Automation_Custom_PreScript.sh and it will be executed automatically. +# NB: Executed script log /var/tmp/dietpi/logs/dietpi-automation_custom_prescript.log + +# Custom Script (post-networking and post-DietPi install) | Runs after DietPi installation is completed # Allows you to automatically execute a custom script at the end of DietPi installation. # Option 1 = Copy your script to /boot/Automation_Custom_Script.sh and it will be executed automatically. # Option 2 = Host your script online, then use AUTO_SETUP_CUSTOM_SCRIPT_EXEC=http://myweb.com/myscript.sh , it will be downloaded and executed automatically. | 0=disabled @@ -146,13 +151,15 @@ CONFIG_HDMI_OUTPUT=1 CONFIG_CPU_GOVERNOR=ondemand CONFIG_CPU_USAGE_THROTTLE_UP=50 -#Limit the max cpu frequency (Mhz) for all cores. | Disabled=disabled | Useful for lowering temp/power usage on your device. +#CPU Frequency Limits +# NB: Intel CPU's use a percentage value (%) from 0-100 (eg: 55) +# NB: All other devices must use a specific MHz value (eg: 1600) +# Limit the MAX cpu frequency for all cores | Disabled=disabled CONFIG_CPU_MAX_FREQ=Disabled - -#Limit the min cpu frequency (Mhz) for all cores. | Disabled=disabled | Useful for 1-wire correct support (eg. 480Mhz). +# Limit the MIN cpu frequency for all cores | Disabled=disabled CONFIG_CPU_MIN_FREQ=Disabled -#Disable Intel based turbo/boost stepping. +# Disable Intel based turbo/boost stepping. This flag should not be required, setting <100% MAX frequency should disable Turbo on Intel CPU's. CONFIG_CPU_DISABLE_TURBO=0 #Min value 10000 microseconds (10ms) @@ -183,6 +190,7 @@ CONFIG_WIFI_COUNTRY_CODE=GB #Serial Console: Set to 1 if you require a serial console. # NB: Serial console is always enabled by default for 1st run setup, then disabled afterwards, unless set below. +# NB: must be ENABLED for the following boards: Odroid XU4/HC1/HC2, RockPro64 CONFIG_SERIAL_CONSOLE_ENABLE=0 #Soundcard diff --git a/dietpi/.version b/dietpi/.version index fcbc21b7ff..f1daa160cf 100644 --- a/dietpi/.version +++ b/dietpi/.version @@ -1,2 +1,2 @@ 6 -14 +15 diff --git a/dietpi/boot b/dietpi/boot index dd26c0a28a..69f4507fd4 100644 --- a/dietpi/boot +++ b/dietpi/boot @@ -10,11 +10,10 @@ # # Info: # - filename /DietPi/dietpi/boot - # - activates on boot from /etc/init.d/dietpi-service + # - activates on boot from dietpi-boot.service #//////////////////////////////////// #Import DietPi-Globals --------------------------------------------------------------- - /DietPi/dietpi/func/dietpi-obtain_hw_model # Running for the 1st time . /DietPi/dietpi/func/dietpi-globals export G_PROGRAM_NAME='DietPi-Boot' G_INIT @@ -24,219 +23,13 @@ #Globals #///////////////////////////////////////////////////////////////////////////////////// - RPi_Set_Clock_Speeds(){ - - #RPi's - if (( $G_HW_MODEL < 10 )); then - - #If no overclocking is set. set values to current (used in dietpi-config as reference for overclocking / current values) - if grep -q '^#over_voltage=' /DietPi/config.txt && - grep -q '^#arm_freq=' /DietPi/config.txt && - grep -q '^#core_freq=' /DietPi/config.txt && - grep -q '^#sdram_freq=' /DietPi/config.txt; then - - #RPi v1 - Set safe clock - if (( $G_HW_MODEL < 2 )); then - - sed -i '/over_voltage=/c\over_voltage=2' /DietPi/config.txt - 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=400' /DietPi/config.txt - - #Zero - if [[ $G_HW_MODEL_DESCRIPTION == *'Zero'* ]]; then - - sed -i '/over_voltage=/c\#over_voltage=0' /DietPi/config.txt - 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 - - #RPi v2 - elif (( $G_HW_MODEL == 2 )); then - - sed -i '/over_voltage=/c\#over_voltage=0' /DietPi/config.txt - 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 - - #RPi v3 - elif (( $G_HW_MODEL == 3 )); then - - sed -i '/over_voltage=/c\#over_voltage=0' /DietPi/config.txt - sed -i '/core_freq=/c\#core_freq=400' /DietPi/config.txt - sed -i "/temp_limit=/c\temp_limit=75" /DietPi/config.txt # https://github.com/Fourdee/DietPi/issues/356 - - local arm_freq=1200 - local sdram_freq=450 - if [[ $G_HW_MODEL_DESCRIPTION == *'RPi 3 Model B+'* ]]; then - - arm_freq=1400 - sdram_freq=500 - - fi - - sed -i "/arm_freq=/c\#arm_freq=$arm_freq" /DietPi/config.txt - sed -i "/sdram_freq=/c\#sdram_freq=$sdram_freq" /DietPi/config.txt - - fi - - fi - - fi - - } - Apply_DietPi_FirstRun_Settings(){ #---------------------------------------------------------------- #Automation - # - Set hostname - /DietPi/dietpi/func/change_hostname "$(grep -m1 '^[[:blank:]]*AUTO_SETUP_NET_HOSTNAME=' /DietPi/dietpi.txt | sed 's/^.*=//')" - - # - Set auto login for next bootup - if grep -qi '^[[:blank:]]*AUTO_SETUP_AUTOMATED=1' /DietPi/dietpi.txt; then - - /DietPi/dietpi/dietpi-autostart 7 - - fi - - # - Disable serial console? - if grep -qi '^[[:blank:]]*CONFIG_SERIAL_CONSOLE_ENABLE=0' /DietPi/dietpi.txt; then - - /DietPi/dietpi/func/dietpi-set_hardware serialconsole disable - - fi - - # - Set root password? - local root_password="$(grep -m1 '^[[:blank:]]*AUTO_SETUP_GLOBAL_PASSWORD=' /DietPi/dietpi.txt | sed 's/^.*=//')" - if [ -n "$root_password" ]; then - - chpasswd <<< "root:$root_password" - chpasswd <<< "dietpi:$root_password" - - fi - - # - Set apt mirror - local target_repo='CONFIG_APT_DEBIAN_MIRROR' - if (( $G_HW_MODEL < 10 )); then - - target_repo='CONFIG_APT_RASPBIAN_MIRROR' - - fi - - /DietPi/dietpi/func/dietpi-set_software apt-mirror "$(grep -m1 "^[[:blank:]]*$target_repo=" /DietPi/dietpi.txt | sed 's/^.*=//')" - - # - Generate unique Dropbear host-key: - rm /etc/dropbear/*key &> /dev/null - dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key &> /dev/null - dropbearkey -t ecdsa -f /etc/dropbear/dropbear_ecdsa_host_key &> /dev/null - dropbearkey -t dss -f /etc/dropbear/dropbear_dss_host_key &> /dev/null - - # - Recreate machine-id: https://github.com/Fourdee/DietPi/issues/2015 - rm /etc/machine-id &> /dev/null - rm /var/lib/dbus/machine-id &> /dev/null - systemd-machine-id-setup - - # - Network - local index_eth=$(sed -n 1p /DietPi/dietpi/.network) - local index_wlan=$(sed -n 2p /DietPi/dietpi/.network) - - systemctl stop networking.service - - # Kill dhclient - killall -w dhclient &> /dev/null - - # Drop Connections - ifdown eth$index_eth &> /dev/null - ifdown wlan$index_wlan &> /dev/null - - # Replace all eth0 and wlan0 values to the indexs DietPi has found. - sed -i "s/eth0/eth$index_eth/g" /etc/network/interfaces - sed -i "s/wlan0/wlan$index_wlan/g" /etc/network/interfaces - - # Grab user requested settings from /dietpi.txt - local Ethernet_Enabled=$(grep -ci -m1 '^[[:blank:]]*AUTO_SETUP_NET_ETHERNET_ENABLED=1' /DietPi/dietpi.txt) - local Wifi_Enabled=$(grep -ci -m1 '^[[:blank:]]*AUTO_SETUP_NET_WIFI_ENABLED=1' /DietPi/dietpi.txt) - - local Use_Static=$(grep -ci -m1 '^[[:blank:]]*AUTO_SETUP_NET_USESTATIC=1' /DietPi/dietpi.txt) - local Static_IP="$(grep -m1 '^[[:blank:]]*AUTO_SETUP_NET_STATIC_IP=' /DietPi/dietpi.txt | sed 's/^.*=//')" - local Static_Mask="$(grep -m1 '^[[:blank:]]*AUTO_SETUP_NET_STATIC_MASK=' /DietPi/dietpi.txt | sed 's/^.*=//')" - local Static_Gateway="$(grep -m1 '^[[:blank:]]*AUTO_SETUP_NET_STATIC_GATEWAY=' /DietPi/dietpi.txt | sed 's/^.*=//')" - local Static_Dns="$(grep -m1 '^[[:blank:]]*AUTO_SETUP_NET_STATIC_DNS=' /DietPi/dietpi.txt | sed 's/^.*=//')" - - # Wifi - if (( $Wifi_Enabled )); then - - #Enable Wlan, disable Eth - Ethernet_Enabled=0 - sed -i "/allow-hotplug wlan/c\allow-hotplug wlan$index_wlan" /etc/network/interfaces - sed -i "/allow-hotplug eth/c\#allow-hotplug eth$index_eth" /etc/network/interfaces - - # - Enable modules + Apply global SSID/Keys from dietpi.txt to wpa_supp - /DietPi/dietpi/func/dietpi-set_hardware wificreds set - /DietPi/dietpi/func/dietpi-set_hardware wifimodules enable - - # Ethernet - elif (( $Ethernet_Enabled )); then - - #Enable Eth, disable Wlan - Wifi_Enabled=0 - sed -i "/allow-hotplug eth/c\allow-hotplug eth$index_eth" /etc/network/interfaces - sed -i "/allow-hotplug wlan/c\#allow-hotplug wlan$index_wlan" /etc/network/interfaces - - fi - - # Static IPs - if (( $Use_Static )); then - - #enable dns-nameservers - sed -i 's/^#dns-nameservers/dns-nameservers/g' /etc/network/interfaces - - if (( $Wifi_Enabled )); then - - sed -i "/iface wlan/c\iface wlan$index_wlan inet static" /etc/network/interfaces - - elif (( $Ethernet_Enabled )); then - - sed -i "/iface eth/c\iface eth$index_eth inet static" /etc/network/interfaces - - fi - - sed -i "/address/c\address $Static_IP" /etc/network/interfaces - sed -i "/netmask/c\netmask $Static_Mask" /etc/network/interfaces - sed -i "/gateway/c\gateway $Static_Gateway" /etc/network/interfaces - sed -i "/dns-nameservers/c\dns-nameservers $Static_Dns" /etc/network/interfaces - - fi - - # Kill dhclient, again: https://github.com/Fourdee/DietPi/issues/660 - killall -w dhclient - - # Restart Networking - systemctl daemon-reload - #systemctl restart networking #: Does exactly the same as ifdown/up that we already do. - - # Manually bring up adapters - if (( $Wifi_Enabled )); then - - ifup wlan$index_wlan - - elif (( $Ethernet_Enabled )); then - - ifup eth$index_eth - - fi - - # - Apply forced eth speed if set in dietpi.txt - /DietPi/dietpi/func/dietpi-set_hardware eth-forcespeed $(grep -m1 '^[[:blank:]]*AUTO_SETUP_NET_ETH_FORCE_SPEED=' /DietPi/dietpi.txt | sed 's/^.*=//' ) - - # - Wait for active connection, then update network details file - Wait_For_Valid_Network_Connection - # - Set NTPD mode - /DietPi/dietpi/func/dietpi-set_software ntpd-mode $(grep -m1 '^[[:blank:]]*CONFIG_NTP_MODE=' /DietPi/dietpi.txt | sed 's/^.*=//') + /DietPi/dietpi/func/dietpi-set_software ntpd-mode $(grep -m1 '^[[:blank:]]*CONFIG_NTP_MODE=' /DietPi/dietpi.txt | sed 's/^[^=]*=//') + #---------------------------------------------------------------- } @@ -246,7 +39,7 @@ local max_loops=1 # Wait mode, max time - local boot_wait_for_network=$(grep -m1 '^CONFIG_BOOT_WAIT_FOR_NETWORK=' /DietPi/dietpi.txt | sed 's/.*=//') + local boot_wait_for_network=$(grep -m1 '^[[:blank:]]*CONFIG_BOOT_WAIT_FOR_NETWORK=' /DietPi/dietpi.txt | sed 's/^[^=]*=//') if (( $boot_wait_for_network == 1 )); then max_loops=10 @@ -254,7 +47,7 @@ fi local loop_count=0 - while true + while : do if [[ $(ip r) =~ ' via ' ]]; then @@ -278,7 +71,7 @@ fi - if (( $boot_wait_for_network != 2 )); then + if (( $boot_wait_for_network < 2 )); then ((loop_count++)) @@ -292,40 +85,18 @@ #---------------------------------------------------------------- #WiFi Country | Additional fallback for (older kernel?) devices that fail with wpa_supplicant.conf https://github.com/Fourdee/DietPi/issues/838 - which iw &> /dev/null && iw reg set "$(grep -m1 '^[[:blank:]]*CONFIG_WIFI_COUNTRY_CODE=' /DietPi/dietpi.txt | sed 's/^.*=//')" & - #---------------------------------------------------------------- - #Apply LED triggers if set - /DietPi/dietpi/func/dietpi-led_control 1 & - #---------------------------------------------------------------- - #RPi set volume to -0.1db | We have to do it here because sound card modules (dietpi-set_hardware) are not enabled on the fly, requires a reboot. - if (( $G_HW_MODEL < 10 )); then - - which amixer &> /dev/null && amixer set PCM -- -010 & - - fi + which iw &> /dev/null && iw reg set "$(grep -m1 '^[[:blank:]]*CONFIG_WIFI_COUNTRY_CODE=' /DietPi/dietpi.txt | sed 's/^[^=]*=//')" & #---------------------------------------------------------------- - #Apply DietPi CPU Governor and settings - /DietPi/dietpi/func/dietpi-set_cpu & + Workaround_WiFi #---------------------------------------------------------------- - #Disable RPi hdmi output if set in dietpi.txt - if grep -q '^[[:blank:]]*CONFIG_HDMI_OUTPUT=0' /DietPi/dietpi.txt; then - - if (( $G_HW_MODEL < 10 )); then - - /opt/vc/bin/tvservice -o &> /dev/null & - - fi - - fi + Wait_For_Valid_Network_Connection #---------------------------------------------------------------- - #Find first index number for network devices (checks 0-9) + #Grab IP data /DietPi/dietpi/func/obtain_network_details #---------------------------------------------------------------- # - Lower dmesg print level (mostly for Odroid C2 where HiFi Shield prints info when starting/stopping stream on tty1) dmesg -n 1 #---------------------------------------------------------------- - Workaround_WiFi - #---------------------------------------------------------------- } @@ -355,23 +126,22 @@ #Pre-Installed image, 1st run if (( $G_DIETPI_INSTALL_STAGE == 2 )); then - G_DIETPI_INSTALL_STAGE=1 - echo $G_DIETPI_INSTALL_STAGE > /DietPi/dietpi/.install_stage - # - Set swap - /DietPi/dietpi/func/dietpi-set_dphys-swapfile $(grep -m1 '^[[:blank:]]*AUTO_SETUP_SWAPFILE_SIZE=' /DietPi/dietpi.txt | sed 's/^.*=//') "$(grep -m1 '^[[:blank:]]*AUTO_SETUP_SWAPFILE_LOCATION=' /DietPi/dietpi.txt | sed 's/.*=//')" + /DietPi/dietpi/func/dietpi-set_dphys-swapfile $(grep -m1 '^[[:blank:]]*AUTO_SETUP_SWAPFILE_SIZE=' /DietPi/dietpi.txt | sed 's/^[^=]*=//') "$(grep -m1 '^[[:blank:]]*AUTO_SETUP_SWAPFILE_LOCATION=' /DietPi/dietpi.txt | sed 's/.*=//')" - # - Set survey + # - Run survey rm /DietPi/dietpi/.dietpi-survey &> /dev/null /DietPi/dietpi/dietpi-survey 1 &> /dev/null & + # - Continue with normal boot + export G_DIETPI_INSTALL_STAGE=1 + echo $G_DIETPI_INSTALL_STAGE > /DietPi/dietpi/.install_stage + fi #Normal Boot if (( $G_DIETPI_INSTALL_STAGE == 1 )); then - Wait_For_Valid_Network_Connection - /DietPi/dietpi/func/run_ntpd 1 &> /dev/null & if grep -qi '^[[:blank:]]*CONFIG_CHECK_DIETPI_UPDATES=1' /DietPi/dietpi.txt; then @@ -386,21 +156,16 @@ #First run prep elif (( $G_DIETPI_INSTALL_STAGE == -1 )); then - # Set RPi v1 safe overclocking profile (900mhz) - RPi_Set_Clock_Speeds - /DietPi/dietpi/func/dietpi-banner 0 - #Activate DietPi Boot Loader User Settings and bring up network (dietpi.txt) + # - Activate and apply any 1st run settings Apply_DietPi_FirstRun_Settings - Workaround_WiFi - - #Finished + # - Finished /DietPi/dietpi/func/dietpi-banner 0 echo -e ' Default Login:\n Username = root\n Password = dietpi\n' - #Set Install Stage index to trigger DietPi-Software installation on login + # - Set Install Stage index to trigger DietPi-Software installation on login echo 0 > /DietPi/dietpi/.install_stage fi diff --git a/dietpi/dietpi-autostart b/dietpi/dietpi-autostart index bc6765ff23..60d4798157 100644 --- a/dietpi/dietpi-autostart +++ b/dietpi/dietpi-autostart @@ -18,8 +18,8 @@ #Import DietPi-Globals --------------------------------------------------------------- . /DietPi/dietpi/func/dietpi-globals - G_CHECK_ROOT_USER export G_PROGRAM_NAME='DietPi-Autostart' + G_CHECK_ROOT_USER G_INIT #Import DietPi-Globals --------------------------------------------------------------- @@ -91,19 +91,19 @@ _EOF_ G_CONFIG_INJECT 'boot_delay=' 'boot_delay=0' /DietPi/config.txt - if (( ! $(grep -ci -m1 ' logo.nologo' /boot/cmdline.txt) )); then + if ! grep -qi ' logo.nologo' /boot/cmdline.txt; then sed -i 's/rootwait/rootwait logo.nologo/' /boot/cmdline.txt fi - if (( ! $(grep -ci -m1 ' loglevel=3' /boot/cmdline.txt) )); then + if ! grep -qi ' loglevel=3' /boot/cmdline.txt; then sed -i 's/rootwait/rootwait loglevel=3/' /boot/cmdline.txt fi - if (( ! $(grep -ci -m1 ' console=tty3' /boot/cmdline.txt) )); then + if ! grep -qi ' console=tty3' /boot/cmdline.txt; then sed -i 's/console=tty1/console=tty3/' /boot/cmdline.txt @@ -124,7 +124,7 @@ _EOF_ fi #Save boot index. - echo -e "$AUTO_START_INDEX" > /DietPi/dietpi/.dietpi-autostart_index + echo $AUTO_START_INDEX > /DietPi/dietpi/.dietpi-autostart_index systemctl daemon-reload @@ -134,7 +134,7 @@ _EOF_ Menu_Main(){ #existing boot flag - AUTO_START_INDEX=$(cat /DietPi/dietpi/.dietpi-autostart_index) + AUTO_START_INDEX=$( "$fp_search_results" - - #Do we have any results? - if (( $(cat "$fp_search_results" | wc -l) > 0 )); then - - readarray search_results_list < "$fp_search_results" - #Create List for Whiptail - G_WHIP_MENU_ARRAY=() - for ((i=0; i<${#search_results_list[@]}; i++)) - do - - local last_backup_date=$( grep 'Completed' ${search_results_list[$i]} | tail -1 | sed 's/.*: //' ) # Date of last backup for this backup - local backup_directory=$( echo -e ${search_results_list[$i]} | sed 's/\/'"$BACKUP_STATS_FILENAME"'//g' ) # Backup directory (minus the backup file), that we can use for target backup directory. - G_WHIP_MENU_ARRAY+=("$backup_directory" ": $last_backup_date") - - done - - G_WHIP_MENU 'Please select a previous backup to use:' - if (( $? == 0 )); then - - FP_TARGET_BACKUP="$G_WHIP_RETURNED_VALUE" - - fi - - #delete[] array - unset search_results_list - rm "$fp_search_results" &> /dev/null - - else - - G_WHIP_MSG 'No previous backups were found in /mnt/*' - - fi - - ;; - - 'Manual') - - Input_User_Directory - - ;; - - 'List') - - /DietPi/dietpi/dietpi-drive_manager 1 - FP_TARGET_BACKUP="$(cat /tmp/dietpi-drive_manager_selmnt)" - if [[ $FP_TARGET_BACKUP == '/' ]]; then - - FP_TARGET_BACKUP='/mnt' - - fi - - FP_TARGET_BACKUP+='/dietpi-backup' - - ;; - - esac - - else - - #Return to main menu - TARGETMENUID=0 - - fi - - Check_Supported_Directory_Location - # - Not supported, reset directory target to previous - if (( ! $TARGET_DIRECTORY_SUPPORTED )); then - - FP_TARGET_BACKUP="$current_directory" - - fi - - } - - Input_User_Directory(){ - - G_WHIP_DEFAULT_ITEM="$FP_TARGET_BACKUP" - G_WHIP_INPUTBOX "Please enter the filepath to your directory. \neg: /mnt/dietpi-backup\n - Must be located inside /mnt/* \n - Must be symlink compatible filesystem (ext2/3/4)" - if (( $? == 0 )); then - - FP_TARGET_BACKUP="$G_WHIP_RETURNED_VALUE" - - fi - - } - - #///////////////////////////////////////////////////////////////////////////////////// - # Errors - #///////////////////////////////////////////////////////////////////////////////////// - Error_Filesystem_Not_Supported(){ - - G_DIETPI-NOTIFY 1 "Filesystem not supported in $FP_TARGET_BACKUP" - - G_WHIP_MSG "Error:\n\n$FP_TARGET_BACKUP Has a filesystem of: $TARGET_FILESYSTEM_TYPE, and is not supported.\n\nThe filesystem must be EXT2/3/4 for symlink compatibility." - - } - - Error_Not_Mnt_Directory(){ - - G_DIETPI-NOTIFY 1 "Target directory is not inside /mnt ($FP_TARGET_BACKUP)" - - G_WHIP_MSG "Directory not supported:\n- $FP_TARGET_BACKUP\n\nThe location must be inside the /mnt/* directory.\n - eg: /mnt/dietpi-backup" - - } - - Error_DietpiUserdata_Directory(){ - - G_DIETPI-NOTIFY 1 "Target directory can not be contained within DietPi user data location ($FP_TARGET_BACKUP)" - - G_WHIP_MSG "Directory not supported:\n- $FP_TARGET_BACKUP\n\nTarget directory can not be contained within DietPi user data location ($G_FP_DIETPI_USERDATA)" - - } - - Error_Rsync_Already_Running(){ - - G_DIETPI-NOTIFY 1 "Another Rsync process is already running." - - echo -e "$RSYNC_MODE_TEXT failed: $(date +"%d-%m-%Y_%H%M"). Rsync is already running." >> "$FP_TARGET_BACKUP/$BACKUP_STATS_FILENAME" - - G_WHIP_MSG "$RSYNC_MODE_TEXT Error:\n\nA $RSYNC_MODE_TEXT could not be started as rsync is already running." - - } - #///////////////////////////////////////////////////////////////////////////////////// # Backup System #///////////////////////////////////////////////////////////////////////////////////// RSYNC_MODE_TEXT=0 - #LOGFILE - LOGFILE='/var/log/dietpi-backup.log' + FP_LOG='/var/log/dietpi-backup.log' #Backup Filepaths FP_SOURCE='/' @@ -314,9 +68,9 @@ ) #rsync options - RSYNC_RUN_OPTIONS_BACKUP="-aH --delete --delete-excluded --exclude-from=$FP_FILTER_INCLUDE_EXCLUDE" - RSYNC_RUN_OPTIONS_RESTORE="-aH --delete-after --exclude-from=$FP_FILTER_INCLUDE_EXCLUDE" - RSYNC_LOGGING_OPTIONS="-v --log-file=$LOGFILE" + RSYNC_RUN_OPTIONS_BACKUP="-aH --info=name0 --info=progress2 --delete --delete-excluded --exclude-from=$FP_FILTER_INCLUDE_EXCLUDE" + RSYNC_RUN_OPTIONS_RESTORE="-aH --info=name0 --info=progress2 --delete-after --exclude-from=$FP_FILTER_INCLUDE_EXCLUDE" + RSYNC_LOGGING_OPTIONS="-v --log-file=$FP_LOG" #Date format for logs Print_Date(){ @@ -352,7 +106,7 @@ #Global - Files - /var/swap - .swap* -- $LOGFILE +- $FP_LOG - $FP_DIETPIBACKUP_SETTINGS - $BACKUP_STATS_FILENAME - fake-hwclock.data @@ -416,15 +170,13 @@ _EOF_ #Start Backup - echo -e "DietPi-Backup Log File. $(date +"%d-%m-%Y_%H%M")\n\n" > "$LOGFILE" + echo -e "DietPi-Backup Log File. $(date +"%d-%m-%Y_%H%M")\n\n" > $FP_LOG #Generate Exclude/Include lists Create_Filter_Include_Exclude Services_Stop - G_DIETPI-NOTIFY 2 "Backing up to: $FP_TARGET_BACKUP" - while true do @@ -445,7 +197,7 @@ _EOF_ local end_result=$(( ( $new_backup_size - $old_backup_size ) / 1024 + 1 )) rm /tmp/dietpi-backup_result - if G_CHECK_FREESPACE "$FP_TARGET_BACKUP"/data $end_result; then + if ! G_CHECK_FREESPACE "$FP_TARGET_BACKUP"/data $end_result; then G_WHIP_BUTTON_OK_TEXT='Ignore' G_WHIP_BUTTON_CANCEL_TEXT='Exit' @@ -459,17 +211,28 @@ _EOF_ fi - G_RUN_CMD rsync $RSYNC_RUN_OPTIONS_BACKUP $RSYNC_LOGGING_OPTIONS "$FP_SOURCE" "$FP_TARGET_BACKUP"/data/ - echo -e "$RSYNC_MODE_TEXT Completed : $(Print_Date)" >> "$FP_TARGET_BACKUP/$BACKUP_STATS_FILENAME" - G_WHIP_MSG "$RSYNC_MODE_TEXT Completed:\n\n$RSYNC_MODE_TEXT was saved to:\n- $FP_TARGET_BACKUP\n- Log file: $LOGFILE" + G_DIETPI-NOTIFY 2 "$RSYNC_MODE_TEXT $FP_TARGET_BACKUP: in progress, please wait..." + + rsync $RSYNC_RUN_OPTIONS_BACKUP $RSYNC_LOGGING_OPTIONS "$FP_SOURCE" "$FP_TARGET_BACKUP"/data/ + EXIT_CODE=$? + G_DIETPI-NOTIFY -1 $EXIT_CODE "$G_PROGRAM_NAME: $RSYNC_MODE_TEXT" + if (( $EXIT_CODE == 0 )); then + + echo -e "$RSYNC_MODE_TEXT Completed : $(Print_Date)" >> "$FP_TARGET_BACKUP/$BACKUP_STATS_FILENAME" + G_WHIP_MSG "$RSYNC_MODE_TEXT Completed:\n - $FP_TARGET_BACKUP" + + else + + G_WHIP_MSG "$RSYNC_MODE_TEXT Failed:\n - $FP_TARGET_BACKUP\n\nYou will given an option to view the logfile on the next screen. Please check it for information and/or errors." + + fi # - done - EXIT_CODE=0 break done - G_WHIP_VIEWLOG "$LOGFILE" + G_WHIP_VIEWLOG $FP_LOG #return to main menu TARGETMENUID=0 @@ -515,16 +278,26 @@ _EOF_ #Generate Exclude/Include lists Create_Filter_Include_Exclude - G_DIETPI-NOTIFY 2 "Restoring from: $FP_TARGET_BACKUP" + G_DIETPI-NOTIFY 2 "$RSYNC_MODE_TEXT $FP_TARGET_BACKUP: in progress, please wait..." RSYNC_MODE_TEXT='Restore' - G_RUN_CMD rsync $RSYNC_RUN_OPTIONS_RESTORE $RSYNC_LOGGING_OPTIONS "$FP_TARGET_BACKUP"/data/ "$FP_SOURCE" - echo -e "$RSYNC_MODE_TEXT Completed : $(Print_Date)" >> "$FP_TARGET_BACKUP/$BACKUP_STATS_FILENAME" - G_WHIP_MSG "$RSYNC_MODE_TEXT Completed:\n\n- from:\n$FP_TARGET_BACKUP\n- Log file: $LOGFILE\n\nNB: A Reboot is highly recommended." - G_WHIP_VIEWLOG "$LOGFILE" + rsync $RSYNC_RUN_OPTIONS_RESTORE $RSYNC_LOGGING_OPTIONS "$FP_TARGET_BACKUP"/data/ "$FP_SOURCE" + EXIT_CODE=$? + G_DIETPI-NOTIFY -1 $EXIT_CODE "$G_PROGRAM_NAME: $RSYNC_MODE_TEXT" + if (( $EXIT_CODE == 0 )); then + + echo -e "$RSYNC_MODE_TEXT Completed : $(Print_Date)" >> "$FP_TARGET_BACKUP/$BACKUP_STATS_FILENAME" + G_WHIP_MSG "$RSYNC_MODE_TEXT Completed:\n - $FP_TARGET_BACKUP\n\nNB: A Reboot is highly recommended." + + else + + G_WHIP_MSG "$RSYNC_MODE_TEXT Failed:\n - $FP_TARGET_BACKUP\n\nYou will given an option to view the logfile on the next screen. Please check it for information and/or errors." + + fi + + G_WHIP_VIEWLOG $FP_LOG # - done - EXIT_CODE=0 TARGETMENUID=0 fi @@ -619,6 +392,264 @@ _EOF_ } + #///////////////////////////////////////////////////////////////////////////////////// + # MENUS + #///////////////////////////////////////////////////////////////////////////////////// + MENU_LASTITEM='' + TARGETMENUID=0 + + EXIT_CODE=-1 #Used for 1 time automated running only (eg: G_BACKUP) + + #TARGETMENUID=0 + Menu_Main(){ + + local backup_last_completed='Backup not found. Please create one.' + + G_WHIP_MENU_ARRAY=() + G_WHIP_MENU_ARRAY+=('' '●─ Info ') + G_WHIP_MENU_ARRAY+=('Help' "What does $G_PROGRAM_NAME do?") + G_WHIP_MENU_ARRAY+=('' '●─ Options ') + G_WHIP_MENU_ARRAY+=('Location' ': Change where your backup will be saved and restored from.') + G_WHIP_MENU_ARRAY+=('Custom Filters' ': Modify custom include/exclude filters for backups.') + if [[ -f $FP_TARGET_BACKUP'/'$BACKUP_STATS_FILENAME ]]; then + + G_WHIP_MENU_ARRAY+=('Delete' ": Remove backup ($FP_TARGET_BACKUP)") + backup_last_completed=$(grep 'Completed' "$FP_TARGET_BACKUP/$BACKUP_STATS_FILENAME" | tail -1) + + fi + G_WHIP_MENU_ARRAY+=('' '●─ Run ') + G_WHIP_MENU_ARRAY+=('Backup' 'Create (or update) a backup of this device.') + G_WHIP_MENU_ARRAY+=('Restore' 'Restore this device from a previous backup.') + + G_WHIP_DEFAULT_ITEM="$MENU_LASTITEM" + G_WHIP_BUTTON_CANCEL_TEXT='Exit' + G_WHIP_MENU "Current backup and restore location:\n - $FP_TARGET_BACKUP\n - $backup_last_completed" + if (( $? == 0 )); then + + MENU_LASTITEM="$G_WHIP_RETURNED_VALUE" + + case "$G_WHIP_RETURNED_VALUE" in + + 'Location') + + TARGETMENUID=1 + + ;; + + 'Custom Filters') + + nano $FP_USER_FILTER_INCLUDE_EXCLUDE_BACKUP + + ;; + + 'Help') + + G_WHIP_MSG "DietPi-Backup is a program that allows you to Backup and Restore your DietPi system.\n\nIf you have broken your system, or want to reset your system to an earlier date, this can all be done with DietPi-Backup.\n\nSimply choose a location where you want to save and restore your backups from, then, select Backup or Restore.\n\nMore information:\n - https://dietpi.com/phpbb/viewtopic.php?f=8&t=5&p=256#p255" + + ;; + + 'Delete') + + G_WHIP_YESNO "Do you wish to DELETE the following backup?\n - $FP_TARGET_BACKUP" + if (( $? == 0 )); then + + rm -R "$FP_TARGET_BACKUP" + + fi + + ;; + + 'Backup') + + G_WHIP_YESNO "The $text_start_mode_desc will be backed up to:\n$FP_TARGET_BACKUP\n\nDo you wish to continue and start the backup?" + if (( $? == 0 )); then + + Run_Backup + + fi + + ;; + + 'Restore') + + G_WHIP_YESNO "The $text_start_mode_desc will be restored from:\n$FP_TARGET_BACKUP\n\nDo you wish to continue and start the restore?" + if (( $? == 0 )); then + + Run_Restore + + fi + + ;; + + esac + + else + + Menu_Exit + + fi + + } + + Menu_Exit(){ + + G_WHIP_SIZE_X_MAX=50 + G_WHIP_YESNO "Exit $G_PROGRAM_NAME?" + if (( $? == 0 )); then + + EXIT_CODE=0 + TARGETMENUID=-1 + + fi + + } + + #TARGETMENUID=1 + Menu_Set_Directory(){ + + local current_directory="$FP_TARGET_BACKUP" + + G_WHIP_MENU_ARRAY=( + + 'Search' 'Find previous backups in /mnt/*' + 'List' 'Select from a list of available mounts/drives' + 'Manual' 'Manually type a directory to use.' + + ) + + G_WHIP_MENU "Please select the location where the backup will be saved, and restored from.\n\nYour current location:\n$FP_TARGET_BACKUP" + if (( $? == 0 )); then + + case "$G_WHIP_RETURNED_VALUE" in + + 'Search') + + local fp_search_results="/tmp/.dietpi-backup_search_results" + echo -e "\n\nSearching /mnt/* for previous backups, please wait... \n \n" + find /mnt -type f -name "$BACKUP_STATS_FILENAME" > "$fp_search_results" + + #Do we have any results? + if (( $(cat "$fp_search_results" | wc -l) > 0 )); then + + readarray search_results_list < "$fp_search_results" + #Create List for Whiptail + G_WHIP_MENU_ARRAY=() + for ((i=0; i<${#search_results_list[@]}; i++)) + do + + local last_backup_date=$( grep 'Completed' ${search_results_list[$i]} | tail -1 | sed 's/.*: //' ) # Date of last backup for this backup + local backup_directory=$( echo -e ${search_results_list[$i]} | sed 's/\/'"$BACKUP_STATS_FILENAME"'//g' ) # Backup directory (minus the backup file), that we can use for target backup directory. + G_WHIP_MENU_ARRAY+=("$backup_directory" ": $last_backup_date") + + done + + G_WHIP_MENU 'Please select a previous backup to use:' + if (( $? == 0 )); then + + FP_TARGET_BACKUP="$G_WHIP_RETURNED_VALUE" + + fi + + #delete[] array + unset search_results_list + rm "$fp_search_results" &> /dev/null + + else + + G_WHIP_MSG 'No previous backups were found in /mnt/*' + + fi + + ;; + + 'Manual') + + Input_User_Directory + + ;; + + 'List') + + /DietPi/dietpi/dietpi-drive_manager 1 + FP_TARGET_BACKUP="$(cat /tmp/dietpi-drive_manager_selmnt)" + if [[ $FP_TARGET_BACKUP == '/' ]]; then + + FP_TARGET_BACKUP='/mnt' + + fi + + FP_TARGET_BACKUP+='/dietpi-backup' + + ;; + + esac + + else + + #Return to main menu + TARGETMENUID=0 + + fi + + Check_Supported_Directory_Location + # - Not supported, reset directory target to previous + if (( ! $TARGET_DIRECTORY_SUPPORTED )); then + + FP_TARGET_BACKUP="$current_directory" + + fi + + } + + Input_User_Directory(){ + + G_WHIP_DEFAULT_ITEM="$FP_TARGET_BACKUP" + G_WHIP_INPUTBOX "Please enter the filepath to your directory. \neg: /mnt/dietpi-backup\n - Must be located inside /mnt/* \n - Must be symlink compatible filesystem (ext2/3/4)" + if (( $? == 0 )); then + + FP_TARGET_BACKUP="$G_WHIP_RETURNED_VALUE" + + fi + + } + + #///////////////////////////////////////////////////////////////////////////////////// + # Errors + #///////////////////////////////////////////////////////////////////////////////////// + Error_Filesystem_Not_Supported(){ + + G_DIETPI-NOTIFY 1 "Filesystem not supported in $FP_TARGET_BACKUP" + + G_WHIP_MSG "Error:\n\n$FP_TARGET_BACKUP Has a filesystem of: $TARGET_FILESYSTEM_TYPE, and is not supported.\n\nThe filesystem must be EXT2/3/4 for symlink compatibility." + + } + + Error_Not_Mnt_Directory(){ + + G_DIETPI-NOTIFY 1 "Target directory is not inside /mnt ($FP_TARGET_BACKUP)" + + G_WHIP_MSG "Directory not supported:\n- $FP_TARGET_BACKUP\n\nThe location must be inside the /mnt/* directory.\n - eg: /mnt/dietpi-backup" + + } + + Error_DietpiUserdata_Directory(){ + + G_DIETPI-NOTIFY 1 "Target directory can not be contained within DietPi user data location ($FP_TARGET_BACKUP)" + + G_WHIP_MSG "Directory not supported:\n- $FP_TARGET_BACKUP\n\nTarget directory can not be contained within DietPi user data location ($G_FP_DIETPI_USERDATA)" + + } + + Error_Rsync_Already_Running(){ + + G_DIETPI-NOTIFY 1 "Another Rsync process is already running." + + echo -e "$RSYNC_MODE_TEXT failed: $(date +"%d-%m-%Y_%H%M"). Rsync is already running." >> "$FP_TARGET_BACKUP/$BACKUP_STATS_FILENAME" + + G_WHIP_MSG "$RSYNC_MODE_TEXT Error:\n\nA $RSYNC_MODE_TEXT could not be started as rsync is already running." + + } + #///////////////////////////////////////////////////////////////////////////////////// # Main Loop #///////////////////////////////////////////////////////////////////////////////////// @@ -640,7 +671,7 @@ _EOF_ if [[ ! -f $FP_USER_FILTER_INCLUDE_EXCLUDE_BACKUP ]]; then cat << _EOF_ > $FP_USER_FILTER_INCLUDE_EXCLUDE_BACKUP -#DietPi-Backup | Custom include/exclude filters +#$_PROGRAM_NAME | Custom include/exclude filters # #To INCLUDE (+) a file/folder: # NB: dietpi_userdata is included by default, as well, if moved to a custom location. @@ -694,7 +725,7 @@ _EOF_ #----------------------------------------------------------------------------------- #Cleaup left over tmp files - rm "$FP_FILTER_INCLUDE_EXCLUDE" &> /dev/null + rm $FP_FILTER_INCLUDE_EXCLUDE &> /dev/null #----------------------------------------------------------------------------------- #delete[] array unset aSUPPORTED_FILESYSTEMS diff --git a/dietpi/dietpi-bugreport b/dietpi/dietpi-bugreport index 54be0e92b6..ae6cedf121 100644 --- a/dietpi/dietpi-bugreport +++ b/dietpi/dietpi-bugreport @@ -21,9 +21,9 @@ #Import DietPi-Globals --------------------------------------------------------------- . /DietPi/dietpi/func/dietpi-globals export G_PROGRAM_NAME='DietPi-Bugreport' - G_INIT G_CHECK_ROOT_USER G_CHECK_ROOTFS_RW + G_INIT #Import DietPi-Globals --------------------------------------------------------------- INPUT=0 @@ -36,7 +36,7 @@ UPLOAD_FILESIZE_LIMIT=10000000 UPLOAD_FILESIZE=0 - SFTP_ADDR='185.101.93.93' + SFTP_ADDR='ssh.dietpi.com' SFTP_USER='dietpi-survey' SFTP_PASS='upload2dietpi' diff --git a/dietpi/dietpi-cloudshell b/dietpi/dietpi-cloudshell index 9b8c9c905a..c198b61e72 100644 --- a/dietpi/dietpi-cloudshell +++ b/dietpi/dietpi-cloudshell @@ -32,7 +32,7 @@ DIETPI_CLOUDSHELL_VERSION=9 #/tmp/.* files used throughout this script. - FP_TEMP='/tmp/dietpi-cloudshell' + FP_TEMP="/tmp/$G_PROGRAM_NAME/.tmp" BLANK_SCREEN_ACTIVE=0 BLANK_SCREEN_AT_SPECIFIC_TIME_ENABLED=0 @@ -59,15 +59,21 @@ #Turn screen on elif (( $BLANK_SCREEN_TIME_HOUR_END == $current_hour )); then - setterm --blank poke &> /dev/tty1 - setterm --reset &> /dev/tty1 - setterm --blank 0 --powersave off &> /dev/tty1 - BLANK_SCREEN_ACTIVE=0 + Disable_Screen_Blanking fi } + Disable_Screen_Blanking(){ + + setterm --blank poke &> /dev/tty1 + setterm --reset &> /dev/tty1 + setterm --blank 0 --powersave off &> /dev/tty1 + BLANK_SCREEN_ACTIVE=0 + + } + #BC does not allow for printing leading zeros. BC_ADD_LEADING_ZERO(){ @@ -158,8 +164,7 @@ } - #Apply fonts - Enable_Term_Options(){ + Init_Term_Options(){ # - Set large font 1st (480x320+) setfont /usr/share/consolefonts/Uni3-TerminusBold32x16 @@ -171,6 +176,9 @@ fi + #Disable screen blanking on tty1 initially + Disable_Screen_Blanking + } #///////////////////////////////////////////////////////////////////////////////////// @@ -419,16 +427,14 @@ fi CPU_USAGE=0 - FP_TEMP='/tmp/.cpu_usage' # PS (inaccurate) - ps -axo %cpu | sed '1d' | sed 's/ //' > $FP_TEMP while read -r line do CPU_USAGE=$( echo "scale=1;$CPU_USAGE + $line" | bc -l ) - done < $FP_TEMP + done <<< "$(ps -axo %cpu | sed '1d' | sed 's/ //')" #ps returns usage of each core, so we devide the total by #n cores CPU_USAGE=$(echo "scale=0;$CPU_USAGE / $G_HW_CPU_CORES" | bc -l ) @@ -498,29 +504,26 @@ local index_start=$1 local index_end=$2 - FP_TEMP='/tmp/.df' - rm $FP_TEMP #df will endless hang when NFS server is down: https://github.com/Fourdee/DietPi/issues/395 # - So lets run it as another thread so we can kill it if it hangs. local df_failed=0 + rm $FP_TEMP df -Ph > $FP_TEMP & - local pid=$(echo $!) # - Wait X seconds before terminating the df thread local max_seconds=4 local current_seconds=0 - while ps aux | awk '{print $2}' | grep -q "$pid\$" # ! -f may exist, but no data at time of scrape, causing 'mount not found'. so lets wait for process to exit. + while [[ ! -f $FP_TEMP ]] do + #kill if (( $current_seconds >= $max_seconds )); then - #kill - G_DIETPI-NOTIFY 1 'DF failed, unable to obtain drive data' sleep 2 - kill $pid + killall -w df df_failed=1 @@ -562,24 +565,11 @@ Percent_To_Graph ${STORAGE_PERCENT[$i]} STORAGE_PERCENT[$i]=$C_PERCENT_GRAPH - #DEBUG John: - echo -e 'Results success:\n' >> /var/log/dietpi-cloudshell.log - echo -e " - Index = $i" >> /var/log/dietpi-cloudshell.log - echo -e " - Path = ${STORAGE_PATH[$i]}" >> /var/log/dietpi-cloudshell.log - echo -e " - Total = ${STORAGE_TOTAL[$i]}" >> /var/log/dietpi-cloudshell.log - else STORAGE_PERCENT[$i]="${STORAGE_PATH[$i]}" STORAGE_FREE[$i]='Mount not active' - #DEBUG John: - echo -e "$(date) | Mount not found:\n" >> /var/log/dietpi-cloudshell.log - echo -e " - Index = $i" >> /var/log/dietpi-cloudshell.log - echo -e " - Path = ${STORAGE_PATH[$i]}\n" >> /var/log/dietpi-cloudshell.log - cat $FP_TEMP >> /var/log/dietpi-cloudshell.log - echo -e '\n' >> /var/log/dietpi-cloudshell.log - fi done @@ -634,8 +624,6 @@ NETWORK_DETAILS_MODE=0 #1=dhcp, 0=static Obtain_NETWORK_DETAILS(){ - FP_TEMP='/tmp/.ip_address' - #Hostname NETWORK_DETAILS_HOSTNAME=$(hostname) @@ -763,15 +751,13 @@ Obtain_MEMORY(){ #Write to temp - FP_TEMP='/tmp/.mem' free -m > $FP_TEMP #RAM MB MEMORY_TOTAL=$(grep -m1 'Mem: ' $FP_TEMP | awk '{print $2}') - #Grab values and seperate cache from "used and free" results. - MEMORY_CACHED=$(grep -m1 'Mem: ' $FP_TEMP | awk '{print $7}') - MEMORY_USED=$(( $(grep -m1 'Mem: ' $FP_TEMP | awk '{print $3}') - $MEMORY_CACHED )) - MEMORY_FREE=$(( $(grep -m1 'Mem: ' $FP_TEMP | awk '{print $4}') + $MEMORY_CACHED )) + #MEMORY_CACHED=$(grep -m1 'Mem: ' $FP_TEMP | awk '{print $6}') + MEMORY_USED=$(( $(grep -m1 'Mem: ' $FP_TEMP | awk '{print $3}') )) + MEMORY_FREE=$(( $(grep -m1 'Mem: ' $FP_TEMP | awk '{print $7}') )) MEMORY_PERCENT=$(echo | awk "{print $MEMORY_USED / $MEMORY_TOTAL * 100}") #convert to interger and graph it @@ -797,7 +783,6 @@ fi - } #PI-HOLE STATS! @@ -1304,7 +1289,7 @@ _EOF_ #0=tty1 1=current OUTPUT_DISPLAY_INDEX=0 - Stop(){ + Menu_Stop(){ #Service if started. systemctl stop dietpi-cloudshell @@ -1320,7 +1305,7 @@ _EOF_ } - Start(){ + Menu_Start(){ #Are we starting on the current screen? (eg: from tty1) local output_current_screen=0 @@ -1346,7 +1331,7 @@ _EOF_ #Launch in blocking mode if (( $output_current_screen == 1 )); then - /DietPi/dietpi/dietpi-cloudshell 1 + Run_Cloudshell #Launch as service on main screen else @@ -1359,6 +1344,86 @@ _EOF_ } + Run_Cloudshell(){ + + Init_Term_Options + + #Start Intro + if (( $RUN_INTRO )); then + + Run_Intro + + fi + + #Set Nice to +10 (not critical) + renice -n 10 $$ &> /dev/null + + #Start display updates + while true + do + + if (( $BLANK_SCREEN_AT_SPECIFIC_TIME_ENABLED )); then + + RUN_BLANK_SCREEN_AT_SPECIFIC_TIME + + fi + + #Disable updates when screen is blanked + if (( $BLANK_SCREEN_ACTIVE )); then + + sleep 60 + + #Update enabled scenes + else + + if (( ${aEnabledScenes[$SCENE_CURRENT]} )); then + + Update_Banner + + # - Input mode scene update (storage array) + if (( $SCENE_CURRENT == 1 )); then + + Update_Scene_1 0 1 + + # - Input mode scene update (storage array) + elif (( $SCENE_CURRENT == 2 )); then + + Update_Scene_1 2 3 + + # - Input mode scene update (storage array) + elif (( $SCENE_CURRENT == 3 )); then + + Update_Scene_1 4 5 + + # - Normal scene update + else + + Update_Scene_$SCENE_CURRENT + + fi + + #Apply refresh rate delay + sleep $REFRESH_RATE + + fi + + #Scene Switcher + ((SCENE_CURRENT++)) + + #Cap + if (( $SCENE_CURRENT >= $MAX_SCENES )); then + + SCENE_CURRENT=0 + + fi + + + fi + + done + + } + #///////////////////////////////////////////////////////////////////////////////////// # Menu System #///////////////////////////////////////////////////////////////////////////////////// @@ -1491,14 +1556,14 @@ _EOF_ 'Start / Restart') Write_Settings_File - Stop - Start + Menu_Stop + Menu_Start ;; 'Stop') - Stop + Menu_Stop ;; @@ -1536,15 +1601,6 @@ _EOF_ #Return to main menu TARGETMENUID=0 - #Colour array - #0 WHITE - #1 RED - #2 GREEN - #3 YELLOW - #4 BLUE - #5 PURPLE - #6 CYAN - G_WHIP_MENU_ARRAY=( '0' 'White' @@ -1676,6 +1732,7 @@ _EOF_ ) + G_WHIP_BUTTON_CANCEL_TEXT='Back' G_WHIP_MENU 'Automatically power down the screen and disable DietPi-Cloudshell processing during a specific time.\n\nNB: This feature will only work if DietPi-Cloudshell was launched with the DietPi-Autostart option, or, launched from the main screen (tty1).' if (( $? == 0 )); then @@ -1747,6 +1804,7 @@ _EOF_ done + G_WHIP_BUTTON_CANCEL_TEXT='Back' G_WHIP_MENU 'Storage Device Mount Location:\n\nDietPi-Cloudshell pulls the storage stats from the drive mount location. If you have custom drives/mounts, please set them here to be displayed during storage scene updates.\n\n - Drive 1 = Displayed during main storage scene\n - Drive 2/3 = Displayed during additional storage scene\n - Drive 4/5 = Displayed during additional storage scene' if (( $? == 0 )); then @@ -1814,81 +1872,7 @@ _EOF_ #Run DietPi-Cloudshell elif (( $INPUT >= 1 )); then - Enable_Term_Options - - #Start Intro - if (( $RUN_INTRO )); then - - Run_Intro - - fi - - #Set Nice to +10 (not critical) - renice -n 10 $$ &> /dev/null - - #Start display updates - while true - do - - if (( $BLANK_SCREEN_AT_SPECIFIC_TIME_ENABLED )); then - - RUN_BLANK_SCREEN_AT_SPECIFIC_TIME - - fi - - #Disable updates when screen is blanked - if (( $BLANK_SCREEN_ACTIVE )); then - - sleep 60 - - #Update enabled scenes - else - - if (( ${aEnabledScenes[$SCENE_CURRENT]} )); then - - Update_Banner - - # - Input mode scene update (storage array) - if (( $SCENE_CURRENT == 1 )); then - - Update_Scene_1 0 1 - - # - Input mode scene update (storage array) - elif (( $SCENE_CURRENT == 2 )); then - - Update_Scene_1 2 3 - - # - Input mode scene update (storage array) - elif (( $SCENE_CURRENT == 3 )); then - - Update_Scene_1 4 5 - - # - Normal scene update - else - - Update_Scene_$SCENE_CURRENT - - fi - - #Apply refresh rate delay - sleep $REFRESH_RATE - - fi - - #Scene Switcher - ((SCENE_CURRENT++)) - - #Cap - if (( $SCENE_CURRENT >= $MAX_SCENES )); then - - SCENE_CURRENT=0 - - fi - - - fi - - done + Run_Cloudshell fi diff --git a/dietpi/dietpi-config b/dietpi/dietpi-config index 21e7c4e3f8..64affed4f2 100644 --- a/dietpi/dietpi-config +++ b/dietpi/dietpi-config @@ -1202,7 +1202,12 @@ elif (( $G_HW_MODEL == 40 )); then #Get Current Values - local current_resolution=$(grep -m1 'optargs=disp.screen0_output_mode=' /DietPi/uEnv.txt | sed 's/.*=//') + local current_resolution=$(grep -m1 '^hdmi_mode=' /DietPi/uEnv.txt | sed 's/.*=//') + if [[ ! $current_resolution ]]; then + + current_resolution='Not set' + + fi G_WHIP_MENU_ARRAY=( @@ -1225,7 +1230,7 @@ if [[ $current_resolution != $G_WHIP_RETURNED_VALUE ]]; then - sed -i "/^optargs=disp.screen0_output_mode=/c\optargs=disp.screen0_output_mode=$G_WHIP_RETURNED_VALUE" /DietPi/uEnv.txt + G_CONFIG_INJECT 'hdmi_mode=' "hdmi_mode=$G_WHIP_RETURNED_VALUE" /DietPi/uEnv.txt REBOOT_REQUIRED=1 fi @@ -1287,6 +1292,17 @@ fi G_WHIP_MENU_ARRAY+=('Time sync mode' ": $ntpd_mode_text") + local rtc_enabled=0 + local rtc_text='Emulated' + if [[ ! $(which fake-hwclock) ]]; then + + rtc_enabled=1 + rtc_text='Hardware' + + fi + + G_WHIP_MENU_ARRAY+=('RTC mode' ": $rtc_text") + G_WHIP_MENU_ARRAY+=('Update firmware' '') #No bluetooth and serial console for VM @@ -1358,6 +1374,9 @@ G_WHIP_MENU 'Please select an option:' if (( $? == 0 )); then + #Return to This Menu + TARGETMENUID=3 + if [[ $G_WHIP_RETURNED_VALUE == 'Swapfile' ]]; then G_WHIP_YESNO 'Swapfile control has been moved to DietPi-Drive_Manager, would you like to run the application now?\n\nOnce finished, exit to resume DietPi-Config' @@ -1367,8 +1386,20 @@ fi - #Return to This Menu - TARGETMENUID=3 + elif [[ $G_WHIP_RETURNED_VALUE == 'RTC mode' ]]; then + + if (( ! $rtc_enabled )); then + + G_AGP fake-hwclock + + else + + G_AGI fake-hwclock + + # - allow times in the past + G_CONFIG_INJECT 'FORCE=' 'FORCE=force' /etc/default/fake-hwclock + + fi elif [[ $G_WHIP_RETURNED_VALUE == 'Time sync mode' ]]; then @@ -1394,9 +1425,6 @@ fi - #Return to This Menu - TARGETMENUID=3 - elif [[ $G_WHIP_RETURNED_VALUE == 'Update firmware' ]]; then #RPI @@ -1434,9 +1462,6 @@ fi - #Return to This Menu - TARGETMENUID=3 - elif [[ $G_WHIP_RETURNED_VALUE == 'Max USB current' ]]; then #Enabled @@ -1463,9 +1488,6 @@ fi - #Return to This Menu - TARGETMENUID=3 - elif [[ $G_WHIP_RETURNED_VALUE == 'I2c state' ]]; then if (( ! $rpi_i2c_enabled )); then @@ -1480,9 +1502,6 @@ fi - #Return to This Menu - TARGETMENUID=3 - elif [[ $G_WHIP_RETURNED_VALUE == 'I2c frequency' ]]; then #remove kHz from current @@ -1500,9 +1519,6 @@ fi - #Return to This Menu - TARGETMENUID=3 - elif [[ $G_WHIP_RETURNED_VALUE == 'Serial console' ]]; then if (( $serialconsole_state == 0 )); then @@ -1517,9 +1533,6 @@ fi - #Return to This Menu - TARGETMENUID=3 - elif [[ $G_WHIP_RETURNED_VALUE == 'Bluetooth' ]]; then if (( $bluetooth_state )); then @@ -1532,9 +1545,6 @@ fi - #Return to This Menu - TARGETMENUID=3 - elif [[ $G_WHIP_RETURNED_VALUE == 'USB boot support' ]]; then if (( ! $rpi3_usb_boot_bit_enabled )); then @@ -1557,9 +1567,6 @@ fi - #Return to This Menu - TARGETMENUID=3 - fi fi @@ -1590,18 +1597,18 @@ fi - local arm_temp=$(G_OBTAIN_CPU_TEMP) - local arm_temp_f='Unknown' - if disable_error=1 G_CHECK_VALIDINT $arm_temp; then + local cpu_temp=$(G_OBTAIN_CPU_TEMP) + local cpu_temp_f='Unknown' + if disable_error=1 G_CHECK_VALIDINT $cpu_temp; then - arm_temp_f="$(( ( $arm_temp * 9 / 5 ) + 32 ))'f" - arm_temp+="'c" + cpu_temp_f="$(( ( $cpu_temp * 9 / 5 ) + 32 ))'f" + cpu_temp+="'c" fi local memory_total=$(( $(grep -m1 'MemTotal:' /proc/meminfo | awk '{print $2}') / 1000 )) local memory_free=$(( $(grep -m1 'MemFree:' /proc/meminfo | awk '{print $2}') / 1000 )) - local memory_usage=$(($memory_total - $memory_free)) + local memory_usage=$(( $memory_total - $memory_free )) #Create Menu List for Whiptail # - this will list the menu options available for each device. @@ -1609,7 +1616,9 @@ #Overclocking if (( $G_HW_MODEL < 10 )); then + G_WHIP_MENU_ARRAY+=('Overclocking' 'Set Profile') + fi #CPU GOV @@ -1637,34 +1646,40 @@ fi + #Define CPU scaling frequency or percent + local type_cpu_freq_info='MHz' + # - Intel + if [[ -f /sys/devices/system/cpu/intel_pstate/max_perf_pct ]]; then + + type_cpu_freq_info='%' + + fi - # User Scaling Max Freq limit. + # - User Scaling Max Freq limit. local user_frequency_max_current=$(grep -m1 '^[[:blank:]]*CONFIG_CPU_MAX_FREQ=' /DietPi/dietpi.txt | sed 's/^[^=]*=//') - local user_frequency_max_text="$user_frequency_max_current MHz" + local user_frequency_max_text="$user_frequency_max_current $type_cpu_freq_info" if (( ! $user_frequency_max_current )); then user_frequency_max_text='[Off]' fi - G_WHIP_MENU_ARRAY+=('CPU Max Freq Limit' ": $user_frequency_max_text") - - # User Scaling Min Freq limit. + # - User Scaling Min Freq limit. local user_frequency_min_current=$(grep -m1 '^[[:blank:]]*CONFIG_CPU_MIN_FREQ=' /DietPi/dietpi.txt | sed 's/^[^=]*=//') - local user_frequency_min_text="$user_frequency_min_current MHz" + local user_frequency_min_text="$user_frequency_min_current $type_cpu_freq_info" if (( ! $user_frequency_min_current )); then user_frequency_min_text='[Off]' fi - G_WHIP_MENU_ARRAY+=('CPU Min Freq Limit' ": $user_frequency_min_text") + G_WHIP_MENU_ARRAY+=('CPU Frequency Limits' ": Max = $user_frequency_max_text | Min = $user_frequency_min_text") #RPi extras if (( $G_HW_MODEL < 10 )); then - local current_arm_temp_limit=$(grep -m1 'temp_limit' /DietPi/config.txt | sed 's/^[^=]*=//') - G_WHIP_MENU_ARRAY+=('ARM Temp Limit ' ": $current_arm_temp_limit 'c") + local current_cpu_temp_limit=$(grep -m1 'temp_limit' /DietPi/config.txt | sed 's/^[^=]*=//') + G_WHIP_MENU_ARRAY+=('ARM Temp Limit ' ": $current_cpu_temp_limit 'c") ##Disabled due to https://github.com/Fourdee/DietPi/issues/73 #G_WHIP_MENU_ARRAY+=("Lower Idle Frequencies" ": $rpi_freq_min_text") @@ -1673,7 +1688,7 @@ fi - G_WHIP_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" + G_WHIP_MENU "Hardware : $G_HW_MODEL_DESCRIPTION \nCPU Temp: $cpu_temp : $cpu_temp_f\nRAM: $memory_total MB | Used: $memory_usage MB | Free: $memory_free MB" if (( $? == 0 )); then #Return to this menu @@ -1754,83 +1769,72 @@ ;; - 'CPU Max Freq Limit'*) + 'CPU Frequency Limits'*) /DietPi/dietpi/dietpi-cpuinfo 2 if [[ ! -f /tmp/dietpi-available_cpu_freqs ]]; then - G_WHIP_MSG 'Your processor / kernel, does not support this feature.\n\n(Info): Scaling_available_frequencies does not exist.' + G_WHIP_MSG 'The processor and/or kernel, does not support this feature.\n\n(Info): Scaling_available_frequencies does not exist.' else - G_WHIP_MENU_ARRAY==() local available_frequency_array=() - readarray available_frequency_array < /tmp/dietpi-available_cpu_freqs - for ((i=0; i<${#available_frequency_array[@]}; i++)) - do - - G_WHIP_MENU_ARRAY+=($(( ${available_frequency_array[$i]} / 1000 )) 'MHz') - - done - - #Add disable option - G_WHIP_MENU_ARRAY+=('Disabled' 'Returns clocks to default') + local division_factor=1000 #display MHz for user menu + # - Intel (disable conversion) + if [[ -f /sys/devices/system/cpu/intel_pstate/max_perf_pct ]]; then - G_WHIP_DEFAULT_ITEM="$user_frequency_max_current" - G_WHIP_MENU "Limit the maximum frequency that your processor can reach.\nThis can be useful for lowering temperature and saving power.\n\nCurrent setting: $user_frequency_max_text" - if (( $? == 0 )); then - - G_CONFIG_INJECT 'CONFIG_CPU_MAX_FREQ=' "CONFIG_CPU_MAX_FREQ=$G_WHIP_RETURNED_VALUE" /DietPi/dietpi.txt - /DietPi/dietpi/func/dietpi-set_cpu + division_factor=1 fi - #delete[] arrays - unset available_frequency_array + local index=0 #0=max | 1=min + while (( $index < 2 )) + do - fi + G_WHIP_MENU_ARRAY=() + for ((i=0; i<${#available_frequency_array[@]}; i++)) + do - ;; + G_WHIP_MENU_ARRAY+=($(( ${available_frequency_array[$i]} / $division_factor )) "$type_cpu_freq_info") - 'CPU Min Freq Limit'*) + done - /DietPi/dietpi/dietpi-cpuinfo 2 + G_WHIP_MENU_ARRAY+=('Disabled' 'Returns clocks to default') - if [[ ! -f /tmp/dietpi-available_cpu_freqs ]]; then + # - MAX + if (( $index == 0 )); then - G_WHIP_MSG "Your processor / kernel, does not support this feature.\n\n(Info): Scaling_available_frequencies does not exist." + G_WHIP_DEFAULT_ITEM="$user_frequency_max_current" + G_WHIP_MENU "Limit the maximum frequency that your processor can reach.\nThis can be useful for lowering temperature and saving power.\n\nCurrent setting: $user_frequency_max_text" + if (( $? == 0 )); then - else + G_CONFIG_INJECT 'CONFIG_CPU_MAX_FREQ=' "CONFIG_CPU_MAX_FREQ=$G_WHIP_RETURNED_VALUE" /DietPi/dietpi.txt - local available_frequency_array=() - G_WHIP_MENU_ARRAY==() + fi - readarray available_frequency_array < /tmp/dietpi-available_cpu_freqs - for ((i=0; i<${#available_frequency_array[@]}; i++)) - do + # - MIN + else - G_WHIP_MENU_ARRAY+=($(( ${available_frequency_array[$i]} / 1000 )) 'MHz') + G_WHIP_DEFAULT_ITEM="$user_frequency_min_current" + G_WHIP_MENU "Limit the minimum frequency that your processor can reach.\nThis can be useful for some timing critical stuff (eg. 1-wire below 480 Mhz won't work).\n\nCurrent setting: $user_frequency_min_text" + if (( $? == 0 )); then - done + G_CONFIG_INJECT 'CONFIG_CPU_MIN_FREQ=' "CONFIG_CPU_MIN_FREQ=$G_WHIP_RETURNED_VALUE" /DietPi/dietpi.txt - #Add disable option - G_WHIP_MENU_ARRAY+=('Disabled' 'Returns clocks to default') + fi - #Run menu - G_WHIP_DEFAULT_ITEM="$user_frequency_min_text" - G_WHIP_MENU "Limit the minimum frequency that your processor can reach.\nThis can be useful for some timing critical stuff (eg. 1-wire below 480 Mhz won't work).\n\nCurrent setting: $user_frequency_min_text" - if (( $? == 0 )); then + fi - G_CONFIG_INJECT 'CONFIG_CPU_MIN_FREQ=' "CONFIG_CPU_MIN_FREQ=$G_WHIP_RETURNED_VALUE" /DietPi/dietpi.txt - /DietPi/dietpi/func/dietpi-set_cpu + ((index++)) - fi + done - #delete[] arrays unset available_frequency_array + /DietPi/dietpi/func/dietpi-set_cpu + fi ;; @@ -1838,6 +1842,7 @@ 'Overclocking'*) TARGETMENUID=13 + ;; 'Change CPU Governor'*) @@ -1925,7 +1930,7 @@ MIN_VALUE=45 MAX_VALUE=85 - G_WHIP_DEFAULT_ITEM=$current_arm_temp_limit + G_WHIP_DEFAULT_ITEM=$current_cpu_temp_limit G_WHIP_INPUTBOX "When the ARM temperature ('c) reaches this value, the ARM will underclock to reduce heat. \n - Recommended value is 65 \n - Valid range $MIN_VALUE - $MAX_VALUE" if (( $? == 0 )); then @@ -3366,7 +3371,7 @@ INTERNET_TEST_URL=$G_WHIP_RETURNED_VALUE INTERNET_TEST_STATE=0 #Not tested - G_RUN_CMD_INFO_ONLY=1 retry_max=2 G_CHECK_URL "$INTERNET_TEST_URL" + G_ERROR_HANDLER_INFO_ONLY=1 retry_max=2 G_CHECK_URL "$INTERNET_TEST_URL" if (( $G_ERROR_HANDLER_EXITCODE_RETURN == 0 )); then INTERNET_TEST_STATE=2 #Online @@ -3971,115 +3976,36 @@ _EOF_ fi - /DietPi/dietpi/func/dietpi-benchmark 0 "$benchmark_temp_file" - - read_speed='Not tested' - write_speed='Not tested' - if [[ -f '/tmp/.dietpi-benchmark_result' ]]; then - - read_speed=$(sed -n 1p /tmp/.dietpi-benchmark_result) - write_speed=$(sed -n 2p /tmp/.dietpi-benchmark_result) - - rm /tmp/.dietpi-benchmark_result - - fi + FSBENCH_FP="$benchmark_temp_file" /DietPi/dietpi/func/dietpi-benchmark 0 # - Update global values. + local write_speed=$(sed -n 2p /tmp/dietpi-benchmark_results) + local read_speed=$(sed -n 3p /tmp/dietpi-benchmark_results) + if (( $device_index == 0 )); then - FSBENCH_SD_WRITE=$write_speed - FSBENCH_SD_READ=$read_speed + FSBENCH_SD_WRITE="${write_speed} MB/s" + FSBENCH_SD_READ="${read_speed} MB/s" elif (( $device_index == 1 )); then - FSBENCH_EXTERNAL_WRITE=$write_speed - FSBENCH_EXTERNAL_READ=$read_speed + FSBENCH_EXTERNAL_WRITE="${write_speed} MB/s" + FSBENCH_EXTERNAL_READ="${read_speed} MB/s" elif (( $device_index == 2 )); then - FSBENCH_RAM_WRITE=$write_speed - FSBENCH_RAM_READ=$read_speed + FSBENCH_RAM_WRITE="${write_speed} MB/s" + FSBENCH_RAM_READ="${read_speed} MB/s" elif (( $device_index == 3 )); then - FSBENCH_CUSTOM_WRITE=$write_speed - FSBENCH_CUSTOM_READ=$read_speed + FSBENCH_CUSTOM_WRITE="${write_speed} MB/s" + FSBENCH_CUSTOM_READ="${read_speed} MB/s" fi } - Run_CPUBenchmark(){ - - /DietPi/dietpi/dietpi-services stop - - 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 - - sync - sleep 1 - - { 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(){ @@ -4098,10 +4024,10 @@ _EOF_ ) G_WHIP_MENU "\ -CPU : Total time $CPUBENCH_INT_MAX int = $CPUBENCH_TIME seconds\n\ -RAM : Write = $FSBENCH_RAM_WRITE | Read = $FSBENCH_RAM_READ\n\ -RootFS : Write = $FSBENCH_SD_WRITE | Read = $FSBENCH_SD_READ \n\ -External Drive : Write = $FSBENCH_EXTERNAL_WRITE | Read = $FSBENCH_EXTERNAL_READ\n\ +CPU : Total time $CPUBENCH_INT_MAX int = $CPUBENCH_TIME seconds +RAM : Write = $FSBENCH_RAM_WRITE | Read = $FSBENCH_RAM_READ +RootFS : Write = $FSBENCH_SD_WRITE | Read = $FSBENCH_SD_READ +External Drive : Write = $FSBENCH_EXTERNAL_WRITE | Read = $FSBENCH_EXTERNAL_READ Custom : Write = $FSBENCH_CUSTOM_WRITE | Read = $FSBENCH_CUSTOM_READ" if (( $? == 0 )); then @@ -4112,7 +4038,8 @@ Custom : Write = $FSBENCH_CUSTOM_WRITE | Read = $FSBENCH_CUSTOM_READ" 'CPU') - Run_CPUBenchmark + /DietPi/dietpi/func/dietpi-benchmark 1 + CPUBENCH_TIME=$(sed -n 1p /tmp/dietpi-benchmark_results) ;; @@ -4565,7 +4492,7 @@ Custom : Write = $FSBENCH_CUSTOM_WRITE | Read = $FSBENCH_CUSTOM_READ" G_WHIP_MENU_ARRAY+=('default' '3.5mm Analogue') # Native PC/MISC devices | Detect and list available - elif (( $G_HW_MODEL == 21 || $G_HW_MODEL == 67 )); then + elif (( $G_HW_MODEL == 21 || $G_HW_MODEL == 42 || $G_HW_MODEL == 67 )); then G_WHIP_MENU_ARRAY+=('default' 'HW:0,0') diff --git a/dietpi/dietpi-cpuinfo b/dietpi/dietpi-cpuinfo index ca19b8796b..1c52cc13c1 100644 --- a/dietpi/dietpi-cpuinfo +++ b/dietpi/dietpi-cpuinfo @@ -13,7 +13,7 @@ # # Usage: # - /DietPi/dietpi/dietpi-cpuinfo Obtain stats and print - # - /DietPi/dietpi/dietpi-cpuinfo 2 Generates file of available, ordered scaling freq's "$FP_CPU_SCALINGAVAILABLE_FREQ" + # - /DietPi/dietpi/dietpi-cpuinfo 2 Generates file of available, ordered scaling freq's $FP_CPU_SCALINGAVAILABLE_FREQ #//////////////////////////////////// #Import DietPi-Globals --------------------------------------------------------------- @@ -74,8 +74,22 @@ done #Obtain available scaling freqs: + # - Intel + if [[ -f /sys/devices/system/cpu/intel_pstate/max_perf_pct ]]; then + + local index=0 + local value=10 + while (( $value <= 100 )) + do + + aCPU_SCALINGAVAILABLE_FREQ[$index]=$value + ((index++)) + value=$(( $value + 5 )) + + done + # - Standard - if [[ -f /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies ]]; then + elif [[ -f /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies ]]; then for ((i=0; i<$(nproc --all); i++)) do @@ -166,8 +180,7 @@ #Current Gov echo -e " Governor \e[90m|\e[0m $CPU_GOV_CURRENT" - if [[ $CPU_GOV_CURRENT == 'ondemand' ]] || - [[ $CPU_GOV_CURRENT == 'conservative' ]]; then + if [[ $CPU_GOV_CURRENT == 'ondemand' || $CPU_GOV_CURRENT == 'conservative' ]]; then echo -e " Throttle up \e[90m|\e[0m $(grep -m1 '^CONFIG_CPU_USAGE_THROTTLE_UP=' /DietPi/dietpi.txt | sed 's/.*=//')% CPU usage" @@ -200,19 +213,19 @@ Obtain_Cpu_Freq # Export to file - rm "$FP_CPU_SCALINGAVAILABLE_FREQ" &> /dev/null + rm $FP_CPU_SCALINGAVAILABLE_FREQ &> /dev/null if (( $CPU_SCALINGSUPPORTED )); then for ((i=0; i<${#aCPU_SCALINGAVAILABLE_FREQ[@]}; i++)) do - echo -e "${aCPU_SCALINGAVAILABLE_FREQ[$i]}" >> "$FP_CPU_SCALINGAVAILABLE_FREQ" + echo -e "${aCPU_SCALINGAVAILABLE_FREQ[$i]}" >> $FP_CPU_SCALINGAVAILABLE_FREQ done # Order, remove dupes - sort -u -n "$FP_CPU_SCALINGAVAILABLE_FREQ" -o "$FP_CPU_SCALINGAVAILABLE_FREQ" + sort -u -n $FP_CPU_SCALINGAVAILABLE_FREQ -o $FP_CPU_SCALINGAVAILABLE_FREQ fi diff --git a/dietpi/dietpi-drive_manager b/dietpi/dietpi-drive_manager index ea01328677..6d15f4c9c4 100644 --- a/dietpi/dietpi-drive_manager +++ b/dietpi/dietpi-drive_manager @@ -49,9 +49,9 @@ FP_TEMP_FSTAB='.fstab' #Drive data - FP_ROOTFS_SOURCE=0 - FP_USERDATA_CURRENT=0 - FP_SWAPFILE_CURRENT=0 + FP_ROOTFS_SOURCE='' + FP_USERDATA_CURRENT='' + FP_SWAPFILE_CURRENT='' INDEX_DRIVE_BEING_EDITED=0 DRIVE_TARGET_BEING_EDITED='' @@ -77,9 +77,6 @@ aDRIVE_SIZE_PERCENTUSED[$INDEX_INIT_CURRENT_DEVICE]='' aDRIVE_SIZE_FREE[$INDEX_INIT_CURRENT_DEVICE]='' - aDRIVE_APM[$INDEX_INIT_CURRENT_DEVICE]='' - aDRIVE_SPINDOWN_DELAY[$INDEX_INIT_CURRENT_DEVICE]='' - aDRIVE_ISFILESYSTEM[$INDEX_INIT_CURRENT_DEVICE]=0 aDRIVE_ISMOUNTED[$INDEX_INIT_CURRENT_DEVICE]=0 aDRIVE_ISREADONLY_CURRENTLY[$INDEX_INIT_CURRENT_DEVICE]=0 @@ -105,9 +102,6 @@ unset aDRIVE_SIZE_PERCENTUSED unset aDRIVE_SIZE_FREE - unset aDRIVE_APM - unset aDRIVE_SPINDOWN_DELAY - unset aDRIVE_ISFILESYSTEM unset aDRIVE_ISMOUNTED unset aDRIVE_ISREADONLY_CURRENTLY @@ -133,10 +127,10 @@ FP_ROOTFS_SOURCE=$(findmnt / -o source -n) #Recreate FStab - cp /etc/fstab $FP_TEMP_FSTAB + cp -a /etc/fstab $FP_TEMP_FSTAB # - Grab current tmpfs entries - local tmpfs_mounts=$(grep '^tmpfs[[:space:]]' $FP_TEMP_FSTAB) + local tmpfs_mounts=$(grep '^tmpfs[[:blank:]]' $FP_TEMP_FSTAB) # - Grab current bind local bind_mounts=$(grep '[[:blank:],]bind[[:blank:],]' $FP_TEMP_FSTAB) @@ -145,8 +139,8 @@ local swap_mount=$(grep -m1 '[[:blank:]]swap[[:blank:]]' $FP_TEMP_FSTAB) # - Grab current network mounts + creds - local net_mounts_samba=$(grep '[[:space:]]cifs[[:space:]]' $FP_TEMP_FSTAB) - local net_mounts_nfs=$(grep '[[:space:]]nfs.*[[:space:]]' $FP_TEMP_FSTAB) + local net_mounts_samba=$(grep '[[:blank:]]cifs[[:blank:]]' $FP_TEMP_FSTAB) + local net_mounts_nfs=$(grep '[[:blank:]]nfs.*[[:blank:]]' $FP_TEMP_FSTAB) local net_mounts_ftp=$(grep '^curlftpfs' $FP_TEMP_FSTAB) # Force regen (PREP) @@ -167,8 +161,7 @@ tmpfs /DietPi tmpfs defaults,size=10m,noatime,nodev,nosuid,mode=1777 0 0 fi - cat << _EOF_ > $FP_TEMP_FSTAB -#----------------------------------------------------------- + echo "#----------------------------------------------------------- #NETWORK #----------------------------------------------------------- #Please use DietPi-Drive_Manager to setup network mounts @@ -190,149 +183,164 @@ $swap_mount #----------------------------------------------------------- #PHYSICAL DRIVES -#----------------------------------------------------------- -_EOF_ +#-----------------------------------------------------------" > $FP_TEMP_FSTAB #Detect mounted drives and add them to fstab G_DIETPI-NOTIFY 2 'Detecting drives, please wait...' local cmd_scrape_string='' local index=0 G_DIETPI-NOTIFY 0 'Detecting currently mounted drives, please wait...' - df -Ph | tail -n +2 | sed '/tmpfs/d' | sed '/^udev/d' > .dietpi-drive_manager_df_tmp + df -Pha | tail -n +2 > .dietpi-drive_manager_df_tmp + + # - Remove bind from list: https://github.com/Fourdee/DietPi/issues/2013#issuecomment-416394374 while read line do - if [[ -z $line ]]; then + if [[ ! $line ]]; then - break + continue fi - Init_New_Device - - aDRIVE_ISMOUNTED[$INDEX_INIT_CURRENT_DEVICE]=1 - aDRIVE_ISPARTITIONTABLE[$INDEX_INIT_CURRENT_DEVICE]=1 - aDRIVE_MOUNT_SOURCE[$INDEX_INIT_CURRENT_DEVICE]=$(awk '{print $1}' <<< $line) - aDRIVE_MOUNT_TARGET[$INDEX_INIT_CURRENT_DEVICE]=$(awk '{print $6}' <<< $line) - # Workaround for /dev/root under RPi, force physical location - if [[ ${aDRIVE_MOUNT_TARGET[$INDEX_INIT_CURRENT_DEVICE]} == '/' ]]; then + local input_bind_mount_source="$(awk '{print $1}' <<< $line)" + local input_bind_mount_target="$(awk '{print $2}' <<< $line)" + sed -i "\#[[:blank:]]$input_bind_mount_target#d" .dietpi-drive_manager_df_tmp + sed -i "\#[[:blank:]]$input_bind_mount_source#d" .dietpi-drive_manager_df_tmp + if (( $DEBUG )); then - aDRIVE_MOUNT_SOURCE[$INDEX_INIT_CURRENT_DEVICE]=$FP_ROOTFS_SOURCE + G_DIETPI-NOTIFY 0 "BIND: match removed from df scrape: $input_bind_mount_source > $input_bind_mount_target" fi - aDRIVE_SOURCE_DEVICE[$INDEX_INIT_CURRENT_DEVICE]=$(Return_Drive_Without_Partitions ${aDRIVE_MOUNT_SOURCE[$INDEX_INIT_CURRENT_DEVICE]}) - # - Networked? - if [[ ! -d '/sys/block/'${aDRIVE_SOURCE_DEVICE[$INDEX_INIT_CURRENT_DEVICE]} ]]; then + done <<< "$bind_mounts" - aDRIVE_ISNETWORKED[$INDEX_INIT_CURRENT_DEVICE]=1 - aDRIVE_ISFILESYSTEM[$INDEX_INIT_CURRENT_DEVICE]=1 - aDRIVE_FSTYPE[$INDEX_INIT_CURRENT_DEVICE]='Net' + # - Process final DF result + while read line + do - # - Physical - else + if [[ ! $line ]]; then - cmd_scrape_string=$(blkid ${aDRIVE_MOUNT_SOURCE[$INDEX_INIT_CURRENT_DEVICE]} -s TYPE -o value) - if [[ $cmd_scrape_string ]]; then + continue - aDRIVE_ISFILESYSTEM[$INDEX_INIT_CURRENT_DEVICE]=1 - aDRIVE_FSTYPE[$INDEX_INIT_CURRENT_DEVICE]=$cmd_scrape_string + elif [[ $(awk '{print $1}' <<< $line) =~ '/' ]]; then + + Init_New_Device + + aDRIVE_ISMOUNTED[$INDEX_INIT_CURRENT_DEVICE]=1 + aDRIVE_ISPARTITIONTABLE[$INDEX_INIT_CURRENT_DEVICE]=1 + aDRIVE_MOUNT_SOURCE[$INDEX_INIT_CURRENT_DEVICE]=$(awk '{print $1}' <<< $line) + aDRIVE_MOUNT_TARGET[$INDEX_INIT_CURRENT_DEVICE]=$(awk '{print $6}' <<< $line) + # Workaround for /dev/root under RPi, force physical location + if [[ ${aDRIVE_MOUNT_TARGET[$INDEX_INIT_CURRENT_DEVICE]} == '/' ]]; then + + aDRIVE_MOUNT_SOURCE[$INDEX_INIT_CURRENT_DEVICE]=$FP_ROOTFS_SOURCE fi - aDRIVE_APM[$INDEX_INIT_CURRENT_DEVICE]=$(hdparm -B /dev/${aDRIVE_SOURCE_DEVICE[$INDEX_INIT_CURRENT_DEVICE]} | grep -i -m1 'APM_level' | awk '{print $NF}') - if ! disable_error=1 G_CHECK_VALIDINT ${aDRIVE_APM[$INDEX_INIT_CURRENT_DEVICE]}; then + aDRIVE_SOURCE_DEVICE[$INDEX_INIT_CURRENT_DEVICE]=$(Return_Drive_Without_Partitions ${aDRIVE_MOUNT_SOURCE[$INDEX_INIT_CURRENT_DEVICE]}) + # - Networked? + if [[ ! -d '/sys/block/'${aDRIVE_SOURCE_DEVICE[$INDEX_INIT_CURRENT_DEVICE]} ]]; then + + aDRIVE_ISNETWORKED[$INDEX_INIT_CURRENT_DEVICE]=1 + aDRIVE_ISFILESYSTEM[$INDEX_INIT_CURRENT_DEVICE]=1 + aDRIVE_FSTYPE[$INDEX_INIT_CURRENT_DEVICE]='Net' + + # - Physical + else + + cmd_scrape_string=$(blkid ${aDRIVE_MOUNT_SOURCE[$INDEX_INIT_CURRENT_DEVICE]} -s TYPE -o value) + if [[ $cmd_scrape_string ]]; then - aDRIVE_APM[$INDEX_INIT_CURRENT_DEVICE]='' + aDRIVE_ISFILESYSTEM[$INDEX_INIT_CURRENT_DEVICE]=1 + aDRIVE_FSTYPE[$INDEX_INIT_CURRENT_DEVICE]=$cmd_scrape_string + + fi fi - fi + G_DIETPI-NOTIFY 2 " - Detected: ${aDRIVE_MOUNT_SOURCE[$INDEX_INIT_CURRENT_DEVICE]} > ${aDRIVE_MOUNT_TARGET[$INDEX_INIT_CURRENT_DEVICE]}" - G_DIETPI-NOTIFY 2 " - Detected: ${aDRIVE_MOUNT_SOURCE[$INDEX_INIT_CURRENT_DEVICE]} > ${aDRIVE_MOUNT_TARGET[$INDEX_INIT_CURRENT_DEVICE]}" + aDRIVE_SIZE_TOTAL[$INDEX_INIT_CURRENT_DEVICE]=$(awk '{print $2}' <<< $line) + aDRIVE_SIZE_USED[$INDEX_INIT_CURRENT_DEVICE]=$(awk '{print $3}' <<< $line) + aDRIVE_SIZE_FREE[$INDEX_INIT_CURRENT_DEVICE]=$(awk '{print $4}' <<< $line) + aDRIVE_SIZE_PERCENTUSED[$INDEX_INIT_CURRENT_DEVICE]=$(awk '{print $5}' <<< $line) - aDRIVE_SIZE_TOTAL[$INDEX_INIT_CURRENT_DEVICE]=$(awk '{print $2}' <<< $line) - aDRIVE_SIZE_USED[$INDEX_INIT_CURRENT_DEVICE]=$(awk '{print $3}' <<< $line) - aDRIVE_SIZE_FREE[$INDEX_INIT_CURRENT_DEVICE]=$(awk '{print $4}' <<< $line) - aDRIVE_SIZE_PERCENTUSED[$INDEX_INIT_CURRENT_DEVICE]=$(awk '{print $5}' <<< $line) + aDRIVE_UUID[$INDEX_INIT_CURRENT_DEVICE]=$(blkid ${aDRIVE_MOUNT_SOURCE[$INDEX_INIT_CURRENT_DEVICE]} -s UUID -o value) + aDRIVE_PART_UUID[$INDEX_INIT_CURRENT_DEVICE]=$(blkid ${aDRIVE_MOUNT_SOURCE[$INDEX_INIT_CURRENT_DEVICE]} -s PARTUUID -o value) - aDRIVE_UUID[$INDEX_INIT_CURRENT_DEVICE]=$(blkid ${aDRIVE_MOUNT_SOURCE[$INDEX_INIT_CURRENT_DEVICE]} -s UUID -o value) - aDRIVE_PART_UUID[$INDEX_INIT_CURRENT_DEVICE]=$(blkid ${aDRIVE_MOUNT_SOURCE[$INDEX_INIT_CURRENT_DEVICE]} -s PARTUUID -o value) + #RO mounted? + #NB: We cant use -m1 for initial check as results can be: + # root@DietPi:~# cat /proc/mounts | grep ' / ' + # rootfs / rootfs rw 0 0 + # /dev/mmcblk0p2 / ext4 ro,noatime,discard,data=ordered 0 0 + if grep -q "[[:blank:]]${aDRIVE_MOUNT_TARGET[$INDEX_INIT_CURRENT_DEVICE]}[[:blank:]].*[[:blank:]]ro," /proc/mounts; then - #RO mounted? - #NB: We cant use -m1 for initial check as results can be: - # root@DietPi:~# cat /proc/mounts | grep ' / ' - # rootfs / rootfs rw 0 0 - # /dev/mmcblk0p2 / ext4 ro,noatime,discard,data=ordered 0 0 - if grep -q "[[:space:]]${aDRIVE_MOUNT_TARGET[$INDEX_INIT_CURRENT_DEVICE]}[[:space:]].*[[:space:]]ro," /proc/mounts; then + aDRIVE_ISREADONLY_CURRENTLY[$INDEX_INIT_CURRENT_DEVICE]=1 - aDRIVE_ISREADONLY_CURRENTLY[$INDEX_INIT_CURRENT_DEVICE]=1 + # - RootFS RW check + if [[ ${aDRIVE_MOUNT_TARGET[$INDEX_INIT_CURRENT_DEVICE]} == '/' ]]; then - # - RootFS RW check - if [[ ${aDRIVE_MOUNT_TARGET[$INDEX_INIT_CURRENT_DEVICE]} == '/' ]]; then + G_DIETPI-NOTIFY 2 "RootFS is currently set to R/O. $G_PROGRAM_NAME requires R/W access." - G_DIETPI-NOTIFY 2 "RootFS is currently set to R/O. $G_PROGRAM_NAME requires R/W access." + G_WHIP_YESNO "RootFS is currently set to 'Read Only'. $G_PROGRAM_NAME requires 'Read Write' access to function.\n\nWould you like to re-enable 'Read Write' access on RootFS?" + if (( $? == 0 )); then - G_WHIP_YESNO "RootFS is currently set to 'Read Only'. $G_PROGRAM_NAME requires 'Read Write' access to function.\n\nWould you like to re-enable 'Read Write' access on RootFS?" - if (( $? == 0 )); then + G_RUN_CMD mount -v -o rw,remount ${aDRIVE_MOUNT_TARGET[$INDEX_INIT_CURRENT_DEVICE]} + G_DIETPI-NOTIFY 0 'RootFS R/W now enabled.' - G_RUN_CMD mount -v -o rw,remount ${aDRIVE_MOUNT_TARGET[$INDEX_INIT_CURRENT_DEVICE]} - G_DIETPI-NOTIFY 0 'RootFS R/W now enabled.' + else - else + /DietPi/dietpi/dietpi-services start - /DietPi/dietpi/dietpi-services start + G_DIETPI-NOTIFY 0 'RootFS currently set to R/O.' + G_DIETPI-NOTIFY 2 'Please run "dietpi-drive_manager" again, if you want to re-enable RootFS R/W.' - G_DIETPI-NOTIFY 0 'RootFS currently set to R/O.' - G_DIETPI-NOTIFY 2 "Please run 'dietpi-drive_manager' again, if you want to re-enable RootFS R/W." + exit - Destroy - exit + fi fi fi - fi + # - Add entry to fstab + if [[ ${aDRIVE_UUID[$INDEX_INIT_CURRENT_DEVICE]} ]]; then - # - Add entry to fstab - if [[ ${aDRIVE_UUID[$INDEX_INIT_CURRENT_DEVICE]} ]]; then + local string_options=',rw' + if (( ${aDRIVE_ISREADONLY_CURRENTLY[$INDEX_INIT_CURRENT_DEVICE]} )); then - local string_options=',rw' - if (( ${aDRIVE_ISREADONLY_CURRENTLY[$INDEX_INIT_CURRENT_DEVICE]} )); then + string_options=',ro' - string_options=',ro' + fi - fi + # - UUID or PARTUUID entry? + local dev_entry="UUID=${aDRIVE_UUID[$INDEX_INIT_CURRENT_DEVICE]}" + if (( $G_HW_MODEL < 10 )) && + [[ ${aDRIVE_MOUNT_TARGET[$INDEX_INIT_CURRENT_DEVICE]} == '/' || ${aDRIVE_MOUNT_TARGET[$INDEX_INIT_CURRENT_DEVICE]} == '/boot' ]]; then - # - UUID or PARTUUID entry? - local dev_entry="UUID=${aDRIVE_UUID[$INDEX_INIT_CURRENT_DEVICE]}" - if (( $G_HW_MODEL < 10 )) && - [[ ${aDRIVE_MOUNT_TARGET[$INDEX_INIT_CURRENT_DEVICE]} == '/' || ${aDRIVE_MOUNT_TARGET[$INDEX_INIT_CURRENT_DEVICE]} == '/boot' ]]; then + dev_entry="PARTUUID=${aDRIVE_PART_UUID[$INDEX_INIT_CURRENT_DEVICE]}" - dev_entry="PARTUUID=${aDRIVE_PART_UUID[$INDEX_INIT_CURRENT_DEVICE]}" + fi - fi + # - Non-RootFS flags + # fsck flag for root device, to allow check on reboot + # x-systemd.automount: [ 1166.110202] systemd-fstab-generator[3512]: Ignoring automount option for root device + local fsck_flag=1 + if [[ ${aDRIVE_MOUNT_TARGET[$INDEX_INIT_CURRENT_DEVICE]} != '/' ]]; then - # - Non-RootFS flags - # fsck flag for root device, to allow check on reboot - # x-systemd.automount: [ 1166.110202] systemd-fstab-generator[3512]: Ignoring automount option for root device - local fsck_flag=1 - if [[ ${aDRIVE_MOUNT_TARGET[$INDEX_INIT_CURRENT_DEVICE]} != '/' ]]; then + string_options+=',nofail,x-systemd.automount' + fsck_flag=0 - string_options+=',nofail,x-systemd.automount' - fsck_flag=0 + fi - fi + echo "$dev_entry ${aDRIVE_MOUNT_TARGET[$INDEX_INIT_CURRENT_DEVICE]} auto defaults,noatime$string_options 0 $fsck_flag" >> $FP_TEMP_FSTAB - cat << _EOF_ >> $FP_TEMP_FSTAB -$dev_entry ${aDRIVE_MOUNT_TARGET[$INDEX_INIT_CURRENT_DEVICE]} auto defaults,noatime$string_options 0 $fsck_flag -_EOF_ + fi fi done < .dietpi-drive_manager_df_tmp - rm .dietpi-drive_manager_df_tmp &> /dev/null + rm .dietpi-drive_manager_df_tmp #Check blkid for unmounted drives, if drive is not mounted, add entry as disabled mount G_DIETPI-NOTIFY 0 'Detecting unmounted drives, please wait...' @@ -340,9 +348,9 @@ _EOF_ while read line do - if [[ -z $line ]]; then + if [[ ! $line ]]; then - break + continue fi @@ -381,22 +389,26 @@ _EOF_ fi - cat << _EOF_ >> $FP_TEMP_FSTAB -#UUID=${aDRIVE_UUID[$INDEX_INIT_CURRENT_DEVICE]} ${aDRIVE_MOUNT_TARGET[$INDEX_INIT_CURRENT_DEVICE]} auto defaults,x-systemd.automount,noatime,rw,nofail 0 0 -_EOF_ + echo "#UUID=${aDRIVE_UUID[$INDEX_INIT_CURRENT_DEVICE]} ${aDRIVE_MOUNT_TARGET[$INDEX_INIT_CURRENT_DEVICE]} auto defaults,x-systemd.automount,noatime,rw,nofail 0 0" >> $FP_TEMP_FSTAB fi done done < .dietpi-drive_manager_blkid_tmp - rm .dietpi-drive_manager_blkid_tmp &> /dev/null + rm .dietpi-drive_manager_blkid_tmp #Find drives that have no partitions lsblk -nro NAME > .dietpi-drive_manager_lsblk_tmp while read line do + if [[ ! $line ]]; then + + continue + + fi + local found=1 # - Exclude drives already found @@ -425,7 +437,7 @@ _EOF_ fi done < .dietpi-drive_manager_lsblk_tmp - rm .dietpi-drive_manager_lsblk_tmp &> /dev/null + rm .dietpi-drive_manager_lsblk_tmp #Set required global flags, for all drives found for ((i=0; i<${#aDRIVE_MOUNT_SOURCE[@]}; i++)) @@ -451,8 +463,6 @@ _EOF_ done - - #DEBUG if (( $DEBUG )); then G_DIETPI-NOTIFY 0 'DEBUG INFO:' @@ -466,7 +476,6 @@ aDRIVE_MOUNT_SOURCE ${aDRIVE_MOUNT_SOURCE[$i]} aDRIVE_MOUNT_TARGET ${aDRIVE_MOUNT_TARGET[$i]} aDRIVE_SOURCE_DEVICE ${aDRIVE_SOURCE_DEVICE[$i]} aDRIVE_FSTYPE ${aDRIVE_FSTYPE[$i]} -aDRIVE_APM ${aDRIVE_APM[$i]} aDRIVE_SIZE_TOTAL ${aDRIVE_SIZE_TOTAL[$i]} aDRIVE_SIZE_USED ${aDRIVE_SIZE_USED[$i]} aDRIVE_SIZE_PERCENTUSED ${aDRIVE_SIZE_PERCENTUSED[$i]} @@ -481,7 +490,6 @@ aDRIVE_ISPARTITIONTABLE ${aDRIVE_ISPARTITIONTABLE[$i]} done - Destroy exit fi @@ -512,7 +520,7 @@ aDRIVE_ISPARTITIONTABLE ${aDRIVE_ISPARTITIONTABLE[$i]} fi - cp $FP_TEMP_FSTAB /etc/fstab + cp -a $FP_TEMP_FSTAB /etc/fstab systemctl daemon-reload rm $FP_TEMP_FSTAB @@ -532,7 +540,7 @@ aDRIVE_ISPARTITIONTABLE ${aDRIVE_ISPARTITIONTABLE[$i]} Rm_Empty_Dir(){ local fp_dir="$1" - if [[ -d $fp_dir && -z $(ls -A $fp_dir) ]]; then + if [[ -d $fp_dir && ! $(ls -A $fp_dir) ]]; then rm -R "$fp_dir" G_DIETPI-NOTIFY 2 "Removed empty directory: $fp_dir" @@ -548,15 +556,15 @@ aDRIVE_ISPARTITIONTABLE ${aDRIVE_ISPARTITIONTABLE[$i]} Return_Drive_Without_Partitions(){ #$1 = dev source - if [[ $1 == '/dev/sd'* || $1 == '/dev/hd'* ]]; then + local drive=${1#/dev/} + if [[ $drive == [sh]d* ]]; then - echo $1 | sed 's/[0-9]$//' | sed 's/\/dev\///' + echo ${drive%[0-9]} #mmc/NVMe else - echo $1 | sed 's/[pn][0-9]$//' | sed 's/\/dev\///' - #NVMe# echo $1 | sed 's/n[0-9]$//' | sed 's/\/dev\///' + echo ${drive%[pn][0-9]} fi @@ -567,6 +575,7 @@ aDRIVE_ISPARTITIONTABLE ${aDRIVE_ISPARTITIONTABLE[$i]} local source=$1 local target=$2 + local apply_mount=1 G_WHIP_DEFAULT_ITEM=$target G_WHIP_INPUTBOX "Please enter the target path, this device will mount to.\n - Default and recommended = $target\n\nNB: The path must start with /mnt/ and be unique. Spaces will be converted automatically to underscores (_)." @@ -575,7 +584,7 @@ aDRIVE_ISPARTITIONTABLE ${aDRIVE_ISPARTITIONTABLE[$i]} if [[ $G_WHIP_RETURNED_VALUE == '/mnt/'* ]]; then # - replace spaces with underscores - target=$(sed 's/[[:space:]]/_/g' <<< "$G_WHIP_RETURNED_VALUE") + target="${G_WHIP_RETURNED_VALUE//[[:space:]]/_}" else @@ -587,13 +596,29 @@ aDRIVE_ISPARTITIONTABLE ${aDRIVE_ISPARTITIONTABLE[$i]} if [[ -d $target ]]; then - G_WHIP_MSG "Error:\n\nThe mount target directory, already exists and may be in use:\n - $target\n\nPlease retry, using a unique mount target location." + if [[ $(ls -A $target) ]]; then - else + G_WHIP_MSG "Error:\n\nThe mount target directory already exists, and, contains data:\n - $target\n\nPlease retry, using a unique mount target location." + apply_mount=0 + + else + + G_WHIP_YESNO "Warning:\n\nThe mount target directory already exists, however, it does not contain any files or data at this time:\n - $target\n\nDo you wish to ignore this warning, and, mount the drive regardless?" + if (( $? != 0 )); then + + apply_mount=0 + + fi + + fi + + fi + + if (( $apply_mount )); then G_DIETPI-NOTIFY 2 "Creating mount folder for $target" mkdir -p $target - G_RUN_CMD_INFO_ONLY=1 G_RUN_CMD mount $source $target + G_ERROR_HANDLER_INFO_ONLY=1 G_RUN_CMD mount $source $target DRIVE_TARGET_BEING_EDITED="$target" fi @@ -605,7 +630,7 @@ aDRIVE_ISPARTITIONTABLE ${aDRIVE_ISPARTITIONTABLE[$i]} local target=$1 - G_RUN_CMD_INFO_ONLY=1 G_RUN_CMD umount $target + G_ERROR_HANDLER_INFO_ONLY=1 G_RUN_CMD umount $target if (( $? == 0 )); then sed -i "\#[[:space:]]$target[[:space:]]#d" /etc/fstab #Only needed for networked drives currently... @@ -631,7 +656,7 @@ aDRIVE_ISPARTITIONTABLE ${aDRIVE_ISPARTITIONTABLE[$i]} else - G_RUN_CMD_INFO_ONLY=1 G_RUN_CMD resize2fs ${aDRIVE_MOUNT_SOURCE[$INDEX_DRIVE_BEING_EDITED]} + G_ERROR_HANDLER_INFO_ONLY=1 G_RUN_CMD resize2fs ${aDRIVE_MOUNT_SOURCE[$INDEX_DRIVE_BEING_EDITED]} fi @@ -806,7 +831,7 @@ aDRIVE_ISPARTITIONTABLE ${aDRIVE_ISPARTITIONTABLE[$i]} G_AG_CHECK_INSTALL_PREREQ rsync #Remove previous fstab entry and mount location - cp /etc/fstab /etc/fstab.bak #incase of Rsync fail + cp -a /etc/fstab /etc/fstab.bak #incase of Rsync fail # Remove automatic entry for new uuid sed -i "\@[[:space:]]${aDRIVE_MOUNT_TARGET[$INDEX_DRIVE_BEING_EDITED]}[[:space:]]@d" /etc/fstab @@ -828,9 +853,8 @@ aDRIVE_ISPARTITIONTABLE ${aDRIVE_ISPARTITIONTABLE[$i]} G_DIETPI-NOTIFY 1 'Rsync has failed, RootFS transfer has been aborted.' # revert FSTAB changes - cp /etc/fstab.bak /etc/fstab + cp -a /etc/fstab.bak /etc/fstab - Destroy exit fi @@ -868,9 +892,9 @@ aDRIVE_ISPARTITIONTABLE ${aDRIVE_ISPARTITIONTABLE[$i]} fi systemctl daemon-reload + sync G_WHIP_MSG 'RootFS transfer completed. Press enter to reboot system.' - reboot } @@ -995,7 +1019,13 @@ aDRIVE_ISPARTITIONTABLE ${aDRIVE_ISPARTITIONTABLE[$i]} unset acategory_list - G_WHIP_MENU_ARRAY+=('' '●─') + G_WHIP_MENU_ARRAY+=('' '●─ Global Options') + + G_WHIP_MENU_ARRAY+=('Idle Spindown' ': Set a global idle duration, before drives power down') + + G_WHIP_MENU_ARRAY+=('' '●─ Add / Refresh Drives') + + G_WHIP_MENU_ARRAY+=('Add network drive' ': Select to mount networked drives') if (( ! $drive_available )); then @@ -1007,8 +1037,6 @@ aDRIVE_ISPARTITIONTABLE ${aDRIVE_ISPARTITIONTABLE[$i]} fi - G_WHIP_MENU_ARRAY+=('Add network drive' ': Select to mount networked drives') - # - User data local userdata_location_text="RootFS ($FP_USERDATA_CURRENT)" if [[ $FP_USERDATA_CURRENT != $G_FP_DIETPI_USERDATA ]]; then @@ -1034,6 +1062,56 @@ aDRIVE_ISPARTITIONTABLE ${aDRIVE_ISPARTITIONTABLE[$i]} TARGETMENUID=3 + elif [[ $G_WHIP_RETURNED_VALUE == 'Idle Spindown' ]]; then + + local apm=127 + + G_WHIP_MENU_ARRAY=('0' ': Disabled') + + local time_info=0 + for (( i=1; i<=240; i++ )) + do + + time_info=$(( $i * 5 )) + + G_WHIP_MENU_ARRAY+=($i ": $time_info Seconds") + + done + + for (( i=241; i<=251; i++ )) + do + + time_info=$(( ( $i - 240 ) * 30 )) + + G_WHIP_MENU_ARRAY+=($i ": $time_info Minutes") + + done + + G_WHIP_DEFAULT_ITEM=241 + G_WHIP_MENU "Please select a idle duration of time, before each drive is powered down:\n - This will be applied to all drives on the system\n - Not all drives support the feature of 'hdparm' and visa versa. End results may vary\n - You can check status with 'hdparm -C /dev/sd*'" + if (( $? == 0 )); then + + > /etc/hdparm.conf + for ((i=0; i<${#aDRIVE_MOUNT_SOURCE[@]}; i++)) + do + + if (( ! ${aDRIVE_ISNETWORKED[$i]} )) && ! grep -q "^/dev/${aDRIVE_SOURCE_DEVICE[$i]}$" /etc/hdparm.conf; then + + G_ERROR_HANDLER_NO_FAIL=1 G_RUN_CMD hdparm -B $apm /dev/${aDRIVE_SOURCE_DEVICE[$i]} + G_ERROR_HANDLER_NO_FAIL=1 G_RUN_CMD hdparm -S $G_WHIP_RETURNED_VALUE /dev/${aDRIVE_SOURCE_DEVICE[$i]} + + echo "/dev/${aDRIVE_SOURCE_DEVICE[$i]} +{ + apm = $apm + spindown_time = $G_WHIP_RETURNED_VALUE +}" >> /etc/hdparm.conf + + fi + + done + + fi + # - Edit drive elif [[ $G_WHIP_RETURNED_VALUE ]]; then @@ -1161,8 +1239,8 @@ aDRIVE_ISPARTITIONTABLE ${aDRIVE_ISPARTITIONTABLE[$i]} # - Swapfile # NB: / rootfs will always be detected in this check, however, no rootFS options for umount and format... - local swapfile_location="$(grep -m1 '^[[:blank:]]*AUTO_SETUP_SWAPFILE_LOCATION=' /DietPi/dietpi.txt | sed 's/.*=//')" - local swapfile_size=$(grep -m1 '^[[:blank:]]*AUTO_SETUP_SWAPFILE_SIZE=' /DietPi/dietpi.txt | sed 's/.*=//') + local swapfile_location="$(grep -m1 '^[[:blank:]]*AUTO_SETUP_SWAPFILE_LOCATION=' /DietPi/dietpi.txt | sed 's/^[^=]*=//')" + local swapfile_size=$(grep -m1 '^[[:blank:]]*AUTO_SETUP_SWAPFILE_SIZE=' /DietPi/dietpi.txt | sed 's/^[^=]*=//') if [[ $swapfile_location == ${aDRIVE_MOUNT_TARGET[$INDEX_DRIVE_BEING_EDITED]}* && ${aDRIVE_MOUNT_TARGET[$INDEX_DRIVE_BEING_EDITED]} != '/' ]] || [[ $swapfile_location == '/var/swap' && ${aDRIVE_MOUNT_TARGET[$INDEX_DRIVE_BEING_EDITED]} == '/' ]]; then @@ -1183,12 +1261,6 @@ aDRIVE_ISPARTITIONTABLE ${aDRIVE_ISPARTITIONTABLE[$i]} G_WHIP_MENU_ARRAY+=('' '●─ Advanced options ') - if [[ ${aDRIVE_APM[$INDEX_DRIVE_BEING_EDITED]} ]]; then - - G_WHIP_MENU_ARRAY+=('Power saving' ": [APM:${aDRIVE_APM[$INDEX_DRIVE_BEING_EDITED]}] | Select to change") - - fi - # - Read only? local read_only_state='[X]' local read_only_state_text='Enabled' @@ -1459,21 +1531,6 @@ aDRIVE_ISPARTITIONTABLE ${aDRIVE_ISPARTITIONTABLE[$i]} fi - elif [[ $G_WHIP_RETURNED_VALUE == 'Power saving' ]]; then - - local min=0 - local max=254 - G_WHIP_INPUTBOX "Please enter an APM value (between $min-$max):" - if (( $? == 0 )); then - - if G_CHECK_VALIDINT $G_WHIP_RETURNED_VALUE $min $max; then - - echo 1 - - fi - - fi - elif [[ $G_WHIP_RETURNED_VALUE == 'Read Only' ]]; then # - Disallow if userdata is located on this drive! @@ -1489,7 +1546,7 @@ aDRIVE_ISPARTITIONTABLE ${aDRIVE_ISPARTITIONTABLE[$i]} elif [[ $G_WHIP_RETURNED_VALUE == 'Benchmark' ]]; then - /DietPi/dietpi/func/dietpi-benchmark 0 "${aDRIVE_MOUNT_TARGET[$INDEX_DRIVE_BEING_EDITED]}" + FSBENCH_FP="${aDRIVE_MOUNT_TARGET[$INDEX_DRIVE_BEING_EDITED]}" /DietPi/dietpi/func/dietpi-benchmark 0 elif [[ $G_WHIP_RETURNED_VALUE == 'Check & Repair' ]]; then @@ -1779,7 +1836,7 @@ NB: fi # NB: Convert spaces into '\040': https://github.com/Fourdee/DietPi/issues/1201#issuecomment-339720271 - samba_clientshare=$(sed 's/ /\\\\040/g' <<< "$G_WHIP_RETURNED_VALUE") + samba_clientshare="${G_WHIP_RETURNED_VALUE//[[:space:]]/\\\\040}" G_WHIP_DEFAULT_ITEM="$samba_clientuser" G_WHIP_INPUTBOX 'Please enter the fileservers username\n - eg: JoeBloggs' @@ -1802,7 +1859,7 @@ NB: break fi - samba_fp_mount_target="/mnt/$(sed 's/\///g' <<< $G_WHIP_RETURNED_VALUE | sed 's/[[:space:]]/_/g')" + samba_fp_mount_target="/mnt/${G_WHIP_RETURNED_VALUE//[[:space:]]/_}" # - Unmount if connected umount /mnt/$samba_fp_mount_target &> /dev/null @@ -1831,9 +1888,7 @@ NB: # - Apply to fstab sed -i "\#[[:space:]]$samba_fp_mount_target[[:space:]]#d" /etc/fstab - cat << _EOF_ >> /etc/fstab -//$samba_clientname/$samba_clientshare $samba_fp_mount_target cifs username=$samba_clientuser,password=$samba_clientpassword,iocharset=utf8,vers=${acifs_versions[$i]},_netdev,nofail 0 0 -_EOF_ + echo "//$samba_clientname/$samba_clientshare $samba_fp_mount_target cifs username=$samba_clientuser,password=$samba_clientpassword,iocharset=utf8,vers=${acifs_versions[$i]},_netdev,nofail 0 0" >> /etc/fstab DRIVE_TARGET_BEING_EDITED="$samba_fp_mount_target" TARGETMENUID=1 @@ -1847,7 +1902,7 @@ _EOF_ if (( $i == ( ${#acifs_versions[@]} - 1 ) )); then # - Run mount again, allow user to see error - G_RUN_CMD_INFO_ONLY=1 G_RUN_CMD mount -t cifs -o username="$samba_clientuser",password="$samba_clientpassword",vers=${acifs_versions[$i]} //"$samba_clientname"/"$samba_clientshare" "$samba_fp_mount_target" + G_ERROR_HANDLER_INFO_ONLY=1 G_RUN_CMD mount -t cifs -o username="$samba_clientuser",password="$samba_clientpassword",vers=${acifs_versions[$i]} //"$samba_clientname"/"$samba_clientshare" "$samba_fp_mount_target" Rm_Empty_Dir "$samba_fp_mount_target" break @@ -1916,9 +1971,7 @@ _EOF_ #Apply to fstab sed -i "\#[[:space:]]$nfs_fp_mount_target[[:space:]]#d" /etc/fstab - cat << _EOF_ >> /etc/fstab -$nfs_server_ip:/ $nfs_fp_mount_target nfs auto,_netdev,nofail 0 0 -_EOF_ + echo "$nfs_server_ip:/ $nfs_fp_mount_target nfs auto,_netdev,nofail 0 0" >> /etc/fstab DRIVE_TARGET_BEING_EDITED="$nfs_fp_mount_target" TARGETMENUID=1 @@ -1947,9 +2000,7 @@ _EOF_ #Apply to fstab sed -i "\#[[:space:]]$nfs_fp_mount_target[[:space:]]#d" /etc/fstab - cat << _EOF_ >> /etc/fstab -$nfs_server_ip:$nfs_fp_server_share $nfs_fp_mount_target nfs auto,_netdev,nofail 0 0 -_EOF_ + echo "$nfs_server_ip:$nfs_fp_server_share $nfs_fp_mount_target nfs auto,_netdev,nofail 0 0" >> /etc/fstab DRIVE_TARGET_BEING_EDITED="$nfs_fp_mount_target" TARGETMENUID=1 @@ -2024,7 +2075,7 @@ $(<$fp_tmp)" while read line do - G_WHIP_MENU_ARRAY+=("$(echo -e $line | awk '{print $6}')" ": $(echo -e $line | awk '{print $1}') | size: $(echo -e $line | awk '{print $2}') | available: $(echo -e $line | awk '{print $4}')") + G_WHIP_MENU_ARRAY+=("$(awk '{print $6}' <<< $line)" ": $(awk '{print $1}' <<< $line) | size: $(awk '{print $2}' <<< $line) | available: $(awk '{print $4}' <<< $line)") done < dietpi-drive_manager_selmnt rm dietpi-drive_manager_selmnt @@ -2036,7 +2087,7 @@ $(<$fp_tmp)" local drive_manager_selection="$G_WHIP_RETURNED_VALUE" G_DIETPI-NOTIFY 0 "Drive mount selected: $drive_manager_selection" - echo -e "$drive_manager_selection" > "$FP_DRIVE_MANAGER_SELECTION" + echo "$drive_manager_selection" > "$FP_DRIVE_MANAGER_SELECTION" fi diff --git a/dietpi/dietpi-explorer b/dietpi/dietpi-explorer index 3f1dab839c..936b0d031f 100644 --- a/dietpi/dietpi-explorer +++ b/dietpi/dietpi-explorer @@ -12,7 +12,8 @@ # - filename /DietPi/dietpi/dietpi-explorer # # Usage: - # - dietpi-explorer (menu system) + # - dietpi-explorer (menu system) + # - dietpi-explorer 1 | Select a folder mode, return result for other applications to /tmp/.dietpi-explorer_selected_location #//////////////////////////////////// #Import DietPi-Globals --------------------------------------------------------------- @@ -22,6 +23,13 @@ G_INIT #Import DietPi-Globals --------------------------------------------------------------- + INPUT=0 + if disable_error=1 G_CHECK_VALIDINT $1; then + + INPUT=$1 + + fi + CURRENT_DIRECTORY='' TARGET_FP='' @@ -35,11 +43,11 @@ if (( $CP_MODE == 0 )); then - G_RUN_CMD_INFO_ONLY=1 G_RUN_CMD cp -R "$CP_SOURCE" "$CP_TARGET"/ + G_ERROR_HANDLER_INFO_ONLY=1 G_RUN_CMD cp -R "$CP_SOURCE" "$CP_TARGET"/ elif (( $CP_MODE == 1 )); then - G_RUN_CMD_INFO_ONLY=1 G_RUN_CMD mv "$CP_SOURCE" "$CP_TARGET"/ + G_ERROR_HANDLER_INFO_ONLY=1 G_RUN_CMD mv "$CP_SOURCE" "$CP_TARGET"/ fi @@ -74,30 +82,38 @@ fi - G_WHIP_MENU_ARRAY+=('' '●─ IO operations ') - G_WHIP_MENU_ARRAY+=('Rename' '') - G_WHIP_MENU_ARRAY+=('Copy' '') - G_WHIP_MENU_ARRAY+=('Move' '') + if (( $INPUT == 1 )); then + + G_WHIP_MENU_ARRAY+=('Select' " : Use '$CURRENT_DIRECTORY/$TARGET_FP'") + + else + + G_WHIP_MENU_ARRAY+=('' '●─ IO operations ') + G_WHIP_MENU_ARRAY+=('Rename' '') + G_WHIP_MENU_ARRAY+=('Copy' '') + G_WHIP_MENU_ARRAY+=('Move' '') - if [[ -n $CP_SOURCE && -d $CURRENT_DIRECTORY/$TARGET_FP && $CP_SOURCE != $CURRENT_DIRECTORY/$TARGET_FP ]]; then + if [[ -n $CP_SOURCE && -d $CURRENT_DIRECTORY/$TARGET_FP && $CP_SOURCE != $CURRENT_DIRECTORY/$TARGET_FP ]]; then - if (( $CP_MODE == 0 )); then + if (( $CP_MODE == 0 )); then - G_WHIP_MENU_ARRAY+=('Paste' " : Copy $CP_SOURCE to $CURRENT_DIRECTORY/$TARGET_FP/") + G_WHIP_MENU_ARRAY+=('Paste' " : Copy $CP_SOURCE to $CURRENT_DIRECTORY/$TARGET_FP/") - elif (( $CP_MODE == 1 )); then + elif (( $CP_MODE == 1 )); then - G_WHIP_MENU_ARRAY+=('Paste' " : Move $CP_SOURCE to $CURRENT_DIRECTORY/$TARGET_FP/") + G_WHIP_MENU_ARRAY+=('Paste' " : Move $CP_SOURCE to $CURRENT_DIRECTORY/$TARGET_FP/") + + fi fi - fi + G_WHIP_MENU_ARRAY+=('Delete' '') - G_WHIP_MENU_ARRAY+=('Delete' '') + G_WHIP_MENU_ARRAY+=('' '●─ Permissions ') + G_WHIP_MENU_ARRAY+=('Chown' ' : Set user and group permissions') + G_WHIP_MENU_ARRAY+=('Chmod' ' : Set read/write/exec permissions') - G_WHIP_MENU_ARRAY+=('' '●─ Permissions ') - G_WHIP_MENU_ARRAY+=('Chown' ' : Set user and group permissions') - G_WHIP_MENU_ARRAY+=('Chmod' ' : Set read/write/exec permissions') + fi G_WHIP_DEFAULT_ITEM='Open' @@ -139,6 +155,11 @@ fi + elif [[ $G_WHIP_RETURNED_VALUE == 'Select' ]]; then + + echo -e "$CURRENT_DIRECTORY/$TARGET_FP" > /tmp/.dietpi-explorer_selected_location + exit 0 + elif [[ $G_WHIP_RETURNED_VALUE == 'Copy' ]]; then CP_SOURCE="$CURRENT_DIRECTORY/$TARGET_FP" @@ -160,7 +181,7 @@ G_WHIP_INPUTBOX "Please enter a new name for '$TARGET_FP'" if (( $? == 0 )); then - G_RUN_CMD_INFO_ONLY=1 G_RUN_CMD mv "$TARGET_FP" "$G_WHIP_RETURNED_VALUE" + G_ERROR_HANDLER_INFO_ONLY=1 G_RUN_CMD mv "$TARGET_FP" "$G_WHIP_RETURNED_VALUE" fi @@ -169,7 +190,7 @@ G_WHIP_YESNO "Delete $CURRENT_DIRECTORY/$TARGET_FP?" if (( $? == 0 )); then - G_RUN_CMD_INFO_ONLY=1 G_RUN_CMD rm -R "$CURRENT_DIRECTORY/$TARGET_FP" + G_ERROR_HANDLER_INFO_ONLY=1 G_RUN_CMD rm -R "$CURRENT_DIRECTORY/$TARGET_FP" fi @@ -177,14 +198,12 @@ G_WHIP_MENU_ARRAY=() - getent passwd | cut -d: -f1 | sort > /tmp/dietpi-explorer.users while read line do G_WHIP_MENU_ARRAY+=( "$line" '' ) - done < /tmp/dietpi-explorer.users - rm /tmp/dietpi-explorer.users + done <<< "$(getent passwd | cut -d: -f1 | sort)" G_WHIP_DEFAULT_ITEM="$permission_current_user" G_WHIP_MENU 'Chown permissions:\n - Please select a User' @@ -194,21 +213,19 @@ G_WHIP_MENU_ARRAY=() - getent group | cut -d: -f1 | sort > /tmp/dietpi-explorer.groups while read line do G_WHIP_MENU_ARRAY+=( "$line" '' ) - done < /tmp/dietpi-explorer.groups - rm /tmp/dietpi-explorer.groups + done <<< "$(getent group | cut -d: -f1 | sort)" G_WHIP_DEFAULT_ITEM="$permission_current_group" G_WHIP_MENU 'Chown permissions:\n - Please select a Group' if (( $? == 0 )); then local chown_group="$G_WHIP_RETURNED_VALUE" - G_RUN_CMD_INFO_ONLY=1 G_RUN_CMD chown -R $chown_user:$chown_group "$CURRENT_DIRECTORY/$TARGET_FP" + G_ERROR_HANDLER_INFO_ONLY=1 G_RUN_CMD chown -R $chown_user:$chown_group "$CURRENT_DIRECTORY/$TARGET_FP" fi @@ -220,7 +237,7 @@ G_WHIP_INPUTBOX 'Chmod permissions:\n - Please enter a value' if (( $? == 0 )); then - G_RUN_CMD_INFO_ONLY=1 G_RUN_CMD chmod -R $G_WHIP_RETURNED_VALUE "$CURRENT_DIRECTORY/$TARGET_FP" + G_ERROR_HANDLER_INFO_ONLY=1 G_RUN_CMD chmod -R $G_WHIP_RETURNED_VALUE "$CURRENT_DIRECTORY/$TARGET_FP" fi @@ -330,6 +347,6 @@ done #----------------------------------------------------------------------------------- - exit + exit 0 #----------------------------------------------------------------------------------- } diff --git a/dietpi/dietpi-process_tool b/dietpi/dietpi-process_tool index 4b93357e32..d40422dd50 100644 --- a/dietpi/dietpi-process_tool +++ b/dietpi/dietpi-process_tool @@ -55,9 +55,6 @@ # G_DIETPI-NOTIFY 0/OK or 1/FAILURE local notify_type=0 - #Update process list again (incase of PID changes via forking processes, during init of this script) - ps ax > $FP_PS_LIST - # - Control verbosity of output local print_info=0 if (( $HIERARCHY <= 1 )); then @@ -72,8 +69,7 @@ if (( ${aAVAILABLE[$i]} )); then # - Find all processes with target name, send PID to $FP_TEMP for later use - grep "${aPROCESS_NAME[$i]}" $FP_PS_LIST | awk '{print $1}' > $FP_TEMP - while read -r line + while read line do #Obtain PID @@ -185,9 +181,7 @@ fi - done < $FP_TEMP - - rm $FP_TEMP + done <<< "$(pgrep -f ${aPROCESS_NAME[$i]})" fi @@ -247,7 +241,6 @@ aNAME[$index]='Jconvolver';aPROCESS_NAME[$index]='jconvolver';((index++)) aNAME[$index]='Minio';aPROCESS_NAME[$index]='minio';((index++)) aNAME[$index]='MiniDLNA';aPROCESS_NAME[$index]='minidlna';((index++)) - #aNAME[$index]='moOde (worker.php)';aPROCESS_NAME[$index]='worker.php';((index++)) aNAME[$index]='Mopidy';aPROCESS_NAME[$index]='mopidy';((index++)) aNAME[$index]='Mosquitto';aPROCESS_NAME[$index]='mosquitto';((index++)) aNAME[$index]='MotionEye';aPROCESS_NAME[$index]='motioneye';((index++)) @@ -261,7 +254,7 @@ aNAME[$index]='NoIp';aPROCESS_NAME[$index]='noip2';((index++)) aNAME[$index]='NZBget';aPROCESS_NAME[$index]='nzbget';((index++)) aNAME[$index]='OctoPrint';aPROCESS_NAME[$index]='octoprint';((index++)) - aNAME[$index]='OpenBazaar';aPROCESS_NAME[$index]='openbazaard.py';((index++)) + aNAME[$index]='OpenBazaar';aPROCESS_NAME[$index]='openbazaard.go';((index++)) aNAME[$index]='Open Media Vault';aPROCESS_NAME[$index]='omv-engined';((index++)) aNAME[$index]='OpenSSH Server';aPROCESS_NAME[$index]='sshd';((index++)) aNAME[$index]='OpenVPN Server';aPROCESS_NAME[$index]='openvpn';((index++)) diff --git a/dietpi/dietpi-services b/dietpi/dietpi-services index d6636aef7d..47c44a909a 100644 --- a/dietpi/dietpi-services +++ b/dietpi/dietpi-services @@ -105,6 +105,7 @@ #Frontends / Misc ------------------------------------------------------ # - Media 'ympd' + 'mympd' 'squeezeboxserver' 'subsonic' 'airsonic' @@ -214,6 +215,7 @@ aSERVICE_NAME+=('amiberry') #: DietPi AmiBerry run service # - DietPi + aSERVICE_NAME+=('dietpi-preboot') aSERVICE_NAME+=('dietpi-boot') aSERVICE_NAME+=('dietpi-postboot') aSERVICE_NAME+=('dietpi-wifi-monitor') #: https://github.com/Fourdee/DietPi/issues/1288#issuecomment-350653480 @@ -301,7 +303,9 @@ if [[ -n ${aSERVICE_NAME[$i]} ]]; then - if [[ -f /etc/systemd/system/${aSERVICE_NAME[$i]}.service || -f /lib/systemd/system/${aSERVICE_NAME[$i]}.service ]]; then + if [[ -f /etc/systemd/system/${aSERVICE_NAME[$i]}.service || + -f /lib/systemd/system/${aSERVICE_NAME[$i]}.service || + -f /usr/lib/systemd/system/${aSERVICE_NAME[$i]}.service ]]; then aSERVICE_AVAILABLE[$i]=1 diff --git a/dietpi/dietpi-software b/dietpi/dietpi-software index ee83817455..afabdafe32 100644 --- a/dietpi/dietpi-software +++ b/dietpi/dietpi-software @@ -185,7 +185,7 @@ _EOF_ #Internet # - Use /etc/apt/sources.list for connection test local internet_url_test="$(grep -m1 '^[[:blank:]]*deb ' /etc/apt/sources.list | awk '{print $2}')" - G_CHECK_URL "$internet_url_test" #will exit on failure here then prompt user to configure network + optional_cmd_inputs='--no-check-certificate' G_CHECK_URL "$internet_url_test" #will exit on failure here then prompt user to configure network #NTPD while true @@ -719,6 +719,17 @@ _EOF_ aSOFTWARE_REQUIRES_ALSA[$index_current]=1 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5#p50' + #------------------ + index_current=148 + + aSOFTWARE_WHIP_NAME[$index_current]='myMPD' + aSOFTWARE_WHIP_DESC[$index_current]='fork of ympd with improved features' + aSOFTWARE_CATEGORY_INDEX[$index_current]=2 + aSOFTWARE_TYPE[$index_current]=0 + aSOFTWARE_REQUIRES_ALSA[$index_current]=1 + aSOFTWARE_REQUIRES_BUILDESSENTIAL[$index_current]=1 + aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=13978#p13978' + #------------------ index_current=119 @@ -812,15 +823,11 @@ _EOF_ aSOFTWARE_WHIP_DESC[$index_current]='web interface media streaming server' aSOFTWARE_CATEGORY_INDEX[$index_current]=2 aSOFTWARE_TYPE[$index_current]=0 - aSOFTWARE_REQUIRES_FFMPEG[$index_current]=1 aSOFTWARE_ONLINEDOC_URL[$index_current]='f=8&t=5&p=1789#p1789' - #disable ARMv6: https://github.com/Fourdee/DietPi/issues/534 + # - Disabled for ARM6: https://github.com/Fourdee/DietPi/issues/534#issuecomment-416405968 aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,1]=0 - #disable ARMv8: https://github.com/Fourdee/DietPi/issues/1059#issuecomment-313661959 - aSOFTWARE_AVAIL_G_HW_ARCH[$index_current,3]=0 - #------------------ index_current=42 @@ -2632,27 +2639,6 @@ _EOF_ fi - #Additional Software required by moOde - if (( ${aSOFTWARE_INSTALL_STATE[168]} == 1 )); then - - #aSOFTWARE_INSTALL_STATE[36]=1 # Squeezelite # Disabled/optional - #aSOFTWARE_INSTALL_STATE[37]=1 # Shairport Sync # Disabled/optional - #aSOFTWARE_INSTALL_STATE[60]=1 # WiFi Hotspot # Installed as per moOde docs - - G_DIETPI-NOTIFY 2 "${aSOFTWARE_WHIP_NAME[128]} will be installed" - aSOFTWARE_INSTALL_STATE[128]=1 # MPD - - G_DIETPI-NOTIFY 2 "${aSOFTWARE_WHIP_NAME[78]} will be installed" - aSOFTWARE_INSTALL_STATE[78]=1 # LESP, override user choice for now. - - G_DIETPI-NOTIFY 2 "${aSOFTWARE_WHIP_NAME[1]} will be installed" - aSOFTWARE_INSTALL_STATE[1]=1 # Samba Client - - G_DIETPI-NOTIFY 2 "${aSOFTWARE_WHIP_NAME[96]} will be installed" - aSOFTWARE_INSTALL_STATE[96]=1 # Samba Server - - fi - #Additional Software required by Google AIY if (( ${aSOFTWARE_INSTALL_STATE[169]} == 1 )); then @@ -2694,8 +2680,7 @@ _EOF_ #Software that requires Mono index=150 - if (( ${aSOFTWARE_INSTALL_STATE[41]} == 1 || - ${aSOFTWARE_INSTALL_STATE[106]} == 1 || + if (( ${aSOFTWARE_INSTALL_STATE[106]} == 1 || ${aSOFTWARE_INSTALL_STATE[144]} == 1 || ${aSOFTWARE_INSTALL_STATE[145]} == 1 || ${aSOFTWARE_INSTALL_STATE[147]} == 1 )); then @@ -2716,8 +2701,7 @@ _EOF_ #Software that requires Python-Pip: https://github.com/Fourdee/DietPi/issues/784 index=130 - if (( ${aSOFTWARE_INSTALL_STATE[58]} == 1 || - ${aSOFTWARE_INSTALL_STATE[99]} == 1 || + if (( ${aSOFTWARE_INSTALL_STATE[99]} == 1 || ${aSOFTWARE_INSTALL_STATE[118]} == 1 || ${aSOFTWARE_INSTALL_STATE[136]} == 1 || ${aSOFTWARE_INSTALL_STATE[139]} == 1 || @@ -2734,10 +2718,12 @@ _EOF_ # YMPD # Cava # OMPD + # myMPD index=128 if (( ${aSOFTWARE_INSTALL_STATE[32]} == 1 || ${aSOFTWARE_INSTALL_STATE[119]} == 1 || - ${aSOFTWARE_INSTALL_STATE[129]} == 1 )); then + ${aSOFTWARE_INSTALL_STATE[129]} == 1 || + ${aSOFTWARE_INSTALL_STATE[148]} == 1 )); then aSOFTWARE_INSTALL_STATE[$index]=1 G_DIETPI-NOTIFY 2 "${aSOFTWARE_WHIP_NAME[$index]} will be installed" @@ -3338,7 +3324,7 @@ _EOF_ if [[ $type == deb ]]; then # Allow error on first attempt, giving APT fix a change to resolve e.g. dependencies - l_message='Installing deb package' G_USER_INPUTS=0 G_RUN_CMD_INFO_ONLY=1 G_RUN_CMD dpkg -i $file + l_message='Installing deb package' G_USER_INPUTS=0 G_ERROR_HANDLER_INFO_ONLY=1 G_RUN_CMD dpkg -i $file (( $G_ERROR_HANDLER_EXITCODE_RETURN )) && G_DIETPI-NOTIFY 2 'Trying automated APT fix' && G_AGF #(( $G_ERROR_HANDLER_EXITCODE_RETURN )) && error? @@ -3758,6 +3744,10 @@ _EOF_ elif (( ${aSOFTWARE_INSTALL_STATE[84]} == 1 )); then debconf-set-selections <<< 'phpmyadmin phpmyadmin/reconfigure-webserver multiselect lighttpd' + # Workaround an APT error, when installing lighttpd and phpmyadmin in the same session: https://github.com/Fourdee/DietPi/issues/316 + G_ERROR_HANDLER_NO_FAIL=1 G_AGI phpmyadmin + G_WHIP_MSG 'Working around Lighttpd + phpMyAdmin APT errors:\n\nYou may have seen an error during the phpMyAdmin APT installation. This occurs, when Lighttpd webserver was installed within the same session.\n +We work around this error by running APT a second time. Please do not worry and ignore any error or failure message within this install steps. After DietPi-Software finished, Lighttpd should start up and phpMyAdmin web UI should be available as expected.' else @@ -3794,7 +3784,7 @@ _EOF_ #Stretch elif (( $G_DISTRO == 4 )); then - INSTALL_URL_ADDRESS='https://dietpi.com/downloads/binaries/all/mpd_0.20.18-1_' + INSTALL_URL_ADDRESS='https://dietpi.com/downloads/binaries/all/mpd_0.20.21-1_' #armv6 if (( $G_HW_ARCH == 1 )); then @@ -3819,7 +3809,7 @@ _EOF_ apt-mark unhold mpd &> /dev/null #??? Not required for dpkg -i installs - DEPS_LIST='libupnp6 libwrap0 libmpdclient2 libflac8 libyajl2 libavahi-client3 libvorbisfile3 libwavpack1 libmad0 libmpg123-0 libopus0 libavformat57 libfaad2 libcdio-paranoia1 libiso9660-8 libshout3 libid3tag0' + DEPS_LIST='libsqlite3-0 libupnp6 libwrap0 libmpdclient2 libflac8 libyajl2 libavahi-client3 libvorbisfile3 libwavpack1 libmad0 libmpg123-0 libopus0 libavformat57 libfaad2 libcdio-paranoia1 libiso9660-8 libshout3 libid3tag0' Download_Install "$INSTALL_URL_ADDRESS" apt-mark hold mpd # prevent repo updates from overwriting @@ -3850,43 +3840,38 @@ _EOF_ Banner_Installing - INSTALL_URL_ADDRESS1='https://github.com/zeromq/libzmq' - INSTALL_URL_ADDRESS2='https://github.com/pyca/pynacl/' - INSTALL_URL_ADDRESS3='https://github.com/OpenBazaar/OpenBazaar-Server.git' - G_CHECK_URL "$INSTALL_URL_ADDRESS1" - G_CHECK_URL "$INSTALL_URL_ADDRESS2" - G_CHECK_URL "$INSTALL_URL_ADDRESS3" + # - Install go + # x86_64 + if (( $G_HW_ARCH == 10 )); then - G_AGI libsodium-dev automake autoconf pkg-config libtool libssl-dev libffi-dev python-dev openssl libzmq3-dev - pip install cryptography + INSTALL_URL_ADDRESS='https://dl.google.com/go/go1.11.linux-amd64.tar.gz' - # libzmq - git clone --depth=1 "$INSTALL_URL_ADDRESS1" - cd libzmq - ./autogen.sh && ./configure && make -j $G_HW_CPU_CORES - make check && make install && ldconfig - cd /tmp/$G_PROGRAM_NAME - rm -R libzmq + # ARMv8 + elif (( $G_HW_ARCH == 3 )); then - # pynacl - git clone --depth=1 "$INSTALL_URL_ADDRESS2" - cd pynacl - python setup.py build && python setup.py install - cd /tmp/$G_PROGRAM_NAME - rm -R pynacl - - # OpenBazaar - git clone --depth=1 "$INSTALL_URL_ADDRESS3" - # - Move OpenBazaar to a 'better' location - mkdir -p /etc/openbazaar-server - cp -R OpenBazaar-Server/* /etc/openbazaar-server/ - rm -R OpenBazaar-Server - # - install OpenBazaar - cd /etc/openbazaar-server - pip install -r requirements.txt - cd /tmp/$G_PROGRAM_NAME + INSTALL_URL_ADDRESS='https://dl.google.com/go/go1.11.linux-arm64.tar.gz' - unset INSTALL_URL_ADDRESS1 INSTALL_URL_ADDRESS2 INSTALL_URL_ADDRESS3 + # ARMv6/7 + else + + INSTALL_URL_ADDRESS='https://dl.google.com/go/go1.11.linux-armv6l.tar.gz' + + fi + + Download_Install "$INSTALL_URL_ADDRESS" /usr/local/ + + mkdir -p $G_FP_DIETPI_USERDATA/go + cat << _EOF_ > /etc/bashrc.d/go.sh +#!/bin/bash +export GOPATH=$G_FP_DIETPI_USERDATA/go +export PATH=\$PATH:/usr/local/go/bin +_EOF_ + + . /etc/bashrc.d/go.sh + + # - Install OB + G_DIETPI-NOTIFY 2 "Installing ${aSOFTWARE_WHIP_NAME[$INSTALLING_INDEX]}, please wait, this will take some time (1-5 minutes)" + G_RUN_CMD go get github.com/OpenBazaar/openbazaar-go fi @@ -3918,7 +3903,7 @@ _EOF_ debconf-set-selections <<< 'fahclient fahclient/power select light' debconf-set-selections <<< 'fahclient fahclient/team string 234437' # Team "DietPi" debconf-set-selections <<< 'fahclient fahclient/user string DietPi' # Default, until user chooses an own username - debconf-set-selections <<< 'fahclient fahclient/passkey string' + debconf-set-selections <<< 'fahclient fahclient/passkey string 06c869246e88c00cb05cc4d1758a97f9' Download_Install 'https://download.foldingathome.org/releases/public/release/fahclient/debian-stable-64bit/v7.5/latest.deb' @@ -4036,6 +4021,21 @@ _EOF_ fi + #myMPD + INSTALLING_INDEX=148 + if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then + + Banner_Installing + + #Sourcebuild pre-reqs + G_AGI libssl-dev libmpdclient-dev libmpdclient2 cmake + + Download_Install 'https://github.com/jcorporation/myMPD/archive/master.zip' + cd myMPD* + G_RUN_CMD ./mkrelease.sh + + fi + #Roon Bridge INSTALLING_INDEX=121 if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then @@ -5358,60 +5358,29 @@ _EOF_ Banner_Installing - #ARM packages only available in 14.04 repo: https://github.com/Fourdee/DietPi/issues/1059#issuecomment-313661959 - INSTALL_URL_ADDRESS='http://download.opensuse.org/repositories/home:/emby/xUbuntu_14.04/' + G_CHECK_URL 'https://github.com/MediaBrowser' - # x86_64, use Debian repos + #X86_64 if (( $G_HW_ARCH == 10 )); then - INSTALL_URL_ADDRESS='http://download.opensuse.org/repositories/home:/emby/Debian_' - - if (( $G_DISTRO == 3 )); then - - INSTALL_URL_ADDRESS+='8.0' - - elif (( $G_DISTRO == 4 )); then + no_check_url=1 Download_Install 'https://github.com/MediaBrowser/Emby.Releases/releases/download/3.5.2.0/emby-server-deb_3.5.2.0_amd64.deb' - INSTALL_URL_ADDRESS+='9.0' + #ARM + else - elif (( $G_DISTRO == 5 )); then + #ARMv8 + if (( $G_HW_ARCH == 3 )); then - # http://download.opensuse.org/repositories/home:/emby/Debian_Next/ - INSTALL_URL_ADDRESS+='Next' + dpkg --add-architecture armhf + G_AGUP + G_AGI gcc-6-base:armhf libc6:armhf libgcc1:armhf zlib1g:armhf fi - INSTALL_URL_ADDRESS+='/' - - fi - - G_CHECK_URL "$INSTALL_URL_ADDRESS" - - echo "deb $INSTALL_URL_ADDRESS /" > /etc/apt/sources.list.d/emby-server.list - curl -sL "$INSTALL_URL_ADDRESS"Release.key | apt-key add - - G_AGUP - - #ARMv7, Grab required pre-reqs from various sources: https://github.com/Fourdee/DietPi/issues/1128#issuecomment-326743471 / https://github.com/Fourdee/DietPi/issues/1150#issuecomment-330291298 - if (( $G_HW_ARCH == 2 )); then - - G_DIETPI-NOTIFY 2 'Installing some needed libraries' - Download_Install 'http://ftp.us.debian.org/debian/pool/main/libj/libjpeg8/libjpeg8_8d-1+deb7u1_armhf.deb' - Download_Install 'http://ftp.us.debian.org/debian/pool/main/libp/libpng/libpng12-0_1.2.50-2+deb8u3_armhf.deb' - Download_Install 'http://ftp.us.debian.org/debian/pool/main/libw/libwebp/libwebp5_0.4.1-1.2+b2_armhf.deb' - - #ARMv8 - elif (( $G_HW_ARCH == 3 )); then - - G_DIETPI-NOTIFY 2 'Installing some needed libraries' - Download_Install 'http://ftp.us.debian.org/debian/pool/main/libp/libpng/libpng12-0_1.2.50-2+deb8u3_arm64.deb' - Download_Install 'http://ftp.us.debian.org/debian/pool/main/libw/libwebp/libwebp5_0.4.1-1.2+b2_arm64.deb' - Download_Install 'https://mirror.i-novus.ru/ubuntu-ports/pool/main/libj/libjpeg-turbo/libjpeg-turbo8_1.3.0-0ubuntu2_arm64.deb' - Download_Install 'http://turul.canonical.com/pool/main/libj/libjpeg8-empty/libjpeg8_8c-2ubuntu8_arm64.deb' + no_check_url=1 Download_Install 'https://github.com/MediaBrowser/Emby.Releases/releases/download/3.5.2.0/emby-server-deb_3.5.2.0_armhf.deb' fi - G_AGI emby-server embymagick - fi #PLEXMEDIASERVER @@ -6051,7 +6020,7 @@ _EOF_ G_CHECK_URL "$INSTALL_URL_ADDRESS" G_THREAD_START git clone --depth=1 "$INSTALL_URL_ADDRESS" - G_AGI python + G_AGI python python-setuptools G_THREAD_WAIT mv plexpy /opt/ @@ -7696,7 +7665,7 @@ _EOF_ # Thus default "phpmyadmin" user need to be used, who on Jessie does not have all privileges: # https://dietpi.com/phpbb/viewtopic.php?f=8&t=5&p=54#p54 systemctl start mysql - mysql -e "grant all privileges on *.* to phpmyadmin@localhost with grant option" + mysql -e 'grant all privileges on *.* to phpmyadmin@localhost with grant option' fi @@ -7717,15 +7686,19 @@ _EOF_ Banner_Configuration + # - Data dir + mkdir -p $G_FP_DIETPI_USERDATA/openbazaar + # - service cat << _EOF_ > /etc/systemd/system/openbazaar.service [Unit] -Description=openbazaar +Description=OpenBazaar [Service] Type=simple -WorkingDirectory=/etc/openbazaar-server -ExecStart=$(which python) openbazaard.py start -a 0.0.0.0 +Environment=GOPATH=$G_FP_DIETPI_USERDATA/go +WorkingDirectory=$G_FP_DIETPI_USERDATA/go +ExecStart=$(which go) run $G_FP_DIETPI_USERDATA/go/src/github.com/OpenBazaar/openbazaar-go/openbazaard.go start -a 0.0.0.0 -d $G_FP_DIETPI_USERDATA/openbazaar [Install] WantedBy=multi-user.target @@ -8387,6 +8360,51 @@ _EOF_ fi + #myMPD + INSTALLING_INDEX=148 + if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then + + Banner_Configuration + + useradd -r -M mympd -G dietpi -s /usr/bin/nologin + + #YMPD service + cat << _EOF_ > /lib/systemd/system/mympd.service +[Unit] +Description=myMPD +After=mpd.service + +[Service] +Type=simple +#User=mympd # Forks its own process using mympd user +ExecStart=$(which mympd) /etc/mypd/mympd.conf + +[Install] +WantedBy=multi-user.target +_EOF_ + + G_CONFIG_INJECT 'webport =' 'webport = 1333' /etc/mympd/mympd.conf + G_CONFIG_INJECT 'ssl =' 'ssl = false' /etc/mympd/mympd.conf + G_CONFIG_INJECT 'user =' 'user = mympd' /etc/mympd/mympd.conf + G_CONFIG_INJECT 'group =' 'group = dietpi' /etc/mympd/mympd.conf + + #symlink music/libary folders used by mympd + if [[ $(readlink /var/lib/mpd/music) != $G_FP_DIETPI_USERDATA/Music ]]; then + + rm -R /var/lib/mpd/music + ln -sf $G_FP_DIETPI_USERDATA/Music /var/lib/mpd/music + + fi + + if [[ $(readlink /usr/share/mympd/htdocs/library) != $G_FP_DIETPI_USERDATA/Music ]]; then + + rm -R /usr/share/mympd/htdocs/library + ln -sf $G_FP_DIETPI_USERDATA/Music /usr/share/mympd/htdocs/library + + fi + + fi + #Roon Bridge INSTALLING_INDEX=121 if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then @@ -9062,16 +9080,13 @@ StandardOutput=tty TTYPath=/dev/tty1 ExecStartPre=/usr/bin/setterm --term linux --blank 0 --powersave off --cursor off - ExecStart=/bin/bash -c '/DietPi/dietpi/dietpi-cloudshell 1' - ExecStop=/usr/bin/setterm --reset ExecStop=/bin/bash -c 'G_DIETPI-NOTIFY 0 DietPi-Cloudshell terminated, have a nice day!' [Install] WantedBy=multi-user.target _EOF_ - systemctl daemon-reload fi @@ -12386,6 +12401,17 @@ _EOF_ fi + UNINSTALLING_INDEX=148 + if (( aSOFTWARE_INSTALL_STATE[$UNINSTALLING_INDEX] == -1 )); then + + userdel -f mympd + rm -R /etc/mympd + rm -R /usr/share/mympd + rm $(which mympd) + rm /lib/systemd/system/mympd.service + + fi + UNINSTALLING_INDEX=128 if (( aSOFTWARE_INSTALL_STATE[$UNINSTALLING_INDEX] == -1 )); then @@ -13345,8 +13371,13 @@ _EOF_ Banner_Uninstalling G_AGP emby-server embymagick - rm /etc/apt/sources.list.d/emby-server.list - G_AGUP + # - Pre v6.15 + if [[ -f /etc/apt/sources.list.d/emby-server.list ]]; then + + rm /etc/apt/sources.list.d/emby-server.list + G_AGUP + + fi fi @@ -13354,9 +13385,12 @@ _EOF_ if (( aSOFTWARE_INSTALL_STATE[$UNINSTALLING_INDEX] == -1 )); then Banner_Uninstalling - rm -R /etc/openbazaar-server + rm /etc/systemd/system/openbazaar.service + rm -R $G_FP_DIETPI_USERDATA/go/src/github.com/OpenBazaar + rm -R /etc/openbazaar-server &> /dev/null # Pre v6.15 OB1.0 + fi UNINSTALLING_INDEX=42 @@ -14177,13 +14211,6 @@ _EOF_ # Stop services /DietPi/dietpi/dietpi-services stop #------------------------------------------------------------ - #Generate Swapfile during 1st run (moved from boot: https://github.com/Fourdee/DietPi/issues/1270#issue-278797206) - if (( $G_DIETPI_INSTALL_STAGE == 0 )); then - - /DietPi/dietpi/func/dietpi-set_dphys-swapfile $(grep -m1 '^[[:blank:]]*AUTO_SETUP_SWAPFILE_SIZE=' /DietPi/dietpi.txt | sed 's/^.*=//') "$(grep -m1 '^[[:blank:]]*AUTO_SETUP_SWAPFILE_LOCATION=' /DietPi/dietpi.txt | sed 's/.*=//')" - - fi - #------------------------------------------------------------ #Generate userdata folders: Create_UserContent_Folders #------------------------------------------------------------ @@ -14270,7 +14297,8 @@ _EOF_ if (( $G_DIETPI_INSTALL_STAGE == 0 )); then # - Remove fake-hwclock, if real hwclock is available - hwclock &> /dev/null && G_AGP fake-hwclock + #REMOVED: Needs further work as SBC's without RTC's (XU4/Sparky SBC) are being flagged for this removal + #hwclock &> /dev/null && G_AGP fake-hwclock # - x86_64 microcode installation if (( $G_HW_ARCH == 10 )); then @@ -14280,44 +14308,6 @@ _EOF_ fi - # - Apply Timezone - if [[ $AUTOINSTALL_TIMEZONE != $( $FP_FILTER_INCLUDE_EXCLUDE +#Global - Folders +- $FP_TARGET +- /boot/dietpi/ +- /DietPi/ +- /dev/ +- /proc/ +- /sys/ +- /tmp/ +- /run/ + +#Global - Files +- $FP_LOG +- $FP_DIETPISYNC_SETTINGS +- $SYNC_STATS_FILENAME +- /var/swap +- .swap* +- *.tmp +# - MS Windows specific +- Thumbs.db +- desktop.ini +- SyncToy* # MS SyncToy +- System Volume Information # - causes error code 23 (permission denied) + +_EOF_ + + #Add users additional list + if [[ -f $FP_USER_FILTER_INCLUDE_EXCLUDE ]]; then + + cat $FP_USER_FILTER_INCLUDE_EXCLUDE >> $FP_FILTER_INCLUDE_EXCLUDE + + fi + + } + + Banner_Start(){ + + local mode='Sync' + #Dry Run? + if (( $SYNC_DRY_RUN )); then + + mode='Dry Run' + + fi + + G_DIETPI-NOTIFY 3 "$G_PROGRAM_NAME" "$mode" + + } + + Run_Sync(){ + + Banner_Start + + # Userdata location verify + G_CHECK_USERDATA + + #Generate Target dir. + mkdir -p "$FP_TARGET" + + systemctl stop rsync &> /dev/null # : https://github.com/Fourdee/DietPi/issues/1869 + killall -w rsync &> /dev/null + + #Error: Folder not found + if [[ ! -d $FP_TARGET ]]; then + + G_WHIP_MSG "Error:\n\nSync failed, unable to create Target directory $FP_TARGET" + + #Error: Rsync is already running + elif (( $(ps aux | grep -ci -m1 "[r]sync") )); then + + G_WHIP_MSG 'Sync Failed:\n\nA sync job could not be started as rsync is already running.' + echo -e "Sync failed: $(date +"%d-%m-%Y_%H%M"). Rsync is already running." >> "$FP_TARGET/$SYNC_STATS_FILENAME" + + #Start sync + else + + #Generate Exclude/Include lists + Create_Filter_Include_Exclude + + #Rsync options + local rync_options+="-aHP4 --info=name0 --info=progress2 --human-readable --delete-excluded --exclude-from=$FP_FILTER_INCLUDE_EXCLUDE --log-file=$FP_LOG " + + # - Compression? + if (( $SYNC_COMPRESSION )); then + + rync_options+='z' + + fi + + # - Dry Run? + if (( $SYNC_DRY_RUN )); then + + rync_options+='n' + + fi + + # - Delete mode? + if (( $SYNC_DELETE_MODE )); then + + rync_options+=' --delete' + + fi + + #Verify enough space + # NB: working in KiB until end MiB conversion, as, don't like using long long int, and, KiB should offer a good end result. + local old_backup_size=$(du -ks "$FP_TARGET" | awk '{print $1}') + + rsync --dry-run --stats $rync_options "$FP_SOURCE"/ "$FP_TARGET"/ > /tmp/dietpi-sync_result + local new_backup_size=$(( $(grep -m1 'Total file size' /tmp/dietpi-sync_result | sed 's/[^0-9]*//g') / 1024 )) + local total_file_count=$(( $(grep -m1 'Number of files' /tmp/dietpi-sync_result | awk '{print $6}' | sed 's/[^0-9]*//g') )) + local total_folder_count=$(( $(grep -m1 'Number of files' /tmp/dietpi-sync_result | awk '{print $8}' | sed 's/[^0-9]*//g') )) + local target_fs_blocksize=$(stat -fc %s "$FP_TARGET") + new_backup_size=$(( $new_backup_size + ( $total_file_count + $total_folder_count ) * $target_fs_blocksize / 1024 )) + local end_result=$(( ( $new_backup_size - $old_backup_size ) / 1024 + 1 )) + rm /tmp/dietpi-sync_result + + if ! G_CHECK_FREESPACE "$FP_TARGET" $end_result; then + + G_WHIP_BUTTON_OK_TEXT='Ignore' + G_WHIP_BUTTON_CANCEL_TEXT='Exit' + G_WHIP_YESNO 'The system sync target location appears to have insufficient free space to successfully finish the backup.\nHowever, this check is a rough estimation in reasonable time, thus it could be marginally incorrect.\n\nWould you like to override this warning and continue with the backup?' + if (( $? )); then + + echo -e "Sync canceled: due to insufficient free space: $(date +"%d-%m-%Y_%H%M")" >> "$FP_TARGET/$SYNC_STATS_FILENAME" + break + + fi + + fi + + G_DIETPI-NOTIFY 2 "Sync | $FP_SOURCE > $FP_TARGET: in progress, please wait..." + + #Sync + rsync $rync_options "$FP_SOURCE"/ "$FP_TARGET"/ + EXIT_CODE=$? + G_DIETPI-NOTIFY -1 $EXIT_CODE "$G_PROGRAM_NAME" + if (( $EXIT_CODE == 0 )); then + + echo -e "Sync completed: $(date +"%d-%m-%Y_%H%M")" >> "$FP_TARGET/$SYNC_STATS_FILENAME" + if (( ! $SYNC_DRY_RUN )); then + + G_WHIP_MSG "Sync completed:\n - $FP_SOURCE > $FP_TARGET" + + else + + G_WHIP_MSG "Dry Run Sync completed (NO modifications):\n - $FP_SOURCE > $FP_TARGET" + + fi + + else + + echo -e "Sync failed: please see the log file for more information ($FP_LOG): $(date +"%d-%m-%Y_%H%M")" >> "$FP_TARGET/$SYNC_STATS_FILENAME" + G_WHIP_MSG "Sync failed:\n - $FP_SOURCE > $FP_TARGET\n\nYou will given an option to view the logfile on the next screen. Please check it for information and/or errors." + + fi + + G_WHIP_VIEWLOG $FP_LOG + + #return to main menu + TARGETMENUID=0 + + fi + + systemctl start rsync &> /dev/null # : https://github.com/Fourdee/DietPi/issues/1869 + + } + + Check_Available_DietPi_Mounts(){ + + local temp_file_mounts='.dietpi-sync_dietpi_mounts' + df -h > "$temp_file_mounts" + + #Samba Client + SAMBA_MOUNT_AVAILABLE=0 + SAMBA_MOUNT_TEXT="Not mounted ($FP_SAMBA_MOUNT). Select to setup." + if (( $(grep -ci -m1 "/mnt/samba" $temp_file_mounts) )); then + + SAMBA_MOUNT_AVAILABLE=1 + SAMBA_MOUNT_TEXT="Size: $(df -h | grep /mnt/samba | awk '{print $2}')B | Available: $(df -h | grep /mnt/samba | awk '{print $4}')B" + + fi + + rm $temp_file_mounts + + } + + #///////////////////////////////////////////////////////////////////////////////////// + # Settings File + #///////////////////////////////////////////////////////////////////////////////////// + #Settings File + FP_DIETPISYNC_SETTINGS='/DietPi/dietpi/.dietpi-sync_settings' + + Write_Settings_File(){ + + cat << _EOF_ > $FP_DIETPISYNC_SETTINGS +FP_SOURCE=$FP_SOURCE +FP_TARGET=$FP_TARGET +SYNC_DELETE_MODE=$SYNC_DELETE_MODE +SYNC_COMPRESSION=$SYNC_COMPRESSION +SYNC_CRONDAILY=$SYNC_CRONDAILY +_EOF_ + + } + + Read_Settings_File(){ + + if [[ -f $FP_DIETPISYNC_SETTINGS ]]; then + + . $FP_DIETPISYNC_SETTINGS + + fi + + } + #///////////////////////////////////////////////////////////////////////////////////// # MENUS #///////////////////////////////////////////////////////////////////////////////////// TARGETMENUID=0 - FTP_MOUNT_AVAILABLE=0 - FTP_MOUNT_TEXT='Not available' SAMBA_MOUNT_AVAILABLE=0 SAMBA_MOUNT_TEXT='Not available' @@ -82,7 +321,8 @@ G_WHIP_MENU_ARRAY=( - 'Help' 'What does DietPi-Sync do?' + '' '●─ Info ' + 'Help' "What does $G_PROGRAM_NAME do?" '' '●─ Options ' 'Source Location' ': Change the Source directory.' 'Target Location' ': Change the Target directory.' @@ -207,10 +447,10 @@ 'Manual' "Manually type your $current_mode_text directory." 'List' 'Select from a list of available mounts/drives' "Samba Client" "$SAMBA_MOUNT_TEXT" - "FTP Client" "$FTP_MOUNT_TEXT" ) + G_WHIP_BUTTON_CANCEL_TEXT='Back' G_WHIP_MENU "$whip_description_text" if (( $? == 0 )); then @@ -220,8 +460,8 @@ /DietPi/dietpi/dietpi-drive_manager 1 - local return_value=$(cat /tmp/dietpi-drive_manager_selmnt) - if [[ $return_value == "/" ]]; then + local return_value=$( /dev/null - - #Global - Folders - echo -e "$FP_TARGET" >> $FP_EXCLUDE_GLOBAL - echo -e "/boot/dietpi/*" >> $FP_EXCLUDE_GLOBAL - echo -e "/DietPi/*" >> $FP_EXCLUDE_GLOBAL - echo -e "/dev/*" >> $FP_EXCLUDE_GLOBAL - echo -e "/proc/*" >> $FP_EXCLUDE_GLOBAL - echo -e "/sys/*" >> $FP_EXCLUDE_GLOBAL - echo -e "/tmp/*" >> $FP_EXCLUDE_GLOBAL - echo -e "/run/*" >> $FP_EXCLUDE_GLOBAL - - #Global - Files - echo -e "$LOGFILE" >> $FP_EXCLUDE_GLOBAL - echo -e $FP_DIETPISYNC_SETTINGS >> $FP_EXCLUDE_GLOBAL - echo -e "$FP_EXCLUDE_USER" >> $FP_EXCLUDE_GLOBAL - echo -e "$FP_INCLUDE_USER" >> $FP_EXCLUDE_GLOBAL - echo -e "$SYNC_STATS_FILENAME" >> $FP_EXCLUDE_GLOBAL - echo -e "/var/swap" >> $FP_EXCLUDE_GLOBAL - echo -e ".swap*" >> $FP_EXCLUDE_GLOBAL - echo -e "*.tmp" >> $FP_EXCLUDE_GLOBAL - # - MS Windows specific - echo -e "Thumbs.db" >> $FP_EXCLUDE_GLOBAL - echo -e "desktop.ini" >> $FP_EXCLUDE_GLOBAL - echo -e "SyncToy*" >> $FP_EXCLUDE_GLOBAL # MS SyncToy - echo -e "System Volume Information" >> $FP_EXCLUDE_GLOBAL # - causes error code 23 (permission denied) - - #Add users additional list - if [[ -f $FP_EXCLUDE_USER ]]; then - - cat $FP_EXCLUDE_USER >> $FP_EXCLUDE_GLOBAL - - fi - - } - - Create_Include_File(){ - - #Generate new - rm $FP_INCLUDE_GLOBAL &> /dev/null - - #Global - Folders - > $FP_INCLUDE_GLOBAL - - #Global - Files - - #Add users additional list - if [[ -f $FP_INCLUDE_USER ]]; then - - cat $FP_INCLUDE_USER >> $FP_INCLUDE_GLOBAL - - fi - - } - - Banner_Start(){ - - local mode='Sync' - #Dry Run? - if (( $SYNC_DRY_RUN )); then - - mode='Dry Run' - - fi - - G_DIETPI-NOTIFY 3 "$G_PROGRAM_NAME" "$mode" - - } - - - Run_Sync(){ - - Banner_Start - - # Userdata location verify - G_CHECK_USERDATA - - #Generate Target dir. - mkdir -p "$FP_TARGET" - - systemctl stop rsync &> /dev/null # : https://github.com/Fourdee/DietPi/issues/1869 - killall -w rsync &> /dev/null - - #Error: Folder not found - if [[ ! -d $FP_TARGET ]]; then - - G_WHIP_MSG "Error:\n\nSync failed, unable to create Target directory $FP_TARGET" - - #Error: Rsync is already running - elif (( $(ps aux | grep -ci -m1 "[r]sync") )); then - - G_WHIP_MSG 'Sync Failed:\n\nA sync job could not be started as rsync is already running.' - echo -e "Sync failed: $(date +"%d-%m-%Y_%H%M"). Rsync is already running." >> "$FP_TARGET/$SYNC_STATS_FILENAME" - - #Start sync - else - - #Generate Exclude/Include lists - Create_Exclude_File - Create_Include_File - - #Archive mode - local rync_options='-a' - #verbose - rync_options+='v' - #Keep partial files + Progress. (eg: if file is interupted, it will resume where it left off, rather than resending the whole file. - rync_options+='P' - #Prefer IPv4 - rync_options+='4' - - #Compression? - if (( $SYNC_COMPRESSION )); then - - rync_options+='z' - - fi - - #Dry Run? - if (( $SYNC_DRY_RUN )); then - - rync_options+='n' - - fi - - #Delete mode? - if (( $SYNC_DELETE_MODE )); then - - rync_options+=' --delete' - - fi - - #Write new logfile - echo -e "DietPi-Sync Log File.\n$(date +%d-%m-%Y_%H%M)\nSYNC_DRY_RUN=$SYNC_DRY_RUN\n\n" > "$LOGFILE" - - #Verify enough space - # NB: working in KiB until end MiB conversion, as, don't like using long long int, and, KiB should offer a good end result. - local old_backup_size=$(du -ks "$FP_TARGET" | awk '{print $1}') - - rsync --dry-run --stats $rync_options --exclude-from=$FP_EXCLUDE_GLOBAL --include-from=$FP_INCLUDE_GLOBAL "$FP_SOURCE"/ "$FP_TARGET"/ > /tmp/dietpi-sync_result - local new_backup_size=$(( $(grep -m1 'Total file size' /tmp/dietpi-sync_result | sed 's/[^0-9]*//g') / 1024 )) - local total_file_count=$(( $(grep -m1 'Number of files' /tmp/dietpi-sync_result | awk '{print $6}' | sed 's/[^0-9]*//g') )) - local total_folder_count=$(( $(grep -m1 'Number of files' /tmp/dietpi-sync_result | awk '{print $8}' | sed 's/[^0-9]*//g') )) - local target_fs_blocksize=$(stat -fc %s "$FP_TARGET") - new_backup_size=$(( $new_backup_size + ( $total_file_count + $total_folder_count ) * $target_fs_blocksize / 1024 )) - local end_result=$(( ( $new_backup_size - $old_backup_size ) / 1024 + 1 )) - rm /tmp/dietpi-sync_result - - if G_CHECK_FREESPACE "$FP_TARGET" $end_result; then - - G_WHIP_BUTTON_OK_TEXT='Ignore' - G_WHIP_BUTTON_CANCEL_TEXT='Exit' - G_WHIP_YESNO 'The system sync target location appears to have insufficient free space to successfully finish the backup.\nHowever, this check is a rough estimation in reasonable time, thus it could be marginally incorrect.\n\nWould you like to override this warning and continue with the backup?' - if (( $? )); then - - echo -e "Sync canceled: due to insufficient free space: $(date +"%d-%m-%Y_%H%M")" >> "$FP_TARGET/$SYNC_STATS_FILENAME" - break - - fi - - fi - - #Sync - G_RUN_CMD rsync $rync_options --log-file=$LOGFILE --exclude-from=$FP_EXCLUDE_GLOBAL --include-from=$FP_INCLUDE_GLOBAL "$FP_SOURCE"/ "$FP_TARGET"/ - echo -e "Sync completed: $(date +"%d-%m-%Y_%H%M")" >> "$FP_TARGET/$SYNC_STATS_FILENAME" - - if (( ! $SYNC_DRY_RUN )); then - - G_WHIP_MSG "Sync completed:\n\n$FP_SOURCE\n\nHas been synced to:\n$FP_TARGET\n\nLog file: $LOGFILE" - - else - - G_WHIP_MSG "Dry Run Sync completed:\n\n$FP_SOURCE\n\nHas been synced with a Dry Run (NO modifications) to:\n$FP_TARGET\n\nLog file: $LOGFILE" - - fi - - G_WHIP_VIEWLOG "$LOGFILE" - - #return to main menu - TARGETMENUID=0 - - fi - - systemctl start rsync &> /dev/null # : https://github.com/Fourdee/DietPi/issues/1869 - - } - - Check_Available_DietPi_Mounts(){ - - local temp_file_mounts="/tmp/.dietpi-sync_dietpi_mounts" - df -h > "$temp_file_mounts" - - #Samba Client - SAMBA_MOUNT_AVAILABLE=0 - SAMBA_MOUNT_TEXT="Not mounted ($FP_SAMBA_MOUNT). Select to setup." - if (( $(grep -ci -m1 "/mnt/samba" "$temp_file_mounts") )); then - - SAMBA_MOUNT_AVAILABLE=1 - SAMBA_MOUNT_TEXT="Size: $(df -h | grep /mnt/samba | awk '{print $2}')B | Available: $(df -h | grep /mnt/samba | awk '{print $4}')B" - - fi - - #FTP Client - FTP_MOUNT_AVAILABLE=0 - FTP_MOUNT_TEXT="Not mounted ($FP_FTP_MOUNT). Select to setup." - if (( $(grep -ci -m1 "/mnt/ftp_client" "$temp_file_mounts") )); then - - FTP_MOUNT_AVAILABLE=1 - FTP_MOUNT_TEXT="Mounted and online." + /DietPi/dietpi/dietpi-drive_manager fi - rm "$temp_file_mounts" - } #///////////////////////////////////////////////////////////////////////////////////// - # Settings File + # Main Loop #///////////////////////////////////////////////////////////////////////////////////// - #Settings File - FP_DIETPISYNC_SETTINGS='/DietPi/dietpi/.dietpi-sync_settings' - - Write_Settings_File(){ - - rm $FP_DIETPISYNC_SETTINGS &> /dev/null - - echo -e "$FP_SOURCE" >> $FP_DIETPISYNC_SETTINGS - echo -e "$FP_TARGET" >> $FP_DIETPISYNC_SETTINGS - echo -e "$SYNC_DELETE_MODE" >> $FP_DIETPISYNC_SETTINGS - echo -e "$SYNC_COMPRESSION" >> $FP_DIETPISYNC_SETTINGS - echo -e "$SYNC_CRONDAILY" >> $FP_DIETPISYNC_SETTINGS - - } - - Read_Settings_File(){ - - if [[ -f $FP_DIETPISYNC_SETTINGS ]]; then + #pre-reqs, install if required. + G_AG_CHECK_INSTALL_PREREQ rsync - local sed_index=1 - FP_SOURCE=$(sed -n "$sed_index"p $FP_DIETPISYNC_SETTINGS);((sed_index++)) - FP_TARGET=$(sed -n "$sed_index"p $FP_DIETPISYNC_SETTINGS);((sed_index++)) - SYNC_DELETE_MODE=$(sed -n "$sed_index"p $FP_DIETPISYNC_SETTINGS);((sed_index++)) - SYNC_COMPRESSION=$(sed -n "$sed_index"p $FP_DIETPISYNC_SETTINGS);((sed_index++)) - SYNC_CRONDAILY=$(sed -n "$sed_index"p $FP_DIETPISYNC_SETTINGS);((sed_index++)) + #Generate optional user include/exclude file + if [[ ! -f $FP_USER_FILTER_INCLUDE_EXCLUDE ]]; then - fi + cat << _EOF_ > $FP_USER_FILTER_INCLUDE_EXCLUDE +#$G_PROGRAM_NAME | Custom include/exclude filters +# +#To INCLUDE (+) a file/folder: +#+ /location/to/my/file +#+ /location/to/my/directory/ +# +#To EXCLUDE (-) a file/folder: +#- /location/to/my/file +#- /location/to/my/directory/ - } +_EOF_ - #///////////////////////////////////////////////////////////////////////////////////// - # Main Loop - #///////////////////////////////////////////////////////////////////////////////////// - #pre-reqs, install if required. - G_AG_CHECK_INSTALL_PREREQ rsync + fi #Read settings file Read_Settings_File @@ -790,10 +725,9 @@ #----------------------------------------------------------------------------------- #Cleaup left over tmp files - rm $FP_INCLUDE_GLOBAL &> /dev/null - rm $FP_EXCLUDE_GLOBAL &> /dev/null + rm $FP_FILTER_INCLUDE_EXCLUDE &> /dev/null #----------------------------------------------------------------------------------- - exit 0 + exit $EXIT_CODE #----------------------------------------------------------------------------------- } diff --git a/dietpi/dietpi-update b/dietpi/dietpi-update index fd2a135e7f..d42cb9e340 100644 --- a/dietpi/dietpi-update +++ b/dietpi/dietpi-update @@ -41,6 +41,7 @@ #UPDATE Vars #///////////////////////////////////////////////////////////////////////////////////// FP_LOG='/var/tmp/dietpi/logs/dietpi-update.log' + FP_TMP_LOG="/tmp/$G_PROGRAM_NAME/dietpi-update.log" DIETPIUPDATE_VERSION_CORE=6 # Version of dietpi-update / set server_version-6 line one to value++ and obsolete previous dietpi-update scripts SERVER_ONLINE=0 @@ -301,8 +302,7 @@ _EOF_ G_CHECK_USERDATA #Insufficient free space - G_CHECK_FREESPACE / 500 - if (( ! $? )); then + if ! G_CHECK_FREESPACE / 500; then : #exit normally for delete [] @@ -340,8 +340,9 @@ _EOF_ #Run update and patcher rm $FP_LOG &> /dev/null - #Run_Update | tee -a $FP_LOG #: https://github.com/Fourdee/DietPi/issues/1877#issuecomment-403866204 - Run_Update > >(tee -a $FP_LOG) 2>&1 + #Run_Update #: https://github.com/Fourdee/DietPi/issues/1877#issuecomment-403866204 + Run_Update > >(tee $FP_TMP_LOG) 2>&1 + mv $FP_TMP_LOG $FP_LOG #.update file stage (only used on 1st run of dietpi-software to check/apply updates, 0 tells dietpi-software to reboot) echo 0 > /DietPi/dietpi/.update_stage diff --git a/dietpi/func/dietpi-banner b/dietpi/func/dietpi-banner index ab2c2026ff..8bd54fa324 100644 --- a/dietpi/func/dietpi-banner +++ b/dietpi/func/dietpi-banner @@ -124,7 +124,7 @@ Credits_Print(){ - echo -e "\e[90m DietPi Core Team : Daniel Knight (founder), MichaIng, K-Plan\e[0m" + echo -e "\e[90m DietPi Team : Daniel Knight (founder), MichaIng, K-Plan\e[0m" local fp_prep_info='/DietPi/dietpi/.prep_info' if [[ -f $fp_prep_info ]]; then @@ -137,14 +137,15 @@ fi - echo -e "\e[90m Image creator : $image_creator\e[0m" - echo -e "\e[90m Pre-image used : $preimage_name\e[0m" + echo -e "\e[90m Image : $image_creator (pre-image: $preimage_name)\e[0m" IMAGE_ADDITIONAL_CREDITS='' fi - echo -e "\e[90m Web : https://DietPi.com | https://twitter.com/dietpi_\n Donate : https://goo.gl/pzISt9" + echo -e '\e[90m Web : https://DietPi.com | https://twitter.com/dietpi_ + Patreon Legends : PINE64 community + Donate : https://DietPi.com/#donate' if [[ $IMAGE_ADDITIONAL_CREDITS ]]; then @@ -152,7 +153,7 @@ fi - echo -e " DietPi web hosting : Powered by https://MyVirtualServer.com\e[0m" + echo -e " DietPi Hosting : Powered by https://MyVirtualServer.com\e[0m" echo -e "\n\e[1m dietpi-launcher\e[0m = All the DietPi programs in one place." echo -e "\e[1m dietpi-config\e[0m = Feature rich configuration tool for your device." echo -e "\e[1m dietpi-software\e[0m = Select optimized software for installation." diff --git a/dietpi/func/dietpi-benchmark b/dietpi/func/dietpi-benchmark index 3568f97bd2..1e7b1cc6fc 100644 --- a/dietpi/func/dietpi-benchmark +++ b/dietpi/func/dietpi-benchmark @@ -10,8 +10,13 @@ #//////////////////////////////////// # # Info: - # /DietPi/dietpi/func/dietpi-benchmark 0 $FP = Benchmark $FP filesystem read/write. result file=/tmp/.dietpi-benchmark_result + # FSBENCH_FP=/location FSBENCH_FILESIZE=optional_size_MB /DietPi/dietpi/func/dietpi-benchmark 0 = Benchmark $FSBENCH_FP filesystem read/write. + # /DietPi/dietpi/func/dietpi-benchmark 1 = Benchmark CPU. + # /DietPi/dietpi/func/dietpi-benchmark 2 = Run all benchmarks and upload to dietpi.com # + # Notes: + # - All results are saved to /tmp/dietpi-benchmark_results + # Please see end of script for fixed layout of above file #//////////////////////////////////// #Import DietPi-Globals --------------------------------------------------------------- @@ -26,90 +31,241 @@ # Global #///////////////////////////////////////////////////////////////////////////////////// + SHOW_RESULTS=${SHOW_RESULTS:-1} #optional input | show results for individual tests? + + CPUBENCH_TIME='Not tested' + CPUBENCH_INT_MAX=${CPUBENCH_INT_MAX:-1000000} #optional input + CPU_Benchmark(){ + + G_DIETPI-NOTIFY 0 "Running DietPi-CPU Benchmark with max value of 1000000 over $(nproc --all) cores, please wait..." + + cat << _EOF_ > $FP_TEMP/bench +#!/bin/bash +target_max_int=$CPUBENCH_INT_MAX +cores=$G_HW_CPU_CORES +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 $FP_TEMP/bench + + sync + sleep 1 + + { time -p $FP_TEMP/bench; } 2> $FP_TEMP/bench_result + + CPUBENCH_TIME=$( grep -m1 'real' $FP_TEMP/bench_result | awk '{print $2}' ) + + if (( $SHOW_RESULTS )); then + + G_WHIP_MSG "CPU Benchmark Results:\n + - Total time = $CPUBENCH_TIME Seconds + - Value to reach = $CPUBENCH_INT_MAX\n\n + NB: A lower 'Total time' is faster" + + fi + + } + + FSBENCH_READ_SPEED='Not tested' + FSBENCH_WRITE_SPEED='Not tested' + FSBENCH_FILESIZE=${FSBENCH_FILESIZE:-0} #optional input for automated + FSBENCH_FP=${FSBENCH_FP:-/} #optional input for automated Filesystem_Benchmark(){ local benchmark_file_name='benchmark.file' - local fp_benchmark_file="$1" - local read_speed=0 - local write_speed=0 - local benchmark_filesize=0 local min_benchmark_size=10 - local max_benchmark_size=$(( $(G_CHECK_FREESPACE $fp_benchmark_file) - 100 )) + local max_benchmark_size=$(( $(G_CHECK_FREESPACE $FSBENCH_FP) - 100 )) if (( $max_benchmark_size > 1000 )); then max_benchmark_size=1000 fi - if [[ $fp_benchmark_file != *'/' ]]; then + if [[ $FSBENCH_FP != *'/' ]]; then - fp_benchmark_file+='/' + FSBENCH_FP+='/' fi - fp_benchmark_file+=$benchmark_file_name + FSBENCH_FP+=$benchmark_file_name printf '\ec' # clear current terminal screen #Obtain user benchmark size. - G_WHIP_DEFAULT_ITEM=$min_benchmark_size - G_WHIP_INPUTBOX "Please enter a filesize test value (MB). A value of 100 is recommended.\n- Minimum value: $min_benchmark_size\n- Maximum possible value: $max_benchmark_size" - if (( $? == 0 )); then + if (( $FSBENCH_FILESIZE == 0 )); then - benchmark_filesize=$G_WHIP_RETURNED_VALUE - if ! G_CHECK_VALIDINT $benchmark_filesize $min_benchmark_size $max_benchmark_size; then + G_WHIP_DEFAULT_ITEM=$min_benchmark_size + G_WHIP_INPUTBOX "Please enter a filesize test value (MB). A value of 100 is recommended.\n- Minimum value: $min_benchmark_size\n- Maximum possible value: $max_benchmark_size" + if (( $? == 0 )); then - benchmark_filesize=-1 + FSBENCH_FILESIZE=$G_WHIP_RETURNED_VALUE fi fi #Run benchmark - if (( $benchmark_filesize > 0 )); then + if G_CHECK_VALIDINT $FSBENCH_FILESIZE $min_benchmark_size $max_benchmark_size; then - G_DIETPI-NOTIFY 2 "Performing Read/Write benchmark on $fp_benchmark_file, please wait..." + G_DIETPI-NOTIFY 2 "Performing Read/Write benchmark on $FSBENCH_FP, please wait..." - G_DIETPI-NOTIFY 2 "Testing Seq Write Speed ($benchmark_filesize MB)" + G_DIETPI-NOTIFY 2 "Testing Seq Write Speed ($FSBENCH_FILESIZE MB)" sleep 1 - write_speed=$(dd bs=4K count=$(( $benchmark_filesize * 1024 / 4 )) if=/dev/zero of=$fp_benchmark_file conv=fdatasync 2>&1 | grep 'MB' | awk '{print $(NF - 1), $NF}') + FSBENCH_WRITE_SPEED=$(dd bs=4K count=$(( $FSBENCH_FILESIZE * 1024 / 4 )) if=/dev/zero of=$FSBENCH_FP conv=fdatasync 2>&1 | grep 'MB' | awk '{print $(NF - 1), $NF}' | sed 's/[^0-9.]*//g') # - Clear cache sync echo 3 > /proc/sys/vm/drop_caches - G_DIETPI-NOTIFY 2 "Testing Seq Read Speed ($benchmark_filesize MB)" + G_DIETPI-NOTIFY 2 "Testing Seq Read Speed ($FSBENCH_FILESIZE MB)" sleep 1 - read_speed=$(dd bs=4K count=$(( $benchmark_filesize * 1024 / 4 )) if=$fp_benchmark_file of=/dev/zero conv=fdatasync 2>&1 | grep 'MB' | awk '{print $(NF - 1), $NF}') + FSBENCH_READ_SPEED=$(dd bs=4K count=$(( $FSBENCH_FILESIZE * 1024 / 4 )) if=$FSBENCH_FP of=/dev/zero conv=fdatasync 2>&1 | grep 'MB' | awk '{print $(NF - 1), $NF}' | sed 's/[^0-9.]*//g') - cat << _EOF_ > /tmp/.dietpi-benchmark_result -$read_speed -$write_speed -_EOF_ + if (( $SHOW_RESULTS )); then + + G_WHIP_MSG "Filesystem Benchmark Results:\n + - Filepath = $FSBENCH_FP + - Test size = ${FSBENCH_FILESIZE} MB + - READ = ${FSBENCH_READ_SPEED} MB/s + - WRITE = ${FSBENCH_WRITE_SPEED} MB/s" + + fi + + rm $FSBENCH_FP &> /dev/null + + fi + + } + + Benchmark_Survey(){ + + SHOW_RESULTS=0 + mkdir -p /var/lib/dietpi/dietpi-benchmark + + G_DIETPI-NOTIFY 0 'Running benchmark suite tests for upload to DietPi-Survey' + + #CPU + if (( $G_HW_CPU_CORES <= 2 )); then - G_WHIP_MSG "Filesystem Benchmark Results:\n\n - - Filepath = $fp_benchmark_file - - Test size = ${benchmark_filesize}MB - - READ = $read_speed - - WRITE = $write_speed" + G_WHIP_YESNO "We have detected a low CPU core count ($G_HW_CPU_CORES). The tests may take upto 5 minutes to complete on a RaspberryPi Zero.\n\nDo you wish to continue?" + if (( $? == 1 )); then - rm $fp_benchmark_file &> /dev/null + exit 0 + + fi fi + CPU_Benchmark + + #FS/RAM + FSBENCH_FILESIZE=10 + + # - RAM + FSBENCH_FP='/tmp' + Filesystem_Benchmark + local ram_write=$FSBENCH_WRITE_SPEED + local ram_read=$FSBENCH_READ_SPEED + + # - Rootfs + FSBENCH_FP='/' + Filesystem_Benchmark + local rootfs_write=$FSBENCH_WRITE_SPEED + local rootfs_read=$FSBENCH_READ_SPEED + + cat << _EOF_ > /var/lib/dietpi/dietpi-benchmark/upload_results +$CPUBENCH_TIME +$rootfs_write +$rootfs_read +$ram_write +$ram_read +_EOF_ + + SHOW_RESULTS=1 + + G_WHIP_MSG "Benchmarks completed: +CPU : Total time $CPUBENCH_INT_MAX int = $CPUBENCH_TIME seconds +RAM : Write = $ram_write MB/s | Read = $ram_read MB/s +RootFS : Write = $rootfs_write MB/s | Read = $rootfs_read MB/s" + } #///////////////////////////////////////////////////////////////////////////////////// # Main Loop #///////////////////////////////////////////////////////////////////////////////////// + #----------------------------------------------------------------------------------- + /DietPi/dietpi/dietpi-services stop + #----------------------------------------------------------------------------------- if (( $INPUT == 0 )); then - Filesystem_Benchmark "$2" + Filesystem_Benchmark + + elif (( $INPUT == 1 )); then + + CPU_Benchmark + + elif (( $INPUT == 2 )); then + + Benchmark_Survey fi #----------------------------------------------------------------------------------- + #Export results data for other scripts: + cat << _EOF_ > /tmp/dietpi-benchmark_results +$CPUBENCH_TIME +$FSBENCH_WRITE_SPEED +$FSBENCH_READ_SPEED +_EOF_ + #----------------------------------------------------------------------------------- + /DietPi/dietpi/dietpi-services start + #----------------------------------------------------------------------------------- exit #----------------------------------------------------------------------------------- diff --git a/dietpi/func/dietpi-globals b/dietpi/func/dietpi-globals index 55be7fb229..db8bba9079 100644 --- a/dietpi/func/dietpi-globals +++ b/dietpi/func/dietpi-globals @@ -11,7 +11,7 @@ # Info: # - Allows export of shared DietPi global variables/funcs into current bash session, and other scripts # - CRITICAL, when using for-loops, always ensure you localize the var before hand (eg: local i=0\nfor (( i=.....)) ), else havoc: https://github.com/Fourdee/DietPi/issues/1454 - # - activates on login /etc/profile.d/99-dietpi-login.sh + # - activates on interactive bash: /etc/bashrc.d/dietpi-login.sh # - activates on all other DietPi script during their init # # Excluded scripts, which do NOT load these globals @@ -23,7 +23,7 @@ #//////////////////////////////////// #----------------------------------------------------------------------------------- - #Exit script for unsupported terminal and set dumb: https://github.com/Fourdee/DietPi/issues/1703#issue-314330405 + # Exit script for unsupported terminal and set dumb: https://github.com/Fourdee/DietPi/issues/1703#issue-314330405 if [[ -z $TERM || $TERM == 'unknown' ]]; then export TERM='dumb' @@ -76,7 +76,7 @@ #DietPi versions G_DIETPI_VERSION_CORE=0 G_DIETPI_VERSION_SUB=0 - if [[ -f '/DietPi/dietpi/.version' ]]; then + if [[ -r '/DietPi/dietpi/.version' ]]; then G_DIETPI_VERSION_CORE=$(sed -n 1p /DietPi/dietpi/.version) G_DIETPI_VERSION_SUB=$(sed -n 2p /DietPi/dietpi/.version) @@ -162,15 +162,15 @@ $(ps f -eo pid,user,tty,cmd | grep -i [d]ietpi)" # Ensure we are in script working dir or users home dir, if available: https://github.com/Fourdee/DietPi/issues/905#issuecomment-298223705 if [[ $G_PROGRAM_NAME ]] && mkdir -p /tmp/$G_PROGRAM_NAME && cd /tmp/$G_PROGRAM_NAME; then - [[ G_DEBUG == 1 ]] && G_DIETPI-NOTIFY 2 "Entered scripts working directory: /tmp/$G_PROGRAM_NAME" + [[ $G_DEBUG == 1 ]] && G_DIETPI-NOTIFY 2 "Entered scripts working directory: /tmp/$G_PROGRAM_NAME" elif [[ -d $HOME ]] && cd $HOME; then - [[ G_DEBUG == 1 ]] && G_DIETPI-NOTIFY 2 "Entered users home directory: $HOME" + [[ $G_DEBUG == 1 ]] && G_DIETPI-NOTIFY 2 "Entered users home directory: $HOME" else - [[ G_DEBUG == 1 ]] && G_DIETPI-NOTIFY 2 "Failed to enter scripts working dir or users home dir. Will use current: $PWD" + [[ $G_DEBUG == 1 ]] && G_DIETPI-NOTIFY 2 "Failed to enter scripts working dir or users home dir. Will use current: $PWD" fi @@ -178,15 +178,7 @@ $(ps f -eo pid,user,tty,cmd | grep -i [d]ietpi)" G_EXIT(){ # - Purge working directory, if existent - if [[ -d /tmp/$G_PROGRAM_NAME ]]; then - - rm -R /tmp/$G_PROGRAM_NAME - - # else - - # echo -e "DEBUG: /tmp/\$G_PROGRAM_NAME did not exist on script exit. \$G_PROGRAM_NAME=${G_PROGRAM_NAME:-NULL}" - - fi + [[ -d /tmp/$G_PROGRAM_NAME ]] && [[ $PWD == /tmp/$G_PROGRAM_NAME* ]] && cd /tmp && rm -R /tmp/$G_PROGRAM_NAME && [[ $G_DEBUG == 1 ]] && G_DIETPI-NOTIFY 2 "Removed scripts working directory: /tmp/$G_PROGRAM_NAME" # - Execute custom exit function, if existent declare -F G_EXIT_CUSTOM &> /dev/null && G_EXIT_CUSTOM @@ -286,7 +278,7 @@ $(ps f -eo pid,user,tty,cmd | grep -i [d]ietpi)" else Status_Failed - ainput_string+=(' An issue has occured\n') + ainput_string+=(' An issue has occurred\n') Print_Output_String 2 fi @@ -337,21 +329,20 @@ $(ps f -eo pid,user,tty,cmd | grep -i [d]ietpi)" local output_lines=0 (( output_lines=(${#input_string}+6)/$(tput cols) )) (( $output_lines )) && tput cuu $output_lines - # If redirect to PID file fails (due to noclobber, on existent file), start processing animation. - # - This method prevents a tiny condition race from checking file existance to creating it, when doing: [[ ! -e file ]] && > file - # set -o noclobber - # if { > /tmp/dietpi-process.pid; } &> /dev/null; then + # If redirect to existent PID file fails due to noclobber, don't start processing animation. + # - This method prevents a tiny condition race from checking file existance until creating it, when doing: [[ ! -e file ]] && > file + set -o noclobber + if { > /tmp/dietpi-process.pid; } &> /dev/null; then - # set +o noclobber - # { Print_Process_Animation & echo $! > /tmp/dietpi-process.pid; disown; } 2> /dev/null + set +o noclobber + { Print_Process_Animation & echo $! > /tmp/dietpi-process.pid; disown; } 2> /dev/null - # else + else - # set +o noclobber - # echo 1 + set +o noclobber - # fi - [[ ! -e /tmp/dietpi-process.pid ]] && > /tmp/dietpi-process.pid && ( Print_Process_Animation & echo $! > /tmp/dietpi-process.pid ) + fi + #[[ ! -e /tmp/dietpi-process.pid ]] && > /tmp/dietpi-process.pid && ( Print_Process_Animation & echo $! > /tmp/dietpi-process.pid ) unset Print_Process_Animation @@ -1060,7 +1051,8 @@ $(ps f -eo pid,user,tty,cmd | grep -i [d]ietpi)" G_ERROR_HANDLER_EXITCODE_RETURN=0 #Same as above, but not destroyed during G_ERROR_HANDLER_RESET, allowing us to return it in funcs G_ERROR_HANDLER_COMMAND='' #eg: G_AGI: moooooooo # For export: On error, following entries will be used - G_RUN_CMD_INFO_ONLY=0 #Only print info and retry options, no exit or bug report, sets G_ERROR_HANDLER_ONERROR_EXIT=1 automatically + G_ERROR_HANDLER_NO_FAIL=0 #Always report a success, regardless of the exit code | G_USER_INPUTS=0 is not required for this + G_ERROR_HANDLER_INFO_ONLY=0 #Only print info and retry options, no exit or bug report, sets G_ERROR_HANDLER_ONERROR_EXIT=0 automatically G_ERROR_HANDLER_ONERROR_EXIT=1 #Do we exit the program when the error occurs? 0=no 1=yes G_ERROR_HANDLER_ONERROR_FPLOGFILE='' #FP to logfile, if available G_ERROR_HANDLER_RETRY=0 #Used in func with while loop to re-run func as needed @@ -1074,20 +1066,20 @@ $(ps f -eo pid,user,tty,cmd | grep -i [d]ietpi)" unset G_ERROR_HANDLER_EXITCODE unset G_ERROR_HANDLER_COMMAND + unset G_ERROR_HANDLER_NO_FAIL + unset G_ERROR_HANDLER_INFO_ONLY unset G_ERROR_HANDLER_ONERROR_EXIT unset G_ERROR_HANDLER_ONERROR_FPLOGFILE - unset G_ERROR_HANDLER_RETRY - unset G_RUN_CMD_INFO_ONLY G_ERROR_HANDLER_EXITCODE=0 G_ERROR_HANDLER_COMMAND='' + G_ERROR_HANDLER_NO_FAIL=0 + G_ERROR_HANDLER_INFO_ONLY=0 G_ERROR_HANDLER_ONERROR_EXIT=1 G_ERROR_HANDLER_ONERROR_FPLOGFILE='' - G_ERROR_HANDLER_RETRY=0 - G_RUN_CMD_INFO_ONLY=0 } @@ -1098,7 +1090,7 @@ $(ps f -eo pid,user,tty,cmd | grep -i [d]ietpi)" [[ $l_message ]] || local l_message="$G_ERROR_HANDLER_COMMAND" #Ok - if (( ! $G_ERROR_HANDLER_EXITCODE )); then + if (( ! $G_ERROR_HANDLER_EXITCODE || $G_ERROR_HANDLER_NO_FAIL )); then G_DIETPI-NOTIFY 0 "$l_message" G_ERROR_HANDLER_RESET @@ -1109,7 +1101,7 @@ $(ps f -eo pid,user,tty,cmd | grep -i [d]ietpi)" local send_bugreport=0 local bugreport_id='N/A' - if (( $G_RUN_CMD_INFO_ONLY )); then + if (( $G_ERROR_HANDLER_INFO_ONLY )); then G_ERROR_HANDLER_ONERROR_EXIT=0 @@ -1135,7 +1127,7 @@ $(ps f -eo pid,user,tty,cmd | grep -i [d]ietpi)" G_DIETPI-NOTIFY 1 "$G_ERROR_HANDLER_COMMAND" # Display "please report to dietpi", if its one of our programs - if [[ $G_PROGRAM_NAME && ! $G_RUN_CMD_INFO_ONLY ]]; then + if [[ $G_PROGRAM_NAME && ! $G_ERROR_HANDLER_INFO_ONLY ]]; then G_DIETPI-NOTIFY 2 "$print_report_to_dietpi_info" @@ -1170,7 +1162,7 @@ $(ps f -eo pid,user,tty,cmd | grep -i [d]ietpi)" fi # Display "please report to dietpi", if its one of our programs - if [[ $G_PROGRAM_NAME && ! $G_RUN_CMD_INFO_ONLY ]]; then + if [[ $G_PROGRAM_NAME && ! $G_ERROR_HANDLER_INFO_ONLY ]]; then whip_msg+="$print_report_to_dietpi_info" @@ -1191,14 +1183,14 @@ $(ps f -eo pid,user,tty,cmd | grep -i [d]ietpi)" local retry_menu_options_count=0 aretry_menu_options+=('Retry' 'Re-run the last command that failed'); ((retry_menu_options_count++)) - if ! ps aux | grep -qi '[d]ietpi-config' && (( ! $G_RUN_CMD_INFO_ONLY )); then + if ! ps aux | grep -qi '[d]ietpi-config' && (( ! $G_ERROR_HANDLER_INFO_ONLY )); then aretry_menu_options+=('DietPi-Config' 'Edit network, APT/NTP mirror settings etc'); ((retry_menu_options_count++)) fi - if [[ $G_PROGRAM_NAME && ! $G_RUN_CMD_INFO_ONLY ]]; then + if [[ $G_PROGRAM_NAME && ! $G_ERROR_HANDLER_INFO_ONLY ]]; then aretry_menu_options+=('Send report' 'Uploads bugreport containing system info to DietPi'); ((retry_menu_options_count++)) @@ -1248,7 +1240,7 @@ $(ps f -eo pid,user,tty,cmd | grep -i [d]ietpi)" fi #Github printout - if (( ! $G_RUN_CMD_INFO_ONLY )); then + if (( ! $G_ERROR_HANDLER_INFO_ONLY )); then echo -e " \e[41m @@ -1371,7 +1363,7 @@ $print_logfile_info #URL Connection test # - $@ = URL - # Optional inputs = timeout | retry_max + # Optional inputs = timeout | retry_max | optional_cmd_inputs (eg: --no-check-certificate) # Prompts user to configure network if $G_USER_INPUTS=1 G_CHECK_URL(){ @@ -1379,13 +1371,14 @@ $print_logfile_info local string="$@" local timeout=${timeout:-10} - local retry_max=${retry_max:-5} #Allow for input + local retry_max=${retry_max:-5} local error_connection_failed=0 + local optional_cmd_inputs=${optional_cmd_inputs:-} G_ERROR_HANDLER_COMMAND="Connection test: $string" G_ERROR_HANDLER_ONERROR_FPLOGFILE='/tmp/G_CHECK_URL' - while true + while : do #Allow user choice to configure network on failure @@ -1399,7 +1392,7 @@ $print_logfile_info whiptail --title 'URL Connection Test Failed' --yesno "DietPi was unable to establish a connection:\n - $string\n\nIf problems persist, the URL may be offline/unreachable.\n\nWould you like to configure network settings and try again?" --yes-button "Ok" --no-button "Exit" --defaultno --backtitle "$WHIP_BACKTITLE" 15 80 if (( ! $? )); then - whiptail --title 'Launching DietPi-Config' --msgbox "DietPi-Config will now be started.\nUse the Network Options menu to change and test your network settings.\n\nWhen completed, exit DietPi-Config to resume." --backtitle "Launching DietPi-Config" 14 60 + whiptail --title 'Launching DietPi-Config' --msgbox 'DietPi-Config will now be started.\nUse the Network Options menu to change and test your network settings.\n\nWhen completed, exit DietPi-Config to resume.' --backtitle "Launching DietPi-Config" 14 60 /DietPi/dietpi/dietpi-config 8 1 #User aborted, exit now with current error information @@ -1427,7 +1420,7 @@ $print_logfile_info G_DIETPI-NOTIFY -2 "($i/$retry_max) Testing connection to $string, please wait..." - wget --spider --timeout=$timeout --tries=1 "$string" &> /tmp/G_CHECK_URL + wget --spider $optional_cmd_inputs --timeout=$timeout --tries=1 "$string" &> /tmp/G_CHECK_URL G_ERROR_HANDLER_EXITCODE=$? # Valid if (( ! $G_ERROR_HANDLER_EXITCODE )); then @@ -1470,7 +1463,7 @@ $print_logfile_info local input=$1 local result=1 - while true + while : do mkdir -p $input @@ -1582,7 +1575,7 @@ $print_logfile_info G_DIETPI-NOTIFY 0 "APT installation for: \e[33m$string\e[0m, please wait..." echo -ne '\e[90m' - DEBIAN_FRONTEND=noninteractive apt-get install -y -qq $force_options $string 2>&1 | tee "$G_FP_LOG_APT" + DEBIAN_FRONTEND=noninteractive apt-get install -y -qq $force_options $string 2>&1 | tee $G_FP_LOG_APT G_ERROR_HANDLER_EXITCODE=${PIPESTATUS[0]} echo -e '\e[0m' @@ -1647,13 +1640,13 @@ $print_logfile_info G_DIETPI-NOTIFY 0 "APT removal for: \e[33m$packages_to_remove\e[0m, please wait..." echo -ne '\e[90m' - DEBIAN_FRONTEND=noninteractive apt-get purge -y $packages_to_remove $options 2>&1 | tee "$G_FP_LOG_APT" + DEBIAN_FRONTEND=noninteractive apt-get purge -y $packages_to_remove $options 2>&1 | tee $G_FP_LOG_APT G_ERROR_HANDLER_EXITCODE=${PIPESTATUS[0]} echo -e '\e[0m' else - G_DIETPI-NOTIFY 2 "None of the requested packages are currently installed, aborting." + G_DIETPI-NOTIFY 2 'None of the requested packages are currently installed. Aborting...' fi @@ -1681,7 +1674,7 @@ $print_logfile_info G_DIETPI-NOTIFY 0 'APT autoremove + purge, please wait...' echo -ne '\e[90m' - DEBIAN_FRONTEND=noninteractive apt-get autoremove --purge -y 2>&1 | tee "$G_FP_LOG_APT" + DEBIAN_FRONTEND=noninteractive apt-get autoremove --purge -y 2>&1 | tee $G_FP_LOG_APT G_ERROR_HANDLER_EXITCODE=${PIPESTATUS[0]} echo -e '\e[0m' @@ -1709,7 +1702,7 @@ $print_logfile_info G_DIETPI-NOTIFY 0 'APT fix, please wait...' echo -ne '\e[90m' - DEBIAN_FRONTEND=noninteractive apt-get install -f -y 2>&1 | tee "$G_FP_LOG_APT" + DEBIAN_FRONTEND=noninteractive apt-get install -f -y 2>&1 | tee $G_FP_LOG_APT G_ERROR_HANDLER_EXITCODE=${PIPESTATUS[0]} echo -e '\e[0m' @@ -1737,8 +1730,8 @@ $print_logfile_info G_DIETPI-NOTIFY 0 'APT update, please wait...' echo -ne '\e[90m' - DEBIAN_FRONTEND=noninteractive apt-get clean 2>&1 | tee "$G_FP_LOG_APT" - DEBIAN_FRONTEND=noninteractive apt-get update 2>&1 | tee -a "$G_FP_LOG_APT" + DEBIAN_FRONTEND=noninteractive apt-get clean 2>&1 | tee $G_FP_LOG_APT + DEBIAN_FRONTEND=noninteractive apt-get update 2>&1 | tee -a $G_FP_LOG_APT G_ERROR_HANDLER_EXITCODE=${PIPESTATUS[0]} echo -e '\e[0m' @@ -1773,7 +1766,7 @@ $print_logfile_info fi echo -ne '\e[90m' - DEBIAN_FRONTEND=noninteractive apt-get upgrade -y $options 2>&1 | tee "$G_FP_LOG_APT" + DEBIAN_FRONTEND=noninteractive apt-get upgrade -y $options 2>&1 | tee $G_FP_LOG_APT G_ERROR_HANDLER_EXITCODE=${PIPESTATUS[0]} echo -e '\e[0m' @@ -1811,7 +1804,7 @@ $print_logfile_info G_DIETPI-NOTIFY 0 'APT dist-upgrade, please wait...' echo -ne '\e[90m' - DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -y $force_options 2>&1 | tee "$G_FP_LOG_APT" + DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -y $force_options 2>&1 | tee $G_FP_LOG_APT G_ERROR_HANDLER_EXITCODE=${PIPESTATUS[0]} echo -e '\e[0m' @@ -1910,7 +1903,7 @@ $print_logfile_info G_AG_CHECK_INSTALL_PREREQ rpi-update SKIP_BACKUP=1 SKIP_WARNING=1 G_RUN_CMD rpi-update #PRUNE_MODULES=1 would remove old/unused /lib/modules/* directories, too dangerous if update fails/firmware is unstable? apt-mark hold raspberrypi-bootloader raspberrypi-kernel libraspberrypi-bin libraspberrypi0 - echo -e "$(date)" > /var/lib/dietpi/.G_RPI_UPDATE + date > /var/lib/dietpi/.G_RPI_UPDATE fi @@ -1996,14 +1989,14 @@ $print_logfile_info } #Check available free space on path, against input value (MB) - # - Returns 1=Ok, 0=insufficient space available + # - Returns 0=Ok, 1=insufficient space available # If $2 is not used, returns available space in MB # - $1 = path # - $2 = Optional, free space (MB) # EG: if (( $(G_CHECK_FREESPACE /path 100) )); then G_CHECK_FREESPACE(){ - local return_value=0 + local return_value=1 local input_path="$1" local input_required_space=$2 local available_space=$(df -mP $input_path | sed -n 2p | awk '{print $4}') @@ -2020,7 +2013,7 @@ $print_logfile_info elif (( $available_space > $input_required_space )); then G_DIETPI-NOTIFY 0 "$string_output" - return_value=1 + return_value=0 else @@ -2272,7 +2265,7 @@ $print_logfile_info export G_USER_INPUTS=0 /DietPi/dietpi/dietpi-backup -1 - sed -i '/DEV_GITBRANCH=/c\DEV_GITBRANCH=testing' /DietPi/dietpi.txt + G_CONFIG_INJECT 'DEV_GITBRANCH=' 'DEV_GITBRANCH=testing' /DietPi/dietpi.txt /DietPi/dietpi/dietpi-update -1 /DietPi/dietpi/dietpi-backup 1 @@ -2284,6 +2277,7 @@ $print_logfile_info # - First tries to replace old setting, else commented setting and otherwise adds it to end of file. # - Optionally adds argument to new line after speficied pattern $4. # - PRESERVE=1 G_CONFIG_INJECT allows to keep current setting, if present. + # - BACKUP=1 G_CONFIG_INJECT allows to backup to file before editing, if backup does not yet exist. # - Example: G_CONFIG_INJECT 'prefer-family[[:blank:]=]' 'prefer-family = IPv4' /etc/wgetrc # - Extended regular expressions can be used for the identifying patterns $1 and $4. # - Escape any of: ".+*?&\|^$()[]{} @@ -2295,66 +2289,93 @@ $print_logfile_info local setting="$2" local file="$3" local after="$4" + local error='' syntax_error(){ - [[ $after ]] && after='\nafter line\n '.$after.' ($4)' - G_WHIP_MSG "[FAILED] Syntax error\n -Couldn't add setting (\$2)\n $setting\ninto file (\$3)\n $file$after\n\nNB: -- Please escape any of the following characters with leading backslash (\):\n \".+*?\\|^\$()[]{} -- Within double quotes (\"\"), please escape backslashes (\) doubled:\n \"\\\\\\\\\" results in \"\\\"" + [[ $after ]] && after='after line\n '.$after.' ($4)\n' + [[ $error ]] && error="\n\"grep\" reported the following error:\n $error\n" + + G_WHIP_MSG "[FAILED] Syntax error +$error +Couldn't add setting (\$2) + $setting +into file (\$3) + $file +$after +NB: +- Please escape any of the following characters with leading backslash (\): + \".+*?\\|^\$()[]{} +- Within double quotes (\"\"), please escape backslashes (\) doubled: + \"\\\\\\\\\" results in \"\\\"" + + unset syntax_error } if [[ ! -w $file ]]; then G_WHIP_MSG "[FAILED] '$file' does not exist or cannot be written to by current user.\n -Please verify the existance of the file, retry with proper permissions or apply the setting manually:\n $(sed -E "c\\$setting" <<< '')" +Please verify the existance of the file, retry with proper permissions or apply the setting manually: + $(sed -E "c\\$setting" <<< '')" - elif grep -qE "^[[:blank:]]*$pattern" $file; then + elif error=$(grep -qE "^[[:blank:]]*$pattern" $file 2>&1); then + # As an error within the condition leads to "false", it can be catched only after next condition match - if (( $PRESERVE )); then + if [[ $PRESERVE == 1 ]]; then G_DIETPI-NOTIFY 0 "Current setting in \e[33m$file\e[0m will be preserved: \e[33m$(grep -Em1 "^[[:blank:]]*$pattern" $file | sed 's|\\|\\\\|g')\e[0m" - elif grep -qE "^[[:blank:]]*$setting([[:space:]]|$)" $file; then + elif error=$(grep -qE "^[[:blank:]]*$setting([[:space:]]|$)" $file 2>&1); then G_DIETPI-NOTIFY 0 "Desired setting in \e[33m$file\e[0m was already set: \e[33m$(grep -Em1 "^[[:blank:]]*$pattern" $file | sed 's|\\|\\\\|g')\e[0m" else + [[ $error ]] && syntax_error && return 1 + [[ $BACKUP == 1 && ! -f $file.bak ]] && cp -a $file $file.bak && G_DIETPI-NOTIFY 2 "Config file backup created: \e[33m$file\e[0m" sed -Ei "0,\|^[[:blank:]]*$pattern.*$|s||$setting|" $file (( $? )) && syntax_error && return 1 G_DIETPI-NOTIFY 0 "Setting in \e[33m$file\e[0m adjusted: \e[33m$(sed -E "c\\$setting" <<< '' | sed 's|\\|\\\\|g')\e[0m" fi - elif grep -qE "^[[:blank:]#;]*$pattern" $file; then + elif error=$(grep -qE "^[[:blank:]#;]*$pattern" $file 2>&1); then + [[ $error ]] && syntax_error && return 1 + [[ $BACKUP == 1 && ! -f $file.bak ]] && cp -a $file $file.bak && G_DIETPI-NOTIFY 2 "Config file backup created: \e[33m$file\e[0m" sed -Ei "0,\|^[[:blank:]#;]*$pattern.*$|s||$setting|" $file (( $? )) && syntax_error && return 1 G_DIETPI-NOTIFY 0 "Comment in \e[33m$file\e[0m converted to setting: \e[33m$(sed -E "c\\$setting" <<< '' | sed 's|\\|\\\\|g')\e[0m" else + [[ $error ]] && syntax_error && return 1 if [[ $after ]]; then - if grep -qE "^[[:blank:]]*$after" $file; then + if error=$(grep -qE "^[[:blank:]]*$after" $file 2>&1); then + [[ $BACKUP == 1 && ! -f $file.bak ]] && cp -a $file $file.bak && G_DIETPI-NOTIFY 2 "Config file backup created: \e[33m$file\e[0m" sed -Ei "0,\|^[[:blank:]]*$after.*$|s||&\n$setting|" $file (( $? )) && syntax_error && return 1 G_DIETPI-NOTIFY 0 "Added setting \e[33m$(sed -E "c\\$setting" <<< '' | sed 's|\\|\\\\|g')\e[0m to \e[33m$file\e[0m after line \e[33m$(grep -Em1 "^[[:blank:]]*$after" $file | sed 's|\\|\\\\|g')\e[0m" else + [[ $error ]] && syntax_error && return 1 - G_WHIP_MSG "[FAILED] Setting could not be added after desired line.\n -The pattern\n $(sed -E "c\\$after" <<< '')\ncould not be found in file\n $file\n -Please retry with valid parameter (\$4) or apply the setting manually:\n $(sed -E "c\\$setting" <<< '')" + G_WHIP_MSG "[FAILED] Setting could not be added after desired line.\n +The pattern + $(sed -E "c\\$after" <<< '') +could not be found in file + $file\n +Please retry with valid parameter (\$4) or apply the setting manually: + $(sed -E "c\\$setting" <<< '')" fi else + [[ $BACKUP == 1 && ! -f $file.bak ]] && cp -a $file $file.bak && G_DIETPI-NOTIFY 2 "Config file backup created: \e[33m$file\e[0m" # The following sed does not work on empty files: [[ ! -s $file ]] && echo '# Added by DietPi:' >> $file sed -Ei "\$s|\$|\n$setting|" $file @@ -2365,8 +2386,6 @@ Please retry with valid parameter (\$4) or apply the setting manually:\n $(sed - fi - unset syntax_error - } #----------------------------------------------------------------------------------- diff --git a/dietpi/func/dietpi-obtain_hw_model b/dietpi/func/dietpi-obtain_hw_model index 30981e6651..260c4016ea 100644 --- a/dietpi/func/dietpi-obtain_hw_model +++ b/dietpi/func/dietpi-obtain_hw_model @@ -105,8 +105,8 @@ #Set locale for all scripts, prevents incorrect scraping export LANG=en_GB.UTF-8 export LC_ALL=en_GB.UTF-8 - #Ensure we are in users home dir: https://github.com/Fourdee/DietPi/issues/905#issuecomment-298223705 - cd $HOME + #Ensure we are in /tmp dir: https://github.com/Fourdee/DietPi/issues/2050#issuecomment-419901350 + cd /tmp #----------------------------------------------------------------------------------- #Import DietPi-Globals --------------------------------------------------------------- #. /DietPi/dietpi/func/dietpi-globals diff --git a/dietpi/func/dietpi-set_cpu b/dietpi/func/dietpi-set_cpu index 586c070470..657de5650a 100644 --- a/dietpi/func/dietpi-set_cpu +++ b/dietpi/func/dietpi-set_cpu @@ -80,29 +80,34 @@ #Apply CPU max/min frequency # - Intel based 0-100%: - if [[ -r /sys/devices/system/cpu/intel_pstate/max_perf_pct ]]; then + if [[ -f /sys/devices/system/cpu/intel_pstate/max_perf_pct ]]; then - G_DIETPI-NOTIFY 2 "Setting CPU Frequency % Range : Max = $CPU_MAX_FREQ % | Min = $CPU_MIN_FREQ %" - if disable_error=1 G_CHECK_VALIDINT $CPU_MAX_FREQ; then + if ! disable_error=1 G_CHECK_VALIDINT $CPU_MAX_FREQ; then - echo $CPU_MAX_FREQ > /sys/devices/system/cpu/intel_pstate/max_perf_pct + CPU_MAX_FREQ=100 fi - if disable_error=1 G_CHECK_VALIDINT $CPU_MIN_FREQ; then + if ! disable_error=1 G_CHECK_VALIDINT $CPU_MIN_FREQ; then - echo $CPU_MIN_FREQ > /sys/devices/system/cpu/intel_pstate/min_perf_pct + CPU_MIN_FREQ=25 fi + echo $CPU_MAX_FREQ > /sys/devices/system/cpu/intel_pstate/max_perf_pct + echo $CPU_MIN_FREQ > /sys/devices/system/cpu/intel_pstate/min_perf_pct + + G_DIETPI-NOTIFY 2 "Applied CPU Frequency Limits : Max = $CPU_MAX_FREQ % | Min = $CPU_MIN_FREQ %" + if [[ -f /sys/devices/system/cpu/intel_pstate/no_turbo ]]; then echo $CPU_DISABLE_TURBO > /sys/devices/system/cpu/intel_pstate/no_turbo - G_DIETPI-NOTIFY 2 "Setting Turbo Mode : $CPU_DISABLE_TURBO (1=disabled)" + G_DIETPI-NOTIFY 2 "Applied Turbo Mode : $CPU_DISABLE_TURBO (1=disabled)" fi - else + # - Standard via kernel (Hz) + elif [[ -f /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq ]]; then # Reset to defaults if no/invalid entry local converted_hz_value_max=-1 #-1 indicates reset CPU freqs diff --git a/dietpi/func/dietpi-set_dphys-swapfile b/dietpi/func/dietpi-set_dphys-swapfile index 526be03967..df1e0f0fd3 100644 --- a/dietpi/func/dietpi-set_dphys-swapfile +++ b/dietpi/func/dietpi-set_dphys-swapfile @@ -14,7 +14,7 @@ # Usage: # - $1 = 0=disable, 1=enable+autosize, >=2=enable+size # - $2 = optional location - # - /DietPi/dietpi/func/dietpi-set_dphys-swapfile = Print current config size and location + # - /DietPi/dietpi/func/dietpi-set_dphys-swapfile = Print current swap size and location #//////////////////////////////////// #Import DietPi-Globals --------------------------------------------------------------- @@ -35,7 +35,7 @@ fi SWAP_LOCATION_TARGET="$SWAP_LOCATION" - if [[ -n $2 ]]; then + if [[ $2 ]]; then SWAP_LOCATION_TARGET="$2" @@ -51,7 +51,7 @@ } - Update_Conf(){ + Update_DietPi_Conf(){ # DietPi.txt sed -i "/^[[:blank:]]*AUTO_SETUP_SWAPFILE_SIZE=/c\AUTO_SETUP_SWAPFILE_SIZE=$SWAP_SIZE" /DietPi/dietpi.txt @@ -77,64 +77,70 @@ Swap_Disable(){ - G_DIETPI-NOTIFY 3 'DietPi-Swapfile' 'Disable swapfile' + G_DIETPI-NOTIFY 0 'Disable swapfile' Delete_Swapfile SWAP_SIZE=0 SWAP_LOCATION='/var/swap' - Update_Conf + Update_DietPi_Conf Update_Tmp } Swap_Enable(){ + # - Create temp file for freespace check, and, fs_type scrape + > "$SWAP_LOCATION_TARGET" + + #Free spacey, checkey weckey + if ! G_CHECK_FREESPACE "$SWAP_LOCATION_TARGET" $SWAP_SIZE_TARGET; then + + G_DIETPI-NOTIFY 1 'Unable to generate swapfile due to insufficient disk space. Swap has be disabled.' + #Exclude devices # - BBB - if (( $G_HW_MODEL == 71 )); then + elif (( $G_HW_MODEL == 71 )); then - G_DIETPI-NOTIFY 2 "Skipping swapfile generation for $G_HW_MODEL_DESCRIPTION" - exit 0 - - fi + G_DIETPI-NOTIFY 2 "Disabled swapfile generation for $G_HW_MODEL_DESCRIPTION" - Delete_Swapfile + #Create new swappey whappey + else - SWAP_SIZE=$SWAP_SIZE_TARGET - SWAP_LOCATION="$SWAP_LOCATION_TARGET" - Update_Conf + SWAP_SIZE=$SWAP_SIZE_TARGET + SWAP_LOCATION="$SWAP_LOCATION_TARGET" - G_DIETPI-NOTIFY 3 'DietPi-Swapfile' 'Generating new swapfile' - G_DIETPI-NOTIFY 2 "Size = $SWAP_SIZE MB" - G_DIETPI-NOTIFY 2 "Location = $SWAP_LOCATION" + G_DIETPI-NOTIFY 0 'Generating new swapfile' + G_DIETPI-NOTIFY 2 "Size = $SWAP_SIZE MB" + G_DIETPI-NOTIFY 2 "Location = $SWAP_LOCATION" - echo '' > "$SWAP_LOCATION" #create temp file to ensure findmnt returns result - local fs_type="$(findmnt -n -o FSTYPE -T $SWAP_LOCATION)" - rm "$SWAP_LOCATION" &> /dev/null + local fs_type="$(findmnt -n -o FSTYPE -T $SWAP_LOCATION)" - #Pre-allocate for filesystems which do no support quick-allocate with fallocate - if [[ $fs_type == 'f2fs' || $fs_type == 'xfs' || $fs_type == 'vfat' ]]; then + #Pre-allocate for filesystems which do no support quick-allocate with fallocate + if [[ $fs_type == 'f2fs' || $fs_type == 'xfs' || $fs_type == 'vfat' ]]; then - G_RUN_CMD dd if=/dev/zero of=$SWAP_LOCATION bs=4K count=$(( $SWAP_SIZE * 1024 / 4 )) + G_RUN_CMD dd if=/dev/zero of=$SWAP_LOCATION bs=4K count=$(( $SWAP_SIZE * 1024 / 4 )) - else + else - G_RUN_CMD fallocate -l $SWAP_SIZE'M' $SWAP_LOCATION + G_RUN_CMD fallocate -l $SWAP_SIZE'M' $SWAP_LOCATION - fi + fi - G_RUN_CMD mkswap $SWAP_LOCATION - chmod 600 "$SWAP_LOCATION" + G_RUN_CMD mkswap $SWAP_LOCATION + chmod 600 "$SWAP_LOCATION" - G_RUN_CMD swapon $SWAP_LOCATION + G_RUN_CMD swapon $SWAP_LOCATION - cat << _EOF_ >> /etc/fstab + cat << _EOF_ >> /etc/fstab $SWAP_LOCATION none swap sw 0 0 _EOF_ - Update_Tmp + Update_DietPi_Conf + Update_Tmp + + fi } @@ -142,36 +148,33 @@ _EOF_ # Main Loop #///////////////////////////////////////////////////////////////////////////////////// #Info mode - Print Size / Location - if [[ -z $1 ]]; then + if [[ ! $1 ]]; then echo -e "$SWAP_SIZE $SWAP_LOCATION" - #Disabled - elif (( $SWAP_SIZE_TARGET == 0 )); then + #Remove/Create swap + else + G_DIETPI-NOTIFY 3 "$G_PROGRAM_NAME" 'Apply' + + #Always reset/remove existing swap Swap_Disable - #Enabled (Auto) - elif (( $SWAP_SIZE_TARGET == 1 )); then + #Auto size? + if (( $SWAP_SIZE_TARGET == 1 )); then - SWAP_SIZE_TARGET=$(( 2048 - $(free -m | grep -m1 'Mem:' | awk '{print $2}') )) - if (( $SWAP_SIZE_TARGET < 0 )); then + SWAP_SIZE_TARGET=$(( 2048 - $(free -m | grep -m1 'Mem:' | awk '{print $2}') )) - Swap_Disable + fi - else + #Configure new swapfile? + if (( $SWAP_SIZE_TARGET > 0 )); then Swap_Enable fi - #Enabled (manual) - elif (( $SWAP_SIZE_TARGET >= 2 )); then - - Swap_Enable - fi - #----------------------------------------------------------------------------------- exit 0 #----------------------------------------------------------------------------------- diff --git a/dietpi/func/dietpi-set_hardware b/dietpi/func/dietpi-set_hardware index 75b65406a3..1051917d62 100644 --- a/dietpi/func/dietpi-set_hardware +++ b/dietpi/func/dietpi-set_hardware @@ -94,15 +94,21 @@ $FP_SCRIPT lcdpanel target_panel (none to remove all) # - Enable RPi Camera module G_CONFIG_INJECT 'start_x=' 'start_x=1' $FP_RPI_CONFIG + # - v4l2 module (motioneye /dev/video0) + G_CONFIG_INJECT 'bcm2835-v4l2' 'bcm2835-v4l2' /etc/modules + # - requires 128MB memory split min. if (( $(grep -m1 'gpu_mem_' $FP_RPI_CONFIG | sed 's/^.*=//g') < 128 )); then - /DietPi/dietpi/func/dietpi-set_hardware gpumemsplit 128 + local tmp=$INPUT_DEVICE_VALUE + INPUT_DEVICE_VALUE=128 - fi + Gpu_Memory_Split_Main - # - v4l2 module (motioneye /dev/video0) - G_CONFIG_INJECT 'bcm2835-v4l2' 'bcm2835-v4l2' /etc/modules + INPUT_DEVICE_VALUE=$tmp + unset tmp + + fi elif [[ $INPUT_DEVICE_VALUE == 'disable' ]]; then diff --git a/dietpi/func/dietpi-set_software b/dietpi/func/dietpi-set_software index 3d6c5810bf..53d4c79f33 100644 --- a/dietpi/func/dietpi-set_software +++ b/dietpi/func/dietpi-set_software @@ -265,7 +265,6 @@ _EOF_ systemctl stop systemd-timesyncd systemctl disable systemd-timesyncd - #apt-mark auto dbus #??? fi diff --git a/dietpi/func/dietpi-set_userdata b/dietpi/func/dietpi-set_userdata index 986801f944..aac3ee834a 100644 --- a/dietpi/func/dietpi-set_userdata +++ b/dietpi/func/dietpi-set_userdata @@ -133,8 +133,8 @@ # "-BM" => result in MiB actual disc usage, respecting disk block size, e.g. "144M" # "-b" => result in bytes apparent size, ignoring disk block size, e.g. "142662603" # Trailing slash required with "du" to correctly check symlink target in case - FREESPACE_REQUIRED_SOURCE=$(du -sBM "$SOURCE_DIRECTORY/" | awk '{print $1}') - if (( ! $(G_CHECK_FREESPACE "$TARGET_DIRECTORY" ${FREESPACE_REQUIRED_SOURCE/M/}) )); then + FREESPACE_REQUIRED_SOURCE=$(du -sBM "$SOURCE_DIRECTORY/" | awk '{print $1}' | sed 's/[^0-9]*//g') + if ! G_CHECK_FREESPACE "$TARGET_DIRECTORY" $FREESPACE_REQUIRED_SOURCE; then LOGFILE_OUTPUT_TEXT="ERROR: Not enough free space in target directory $TARGET_DIRECTORY.\n - Required $FREESPACE_REQUIRED_SOURCE" EXIT_CODE=1 diff --git a/dietpi/login b/dietpi/login index dceb8516ea..b005b3b145 100644 --- a/dietpi/login +++ b/dietpi/login @@ -35,6 +35,7 @@ G_HW_MODEL=$(sed -n 1p /DietPi/dietpi/.hw_model) G_DISTRO=$(sed -n 3p /DietPi/dietpi/.hw_model) FP_DIETPI_FIRSTRUNSETUP_LOG='/var/tmp/dietpi/logs/dietpi-firstrun-setup.log' + FP_TMP_DIETPI_FIRSTRUNSETUP_LOG="/tmp/dietpi-firstrun-setup.log" #///////////////////////////////////////////////////////////////////////////////////// #DietPi-Autostart @@ -196,23 +197,20 @@ done - #Start DietPi-Software if required - G_DIETPI_INSTALL_STAGE=$( $FP_EMR @@ -72,7 +72,9 @@ Update_EMR_Index - elif (( $EMR_INDEX == 1 )); then + fi + + if (( $EMR_INDEX == 1 )); then #RAMlog 0 free space check due to issues with failing DietPi cron jobs in v6.11 if (( $(G_CHECK_FREESPACE /var/log) < 2 )); then @@ -84,7 +86,9 @@ Update_EMR_Index - # elif (( $EMR_INDEX == 2 )); then + fi + + # if (( $EMR_INDEX == 2 )); then #Date fix, due to NTP > systemd-timesyncd, unknown cause: https://github.com/Fourdee/DietPi/issues/2017 # if (( $(date +%Y%m%d) < 20180820 )); then @@ -96,13 +100,14 @@ # fi # Update_EMR_Index + # fi - # elif (( $EMR_INDEX == 3 )); then + # if (( $EMR_INDEX == 3 )); then #echo -e 'nothing here yet' # Update_EMR_Index - fi + # fi #///////////////////////////////////////////////////////////////////////////////////// #Incremental patch system: @@ -841,15 +846,6 @@ _EOF_ fi - fi - #------------------------------------------------------------------------------- - #Sparky kernel update: https://github.com/sparky-sbc/sparky-test/tree/master/dsd-marantz - if (( $G_HW_MODEL == 70 )); then - - # patches - G_RUN_CMD wget https://raw.githubusercontent.com/sparky-sbc/sparky-test/master/dsd-marantz/snd-usb-audio.ko -O /lib/modules/3.10.38/kernel/sound/usb/snd-usb-audio.ko - G_RUN_CMD wget https://raw.githubusercontent.com/sparky-sbc/sparky-test/master/dsd-marantz/snd-usbmidi-lib.ko -O /lib/modules/3.10.38/kernel/sound/usb/snd-usbmidi-lib.ko - fi #------------------------------------------------------------------------------- #DietPi-Survey rework phase 2: https://github.com/Fourdee/DietPi/issues/1827#issuecomment-395970075, https://github.com/Fourdee/DietPi/pull/1884 @@ -1065,9 +1061,6 @@ _EOF_ # - Disable cron.minutely, if unused to reduce cron executions and logs (( $(find /etc/cron.minutely/ | wc -l) > 2 )) || sed -i '\|cron\.minutely|s|^\*/[0-9]*[[:blank:]]|#*/0 |' /etc/crontab #------------------------------------------------------------------------------- - # - Remove fake-hwclock, if real hwclock is available - hwclock &> /dev/null && apt-mark auto fake-hwclock - #------------------------------------------------------------------------------- #Remove "ntfs-3g" respectively "hfsplus", if no attached drive requires it. local fs_list=$(lsblk -nro FSTYPE) grep -q 'ntfs' <<< $fs_list || apt-mark auto ntfs-3g @@ -1135,9 +1128,6 @@ _EOF_ elif (( $G_DIETPI_VERSION_SUB == 13 )); then - #------------------------------------------------------------------------------- - #Survey/BugReport SFTP uploads, add same cert for IP access: https://github.com/Fourdee/DietPi/issues/2022 - G_CONFIG_INJECT '185.101.93.93 ' '185.101.93.93 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDE6aw3r6aOEqendNu376iiCHr9tGBIWPgfrLkzjXjEsHGyVSUFNnZt6pftrDeK7UX\+qX4FxOwQlugG4fymOHbimRCFiv6cf7VpYg1Ednquq9TLb7/cIIbX8a6AuRmX4fjdGuqwmBq3OG7ZksFcYEFKt5U4mAJIaL8hXiM2iXjgY02LqiQY/QWATsHI4ie9ZOnwrQE\+Rr6mASN1BVFuIgyHIbwX54jsFSnZ/7CdBMkuAd9B8JkxppWVYpYIFHE9oWNfjh/epdK8yv9Oo6r0w5Rb\+4qaAc5g\+RAaknHeV6Gp75d2lxBdCm5XknKKbGma2\+/DfoE8WZTSgzXrYcRlStYN' /root/.ssh/known_hosts #------------------------------------------------------------------------------- #Encrypt and secure GLOBAL_PW used by DietPi-Software: https://github.com/Fourdee/DietPi/issues/2021 if [[ ! -r '/var/lib/dietpi/dietpi-software/.GLOBAL_PW.bin' ]]; then @@ -1192,6 +1182,72 @@ _EOF_ fi #------------------------------------------------------------------------------- + elif (( $G_DIETPI_VERSION_SUB == 14 )); then + + #------------------------------------------------------------------------------- + #Survey/BugReport SFTP uploads, add cert for access: https://github.com/Fourdee/DietPi/issues/2022 + sed -i '/^dietpi.com/d' /root/.ssh/known_hosts + sed -i '/^185.101.93.93/d' /root/.ssh/known_hosts + G_CONFIG_INJECT 'ssh.dietpi.com ' 'ssh.dietpi.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDE6aw3r6aOEqendNu376iiCHr9tGBIWPgfrLkzjXjEsHGyVSUFNnZt6pftrDeK7UX\+qX4FxOwQlugG4fymOHbimRCFiv6cf7VpYg1Ednquq9TLb7/cIIbX8a6AuRmX4fjdGuqwmBq3OG7ZksFcYEFKt5U4mAJIaL8hXiM2iXjgY02LqiQY/QWATsHI4ie9ZOnwrQE\+Rr6mASN1BVFuIgyHIbwX54jsFSnZ/7CdBMkuAd9B8JkxppWVYpYIFHE9oWNfjh/epdK8yv9Oo6r0w5Rb\+4qaAc5g\+RAaknHeV6Gp75d2lxBdCm5XknKKbGma2\+/DfoE8WZTSgzXrYcRlStYN' /root/.ssh/known_hosts + #------------------------------------------------------------------------------- + #Reinstall fake-hwclock: https://github.com/Fourdee/DietPi/issues/2035#issuecomment-416345155 + G_AGI fake-hwclock + #------------------------------------------------------------------------------- + #Disable net offload for devices which are prone to stability issues with it enabled (@carlosedp): https://github.com/Fourdee/DietPi/issues/2028#issue-352323603 + for file in /etc/network/if-up.d/* + do + + if [[ $file != 'dietpi-disable_offload' ]]; then + + if (( $(grep -ci -m1 '\$ETHTOOL -K "\$IFACE" rx off tx off' $file) )); then + + rm $file + echo -e "DEBUG: removed $file" + + fi + + fi + + done + chmod +x /etc/network/if-up.d/dietpi-disable_offload + #------------------------------------------------------------------------------- + #Sparky kernel update: https://github.com/sparky-sbc/sparky-test/tree/master/dsd-marantz + if (( $G_HW_MODEL == 70 )); then + + # patches + G_RUN_CMD wget https://raw.githubusercontent.com/sparky-sbc/sparky-test/master/dsd-marantz/snd-usb-audio.ko -O /lib/modules/3.10.38/kernel/sound/usb/snd-usb-audio.ko + G_RUN_CMD wget https://raw.githubusercontent.com/sparky-sbc/sparky-test/master/dsd-marantz/snd-usbmidi-lib.ko -O /lib/modules/3.10.38/kernel/sound/usb/snd-usbmidi-lib.ko + + fi + #------------------------------------------------------------------------------- + #Reinstalls: + # MPD: https://github.com/Fourdee/DietPi/issues/2032#issuecomment-415559451 + # PlexPy: https://github.com/Fourdee/DietPi/issues/2047 + if (( $G_DIETPI_INSTALL_STAGE == 1 )); then + + /DietPi/dietpi/dietpi-software reinstall 128 146 + + fi + #------------------------------------------------------------------------------- + #Update DietPi-Sync save file to new format + if [[ -f /DietPi/dietpi/.dietpi-sync_settings ]] && ! grep -q '^FP_SOURCE=' /DietPi/dietpi/.dietpi-sync_settings; then + + cp /DietPi/dietpi/.dietpi-sync_settings /DietPi/dietpi/.dietpi-sync_settings_bk + cat << _EOF_ > /DietPi/dietpi/.dietpi-sync_settings +FP_SOURCE=$(sed -n 1p /DietPi/dietpi/.dietpi-sync_settings_bk) +FP_TARGET=$(sed -n 2p /DietPi/dietpi/.dietpi-sync_settings_bk) +SYNC_DELETE_MODE=$(sed -n 3p /DietPi/dietpi/.dietpi-sync_settings_bk) +SYNC_COMPRESSION=$(sed -n 4p /DietPi/dietpi/.dietpi-sync_settings_bk) +SYNC_CRONDAILY=$(sed -n 5p /DietPi/dietpi/.dietpi-sync_settings_bk) +_EOF_ + + fi + #------------------------------------------------------------------------------- + #Preboot script addition + systemctl daemon-reload + systemctl enable dietpi-preboot.service + #------------------------------------------------------------------------------- + fi #------------------------------------------------------------------------------- diff --git a/dietpi/preboot b/dietpi/preboot new file mode 100644 index 0000000000..bcabce3f1a --- /dev/null +++ b/dietpi/preboot @@ -0,0 +1,366 @@ +#!/bin/bash +{ + #//////////////////////////////////// + # DietPi PreBoot Script + # + #//////////////////////////////////// + # Created by Daniel Knight / daniel.knight@dietpi.com / dietpi.com + # + #//////////////////////////////////// + # + # Info: + # - filename /DietPi/dietpi/preboot + # - activates on boot from dietpi-preboot.service, runs before dietpi-boot.service and networking + #//////////////////////////////////// + + #Import DietPi-Globals --------------------------------------------------------------- + /DietPi/dietpi/func/dietpi-obtain_hw_model # Running for the 1st time + . /DietPi/dietpi/func/dietpi-globals + export G_PROGRAM_NAME='DietPi-PreBoot' + G_INIT + #Import DietPi-Globals --------------------------------------------------------------- + + #///////////////////////////////////////////////////////////////////////////////////// + #Globals + #///////////////////////////////////////////////////////////////////////////////////// + + RPi_Set_Clock_Speeds(){ + + #RPi's + if (( $G_HW_MODEL < 10 )); then + + #If no overclocking is set. set values to current (used in dietpi-config as reference for overclocking / current values) + if grep -q '^#over_voltage=' /DietPi/config.txt && + grep -q '^#arm_freq=' /DietPi/config.txt && + grep -q '^#core_freq=' /DietPi/config.txt && + grep -q '^#sdram_freq=' /DietPi/config.txt; then + + #RPi v1 - Set safe clock + if (( $G_HW_MODEL < 2 )); then + + sed -i '/over_voltage=/c\over_voltage=2' /DietPi/config.txt + 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=400' /DietPi/config.txt + + #Zero + if [[ ${G_HW_MODEL_DESCRIPTION,,} == *'zero'* ]]; then + + sed -i '/over_voltage=/c\#over_voltage=0' /DietPi/config.txt + 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 + + #RPi v2 + elif (( $G_HW_MODEL == 2 )); then + + sed -i '/over_voltage=/c\#over_voltage=0' /DietPi/config.txt + 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 + + #RPi v3 + elif (( $G_HW_MODEL == 3 )); then + + sed -i '/over_voltage=/c\#over_voltage=0' /DietPi/config.txt + sed -i '/core_freq=/c\#core_freq=400' /DietPi/config.txt + sed -i "/temp_limit=/c\temp_limit=75" /DietPi/config.txt # https://github.com/Fourdee/DietPi/issues/356 + + local arm_freq=1200 + local sdram_freq=450 + if [[ ${G_HW_MODEL_DESCRIPTION,,} == *'rpi 3 model b+'* ]]; then + + arm_freq=1400 + sdram_freq=500 + + fi + + sed -i "/arm_freq=/c\#arm_freq=$arm_freq" /DietPi/config.txt + sed -i "/sdram_freq=/c\#sdram_freq=$sdram_freq" /DietPi/config.txt + + fi + + fi + + fi + + } + + Apply_DietPi_FirstRun_Settings(){ + + #---------------------------------------------------------------- + #Automation + #---------------------------------------------------------------- + # - Grab available network devices + /DietPi/dietpi/func/obtain_network_details + + # - Generate Swapfile + /DietPi/dietpi/func/dietpi-set_dphys-swapfile $(grep -m1 '^[[:blank:]]*AUTO_SETUP_SWAPFILE_SIZE=' /DietPi/dietpi.txt | sed 's/^.*=//') "$(grep -m1 '^[[:blank:]]*AUTO_SETUP_SWAPFILE_LOCATION=' /DietPi/dietpi.txt | sed 's/.*=//')" + + # - IPversion preference: https://github.com/Fourdee/DietPi/issues/472 + /DietPi/dietpi/func/dietpi-set_hardware preferipversion "$(grep -m1 '^[[:blank:]]*CONFIG_PREFER_IPVERSION=' /DietPi/dietpi.txt | sed 's/^.*=//')" + + # - Apply Timezone + local autoinstall_timezone="$(grep -m1 '^[[:blank:]]*AUTO_SETUP_TIMEZONE=' /DietPi/dietpi.txt | sed 's/^[^=]*=//' )" + if [[ $autoinstall_timezone != $( /dev/null + dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key &> /dev/null + dropbearkey -t ecdsa -f /etc/dropbear/dropbear_ecdsa_host_key &> /dev/null + dropbearkey -t dss -f /etc/dropbear/dropbear_dss_host_key &> /dev/null + + # - Recreate machine-id: https://github.com/Fourdee/DietPi/issues/2015 + rm /etc/machine-id &> /dev/null + rm /var/lib/dbus/machine-id &> /dev/null + systemd-machine-id-setup + + # Failsafe + killall -w dhclient &> /dev/null + + local index_eth=$(sed -n 1p /DietPi/dietpi/.network) + local index_wlan=$(sed -n 2p /DietPi/dietpi/.network) + + # Replace all eth0 and wlan0 values to the indexs DietPi has found. + sed -i "s/eth0/eth$index_eth/g" /etc/network/interfaces + sed -i "s/wlan0/wlan$index_wlan/g" /etc/network/interfaces + + # Grab user requested settings from /dietpi.txt + local ethernet_enabled=$(grep -ci -m1 '^[[:blank:]]*AUTO_SETUP_NET_ETHERNET_ENABLED=1' /DietPi/dietpi.txt) + local wifi_enabled=$(grep -ci -m1 '^[[:blank:]]*AUTO_SETUP_NET_WIFI_ENABLED=1' /DietPi/dietpi.txt) + + local use_static=$(grep -ci -m1 '^[[:blank:]]*AUTO_SETUP_NET_USESTATIC=1' /DietPi/dietpi.txt) + local static_ip="$(grep -m1 '^[[:blank:]]*AUTO_SETUP_NET_STATIC_IP=' /DietPi/dietpi.txt | sed 's/^[^=]*=//')" + local static_mask="$(grep -m1 '^[[:blank:]]*AUTO_SETUP_NET_STATIC_MASK=' /DietPi/dietpi.txt | sed 's/^[^=]*=//')" + local static_gateway="$(grep -m1 '^[[:blank:]]*AUTO_SETUP_NET_STATIC_GATEWAY=' /DietPi/dietpi.txt | sed 's/^[^=]*=//')" + local static_dns="$(grep -m1 '^[[:blank:]]*AUTO_SETUP_NET_STATIC_DNS=' /DietPi/dietpi.txt | sed 's/^[^=]*=//')" + + # Wifi + if (( $wifi_enabled )); then + + #Enable Wlan, disable Eth + ethernet_enabled=0 + sed -i "/allow-hotplug wlan/c\allow-hotplug wlan$index_wlan" /etc/network/interfaces + sed -i "/allow-hotplug eth/c\#allow-hotplug eth$index_eth" /etc/network/interfaces + + # - Apply global SSID/Keys from dietpi.txt to wpa_supp + /DietPi/dietpi/func/dietpi-set_hardware wificreds set + + # Ethernet + elif (( $ethernet_enabled )); then + + #Enable Eth, disable Wlan + sed -i "/allow-hotplug eth/c\allow-hotplug eth$index_eth" /etc/network/interfaces + sed -i "/allow-hotplug wlan/c\#allow-hotplug wlan$index_wlan" /etc/network/interfaces + + wifi_enabled=0 + /DietPi/dietpi/func/dietpi-set_hardware wifimodules disable + + fi + + # Static IPs + if (( $use_static )); then + + #enable dns-nameservers + sed -i 's/^#dns-nameservers/dns-nameservers/g' /etc/network/interfaces + + if (( $wifi_enabled )); then + + sed -i "/iface wlan/c\iface wlan$index_wlan inet static" /etc/network/interfaces + + elif (( $ethernet_enabled )); then + + sed -i "/iface eth/c\iface eth$index_eth inet static" /etc/network/interfaces + + fi + + sed -i "/address/c\address $static_ip" /etc/network/interfaces + sed -i "/netmask/c\netmask $static_mask" /etc/network/interfaces + sed -i "/gateway/c\gateway $static_gateway" /etc/network/interfaces + sed -i "/dns-nameservers/c\dns-nameservers $static_dns" /etc/network/interfaces + + fi + + # - reload networking + systemctl daemon-reload + + # Failsafe + systemctl stop networking.service + killall -w dhclient &> /dev/null + + # - Bring up networking (this is required, not sure what systemD isnt doing here, as this service runs before networking?!!?) + if (( $wifi_enabled )); then + + ifup wlan$index_wlan + + elif (( $ethernet_enabled )); then + + ifup eth$index_eth + + fi + + } + + Run_Init(){ + + #---------------------------------------------------------------- + #Apply DietPi CPU Governor and settings + /DietPi/dietpi/func/dietpi-set_cpu & + #---------------------------------------------------------------- + #Apply LED triggers if set + /DietPi/dietpi/func/dietpi-led_control 1 & + #---------------------------------------------------------------- + #RPi Specials + # set volume to -0.1db | We have to do it here because sound card modules (dietpi-set_hardware) are not enabled on the fly, requires a reboot. + # Disable RPi hdmi output if set in dietpi.txt + if (( $G_HW_MODEL < 10 )); then + + which amixer &> /dev/null && amixer set PCM -- -010 & + if grep -qi '^[[:blank:]]*CONFIG_HDMI_OUTPUT=0' /DietPi/dietpi.txt; then + + /opt/vc/bin/tvservice -o &> /dev/null & + + fi + + fi + #---------------------------------------------------------------- + + } + + Main(){ + + #Pre-Installed image, 1st run + if (( $G_DIETPI_INSTALL_STAGE == 2 )); then + + echo 0 + + fi + + #Normal Boot + if (( $G_DIETPI_INSTALL_STAGE == 1 )); then + + echo 0 + + #First run prep + elif (( $G_DIETPI_INSTALL_STAGE == -1 )); then + + # - Set RPi v1 safe overclocking profile (900mhz) + RPi_Set_Clock_Speeds + + # - End user automated script + if [[ -f /boot/Automation_Custom_PreScript.sh ]]; then + + G_DIETPI-NOTIFY 2 'Running custom script, please wait...' + + local fp_dietpiautomation_custom_prescript_log='/var/tmp/dietpi/logs/dietpi-automation_custom_prescript.log' + chmod +x /boot/Automation_Custom_PreScript.sh + /boot/Automation_Custom_PreScript.sh | tee $fp_dietpiautomation_custom_prescript_log + if (( $? == 0 )); then + + G_DIETPI-NOTIFY 0 'Custom script' + + else + + G_DIETPI-NOTIFY 1 "Custom script: Please see the log file for more information $fp_dietpiautomation_custom_prescript_log" + + fi + + fi + + # - Activate DietPi Boot Loader User Settings and bring up network (dietpi.txt) + Apply_DietPi_FirstRun_Settings + + fi + + } + + #///////////////////////////////////////////////////////////////////////////////////// + # Main Loop + #///////////////////////////////////////////////////////////////////////////////////// + #----------------------------------------------------------------------------------- + # Init + Run_Init + #----------------------------------------------------------------------------------- + Main + #----------------------------------------------------------------------------------- + exit + #----------------------------------------------------------------------------------- +} diff --git a/dietpi/server_version-6 b/dietpi/server_version-6 index fcbc21b7ff..f1daa160cf 100644 --- a/dietpi/server_version-6 +++ b/dietpi/server_version-6 @@ -1,2 +1,2 @@ 6 -14 +15 diff --git a/rootfs/etc/network/if-up.d/dietpi-disable_offload b/rootfs/etc/network/if-up.d/dietpi-disable_offload new file mode 100644 index 0000000000..599bd2dfa6 --- /dev/null +++ b/rootfs/etc/network/if-up.d/dietpi-disable_offload @@ -0,0 +1,53 @@ +#!/bin/bash +{ + #//////////////////////////////////// + # dietpi-disable_offload + # + #//////////////////////////////////// + # Created by Daniel Knight + # Based on original fix & code by @carlosedp: https://github.com/Fourdee/DietPi/issues/2028#issue-352323603 + # + #//////////////////////////////////// + # + # Info: + # - Sets TCP/UDP offloading disabled for the required devices, which are prone to retransmissions and reset errors. + # - Currently known: RK3399/rock64 + # + # Exit codes: + # - 1=failure + # ethtool does not exist + # Failed to set ethtool to flagged devices + # - 0=ok + # + #//////////////////////////////////// + + #/////////////////////////////////////////////////////////////////////////////////// + # Globals + #/////////////////////////////////////////////////////////////////////////////////// + CMD=$(which ethtool) + EXIT_CODE=1 + + #/////////////////////////////////////////////////////////////////////////////////// + # Main Loop + #/////////////////////////////////////////////////////////////////////////////////// + #----------------------------------------------------------------------------------- + #Ethtool exists? + if [[ $CMD ]]; then + + EXIT_CODE=0 #Set success for all devices by default + + if [[ -d /sys/devices/platform/fe300000.ethernet/net/$IFACE || + -d /sys/devices/platform/ff540000.eth/net/$IFACE || + -d /sys/devices/platform/ff540000.ethernet/net/$IFACE ]]; then + + $CMD -K $IFACE rx off tx off + EXIT_CODE=$? #Update exit code once applied + + fi + + fi + #----------------------------------------------------------------------------------- + exit $EXIT_CODE + #----------------------------------------------------------------------------------- + +} diff --git a/rootfs/etc/profile.d/dietpi-unsupported_terminal.sh b/rootfs/etc/profile.d/dietpi-unsupported_terminal.sh new file mode 100644 index 0000000000..56ac25e8ec --- /dev/null +++ b/rootfs/etc/profile.d/dietpi-unsupported_terminal.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# Workaround for SSH client passing an unsupported $TERM string +if [[ $SSH_TTY ]] && ! toe -a | grep -q "$TERM"; then + + TERM_old="$TERM" + ncurses_term='' + + if [[ $TERM =~ 256 ]]; then + + export TERM='xterm-256color' + + else + + export TERM='xterm' + + fi + + G_WHIP_MENU_ARRAY=('0' 'Ignore for now, I will change the SSH clients terminal.') + + if ! dpkg-query -s ncurses-term &> /dev/null; then + + ncurses_term=' or install the "ncurses-term" packages, which enables a wider terminal support' + G_WHIP_MENU_ARRAY+=('1' 'Install "ncurses-term" now to add a wider terminal support.') + + fi + + G_WHIP_DEFAULT_ITEM=1 + G_PROGRAM_NAME='Unsupported SSH client terminal' G_WHIP_MENU "[WARNING] The terminal passed by your SSH client (TERM=$TERM_old) is not supported by this DietPi server.\n +To enable usage, we were fooling the server by setting \"TERM=$TERM\". This is not the cleanest solution, since commands might expect colours or formats, that are not supported by the actual terminal.\n +Please change your SSH clients terminal (passed $TERM string)$ncurses_term." + (( ! $? && G_WHIP_RETURNED_VALUE )) && G_AGI ncurses-term + + unset TERM_old + unset ncurses_term + +fi diff --git a/rootfs/etc/systemd/system/dietpi-boot.service b/rootfs/etc/systemd/system/dietpi-boot.service index 69892b210a..d55f7d21a3 100644 --- a/rootfs/etc/systemd/system/dietpi-boot.service +++ b/rootfs/etc/systemd/system/dietpi-boot.service @@ -1,7 +1,8 @@ [Unit] Description=DietPi-Boot -Requires=dietpi-ramdisk.service -After=network-online.target network.target networking.service dietpi-ramdisk.service dietpi-ramlog.service +#Order 3 +Requires=dietpi-ramdisk.service dietpi-preboot.service +After=dietpi-ramdisk.service dietpi-ramlog.service dietpi-preboot.service network-online.target network.target networking.service [Service] Type=oneshot diff --git a/rootfs/etc/systemd/system/dietpi-postboot.service b/rootfs/etc/systemd/system/dietpi-postboot.service index 0804ece5c3..e606fa5f35 100644 --- a/rootfs/etc/systemd/system/dietpi-postboot.service +++ b/rootfs/etc/systemd/system/dietpi-postboot.service @@ -1,7 +1,8 @@ [Unit] Description=DietPi-PostBoot -Requires=dietpi-boot.service dietpi-ramdisk.service -After=dietpi-boot.service dietpi-ramdisk.service dietpi-ramlog.service +#Order 4 +Requires=dietpi-ramdisk.service dietpi-boot.service +After=dietpi-ramdisk.service dietpi-ramlog.service dietpi-boot.service Before=rc-local.service rc.local.service [Service] diff --git a/rootfs/etc/systemd/system/dietpi-preboot.service b/rootfs/etc/systemd/system/dietpi-preboot.service new file mode 100644 index 0000000000..83cfcc60b0 --- /dev/null +++ b/rootfs/etc/systemd/system/dietpi-preboot.service @@ -0,0 +1,15 @@ +[Unit] +Description=DietPi-PreBoot +#Order 2 +Requires=dietpi-ramdisk.service +Before=dietpi-boot.service network-online.target network.target networking.service +After=local-fs.target boot.mount dietpi-ramdisk.service dietpi-ramlog.service + +[Service] +Type=oneshot +RemainAfterExit=yes +StandardOutput=tty +ExecStart=/bin/bash -c '/DietPi/dietpi/preboot | tee /var/tmp/dietpi/logs/dietpi-preboot.log' + +[Install] +WantedBy=local-fs.target diff --git a/rootfs/etc/systemd/system/dietpi-ramdisk.service b/rootfs/etc/systemd/system/dietpi-ramdisk.service index 848314865c..b1f4fadf82 100644 --- a/rootfs/etc/systemd/system/dietpi-ramdisk.service +++ b/rootfs/etc/systemd/system/dietpi-ramdisk.service @@ -1,5 +1,6 @@ [Unit] Description=DietPi-RAMdisk +#Order 1 After=local-fs.target boot.mount Before=rsyslog.service syslog.service diff --git a/rootfs/etc/systemd/system/dietpi-ramlog.service b/rootfs/etc/systemd/system/dietpi-ramlog.service index 512bfbe034..496c9c66ba 100644 --- a/rootfs/etc/systemd/system/dietpi-ramlog.service +++ b/rootfs/etc/systemd/system/dietpi-ramlog.service @@ -1,5 +1,6 @@ [Unit] Description=DietPi-RAMlog +#Order 1 After=local-fs.target boot.mount Before=rsyslog.service syslog.service diff --git a/rootfs/var/lib/dietpi/services/fs_partition_resize.sh b/rootfs/var/lib/dietpi/services/fs_partition_resize.sh index 0504f2c115..f74713e6fc 100644 --- a/rootfs/var/lib/dietpi/services/fs_partition_resize.sh +++ b/rootfs/var/lib/dietpi/services/fs_partition_resize.sh @@ -17,8 +17,9 @@ TARGET_DRIVE=${TARGET_DEV%[0-9]} # EG: /dev/mmcblk[0-9]p # Only redo partitions, if drive actually contains a partition table. if [[ $TARGET_PARTITION ]]; then - #Rock64 GPT resize | modified version of ayufan-rock64 resize script. I take no credit for this. - if [[ -f /etc/.dietpi_hw_model_identifier ]] && (( $(