Skip to content

Commit

Permalink
Merge pull request #1386 from Fourdee/adjust_ipv_selection
Browse files Browse the repository at this point in the history
DietPi-Config | Adjust IPv related settings
  • Loading branch information
Fourdee authored Jan 12, 2018
2 parents 6440d14 + dc53a33 commit 85589b4
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 65 deletions.
23 changes: 20 additions & 3 deletions dietpi/dietpi-config
Original file line number Diff line number Diff line change
Expand Up @@ -3044,7 +3044,7 @@
#IPv6 status
local ipv6_enabled=1
local ipv6_status_text='Enabled'
if [ -f /etc/modprobe.d/blacklist-ipv6.conf ]; then
if [ -f /etc/modprobe.d/99-dietpi-blacklist-ipv6.conf ]; then
ipv6_enabled=0
ipv6_status_text='Disabled'
fi
Expand Down Expand Up @@ -3125,7 +3125,16 @@

if (( $CHOICE == 0 )); then

echo -e "blacklist ipv6" > /etc/modprobe.d/blacklist-ipv6.conf
# - Blacklist kernel module
echo 'blacklist ipv6' > /etc/modprobe.d/99-dietpi-blacklist-ipv6.conf
# - APT force IPv4
echo 'Acquire::ForceIPv4 "true";' > /etc/apt/apt.conf.d/99-dietpi-force-ipv4
# - Wget prefer IPv4
grep -q '^[[:blank:]]*prefer-family =' /etc/wgetrc &&
sed -i '/^[[:blank:]]*prefer-family =/c\prefer-family = IPv4' /etc/wgetrc ||
grep -q '^[[:blank:]#;]*prefer-family =' /etc/wgetrc &&
sed -i '/^[[:blank:]#;]*prefer-family =/c\prefer-family = IPv4' /etc/wgetrc ||
echo 'prefer-family = IPv4' >> /etc/wgetrc
REBOOT_REQUIRED=1

fi
Expand All @@ -3138,7 +3147,15 @@

if (( $CHOICE == 0 )); then

rm /etc/modprobe.d/blacklist-ipv6.conf &> /dev/null
rm /etc/modprobe.d/99-dietpi-blacklist-ipv6.conf &> /dev/null
# - APT allow IPv6 but do not force it: https://github.com/Fourdee/DietPi/issues/472#issuecomment-356444922
rm /etc/apt/apt.conf.d/99-dietpi-force-ipv4 &> /dev/null
# - Wget prefer IPv6
grep -q '^[[:blank:]]*prefer-family =' /etc/wgetrc &&
sed -i '/^[[:blank:]]*prefer-family =/c\prefer-family = IPv6' /etc/wgetrc ||
grep -q '^[[:blank:]#;]*prefer-family =' /etc/wgetrc &&
sed -i '/^[[:blank:]#;]*prefer-family =/c\prefer-family = IPv6' /etc/wgetrc ||
echo 'prefer-family = IPv6' >> /etc/wgetrc
REBOOT_REQUIRED=1

fi
Expand Down
96 changes: 44 additions & 52 deletions dietpi/func/dietpi-globals
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
# $1 = Optional input directory (eg: G_TREESIZE /etc/apt)
G_TREESIZE()
{
du -k --max-depth=1 $1 | sort -nr | awk '
du -k --max-depth=1 "$1" | sort -nr | awk '
BEGIN {
split("KB,MB,GB,TB", Units, ",");
}
Expand All @@ -92,6 +92,8 @@

# DietPi-Notify
# $1:
# -2=process animation
# - $2 = text
# -1=autodetect_fail_ok
# - $2 = EXIT_CODE
# 0=OK
Expand Down Expand Up @@ -121,79 +123,71 @@

Print_Process_Animation(){

local bright_dot="\e[1;93m.\e[0m"
local dimmed_dot="\e[2;33m.\e[0m"
local aprocess_string=(
#"\e[90m[\e[1;93m\u23F9 \e[90m]\e[0m"
#"\e[90m[\e[2;33m\u23F9\e[0m\e[1;93m\u23F9 \e[0m\e[90m]\e[0m"
#"\e[90m[ \e[2;33m\u23F9\e[0m\e[1;93m\u23F9 \e[0m\e[90m]\e[0m"
#"\e[90m[ \e[2;33m\u23F9\e[0m\e[1;93m\u23F9 \e[0m\e[90m]\e[0m"
#"\e[90m[ \e[2;33m\u23F9\e[0m\e[1;93m\u23F9 \e[0m\e[90m]\e[0m"
#"\e[90m[ \e[2;33m\u23F9\e[0m\e[1;93m\u23F9\e[0m\e[90m]\e[0m"
#"\e[90m[ \e[1;93m\u23F9\e[0m\e[2;33m\u23F9\e[0m\e[90m]\e[0m"
#"\e[90m[ \e[1;93m\u23F9\e[0m\e[2;33m\u23F9 \e[0m\e[90m]\e[0m"
#"\e[90m[ \e[1;93m\u23F9\e[0m\e[2;33m\u23F9 \e[0m\e[90m]\e[0m"
#"\e[90m[ \e[1;93m\u23F9\e[0m\e[2;33m\u23F9 \e[0m\e[90m]\e[0m"
#"\e[90m[\e[1;93m\u23F9\e[0m\e[2;33m\u23F9 \e[0m\e[90m]\e[0m"
"\e[90m[\e[1;93m. \e[90m]\e[0m"
"\e[90m[\e[2;33m.\e[0m\e[1;93m. \e[0m\e[90m]\e[0m"
"\e[90m[ \e[2;33m.\e[0m\e[1;93m. \e[0m\e[90m]\e[0m"
"\e[90m[ \e[2;33m.\e[0m\e[1;93m. \e[0m\e[90m]\e[0m"
"\e[90m[ \e[2;33m.\e[0m\e[1;93m. \e[0m\e[90m]\e[0m"
"\e[90m[ \e[2;33m.\e[0m\e[1;93m.\e[0m\e[90m]\e[0m"
"\e[90m[ \e[1;93m.\e[0m\e[2;33m.\e[0m\e[90m]\e[0m"
"\e[90m[ \e[1;93m.\e[0m\e[2;33m. \e[0m\e[90m]\e[0m"
"\e[90m[ \e[1;93m.\e[0m\e[2;33m. \e[0m\e[90m]\e[0m"
"\e[90m[ \e[1;93m.\e[0m\e[2;33m. \e[0m\e[90m]\e[0m"
"\e[90m[\e[1;93m.\e[0m\e[2;33m. \e[0m\e[90m]\e[0m"
#\u23F9
"$bright_dot "
"$dimmed_dot$bright_dot "
" $dimmed_dot$bright_dot "
" $dimmed_dot$bright_dot "
" $dimmed_dot$bright_dot "
" $dimmed_dot$bright_dot"
" $bright_dot$dimmed_dot"
" $bright_dot$dimmed_dot "
" $bright_dot$dimmed_dot "
" $bright_dot$dimmed_dot "
"$bright_dot$dimmed_dot "
)

for (( i=0; i<=${#aprocess_string[*]}; i++ )); do
for (( i=0; i<=${#aprocess_string[@]}; i++ )); do

(( i == 11 )) && i=1
builtin printf "\r${aprocess_string[i]} "
[ -f /tmp/dietpi-process.pid ] && printf "\r$bracket_string_l${aprocess_string[i]}$bracket_string_r " || break
sleep 0.15

done

unset aprocess_string

}

Clean_Process_Animation(){

if [ -f /var/run/dietpi-process.pid ]; then
if [ -f /tmp/dietpi-process.pid ]; then

kill $(</var/run/dietpi-process.pid) &> /dev/null
rm /var/run/dietpi-process.pid
kill "$(</tmp/dietpi-process.pid)" &> /dev/null
rm /tmp/dietpi-process.pid &> /dev/null || sudo rm /tmp/dietpi-process.pid &> /dev/null
# In case, the output took more than one line, clean from cursor (animation position) until end of terminal.
tput ed

fi
echo -en "\r\e[K"
printf "\r\e[K"

}

Print_Process(){

echo -ne "\r\e[9C"
printf "\r\e[9C"

}

Print_Ok(){

Clean_Process_Animation
echo -ne "$bracket_string_l$status_text_ok$bracket_string_r "
printf "$bracket_string_l$status_text_ok$bracket_string_r "

}

Print_Failed(){

Clean_Process_Animation
echo -ne "$bracket_string_l$status_text_error$bracket_string_r "
printf "$bracket_string_l$status_text_error$bracket_string_r "

}

Print_Info(){

Clean_Process_Animation
echo -ne "$bracket_string_l$status_text_info$bracket_string_r "
printf "$bracket_string_l$status_text_info$bracket_string_r "

}

Expand All @@ -204,18 +198,9 @@
local i=0
for (( i=$1;i<${#ainput_string[@]} ;i++))
do
echo -ne "${ainput_string[$i]}"
printf "${ainput_string[$i]}"
done

# echo -e "SIZE = ${#ainput_string}"

# ainput_string="$@"
# for (( i=$1;i<${#ainput_string} ;i++))
# do
# echo -ne "${ainput_string:$i:1}"
# sleep 0.02
# done

}

#--------------------------------------------------------------------------------------
Expand Down Expand Up @@ -249,7 +234,17 @@

Print_Process
Print_Input_String 1
[ ! -f /var/run/dietpi-process.pid ] && ( Print_Process_Animation & builtin echo $! > /var/run/dietpi-process.pid )
# Calculate the amount of output lines and in case move cursor up for correct animation and to allow cleaning the whole output.
local string="$*"
local lines=0
(( lines=(${#string}+6)/$(tput cols) ))
while (( lines > 0 )); do

tput cuu1
(( lines-- ))

done
[ ! -f /tmp/dietpi-process.pid ] && touch /tmp/dietpi-process.pid && ( Print_Process_Animation & echo $! > /tmp/dietpi-process.pid )

#Status Ok
#$@ = txt desc
Expand Down Expand Up @@ -284,19 +279,16 @@
echo -e "\n \e[38;5;154m$2\e[0m"
echo -e "$header_line"
echo -e " \e[90mMode: \e[0m$(Print_Input_String 2)\n"
#Print_Process
#echo -ne "\e[90mPlease wait...\e[0m"
#[ ! -f /var/run/dietpi-process.pid ] && ( Print_Process_Animation & builtin echo $! > /var/run/dietpi-process.pid )

fi
#-----------------------------------------------------------------------------------
unset ainput_string
# Unset also internal functions, otherwise they are accessible from terminal.
unset Print_Process_Animation
unset Clean_Process_Animation
unset Print_Process
unset Print_Ok
unset Print_Failed
unset Print_Info
unset Print_Process
unset Print_Input_String
#-----------------------------------------------------------------------------------

Expand Down Expand Up @@ -951,7 +943,7 @@ $print_logfile_info
local string=( "$@" )
local packages_to_install=''

G_DIETPI-NOTIFY 2 "Checking for pre-req APT packages: ${string[@]}"
G_DIETPI-NOTIFY 2 "Checking for pre-req APT packages: ${string[*]}"

dpkg --get-selections > "$fp_temp"
for i in "${string[@]}"
Expand Down
12 changes: 2 additions & 10 deletions dietpi/func/dietpi-set_core_environment
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,6 @@ _EOF_

fi

G_DIETPI-NOTIFY 2 "Configuring: prefer IPv4 (wget):"

sed -i '/prefer-family =/c\prefer-family = IPv4' /etc/wgetrc

G_DIETPI-NOTIFY 2 "Configuring: force IPv4 (APT):"

echo 'Acquire::ForceIPv4 "true";' > /etc/apt/apt.conf.d/99force-ipv

#-----------------------------------------------------------------------------------
#MISC

Expand All @@ -371,8 +363,8 @@ _EOF_

G_DIETPI-NOTIFY 2 "Setting vm.swappiness=1:"

sed -i '/vm.swappiness=/d' /etc/sysctl.conf
echo -e "vm.swappiness=1" > /etc/sysctl.d/97-dietpi.conf
sed -i '/^[[:blank:]]*vm.swappiness=/d' /etc/sysctl.conf
echo -e "vm.swappiness=1" > /etc/sysctl.d/99-dietpi.conf

#-----------------------------------------------------------------------------------
G_DIETPI-NOTIFY 0 "Completed DietPi core environment"
Expand Down

0 comments on commit 85589b4

Please sign in to comment.