Skip to content

Commit

Permalink
v9.0
Browse files Browse the repository at this point in the history
- DietPi-Set_software | Further coding
  • Loading branch information
MichaIng committed Jan 15, 2024
1 parent e8aaaba commit b481bd6
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions dietpi/func/dietpi-set_software
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ $FP_SCRIPT disable_ssh_password_logins [01]|root|<empty> Whether to disable SSH
echo "$AVAIABLE_COMMANDS"
}

# $1: INPUT_ADDITIONAL_$1
Unknown_Input_Additional()
{
local argument="INPUT_ADDITIONAL_$1"
argument=${!argument}
EXIT_CODE=1
G_DIETPI-NOTIFY 2 "Unknown input argument ($argument) for command \"$INPUT_MODE_NAME $INPUT_MODE_NAME\". Nothing has been applied."
echo "$AVAIABLE_COMMANDS"
}

#/////////////////////////////////////////////////////////////////////////////////////
# locale
#/////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -138,13 +148,9 @@ deb $INPUT_MODE_VALUE $G_DISTRO_NAME-backports main contrib non-free' > /etc/apt
local fp='/etc/apt/apt.conf.d/99-dietpi-cache' fp_compress='/etc/apt/apt.conf.d/98dietpi-nocompress'

# Clean current cache before changing it, failsafe cleanup if custom dir was chosen before
G_EXEC_NOHALT=1 G_EXEC apt-get clean
G_EXEC apt-get clean

if [[ $INPUT_MODE_VALUE == 'reset' ]]
then
G_EXEC rm -Rf /tmp/apt "$fp" "$fp_compress"
return 0
fi
[[ $INPUT_MODE_VALUE == 'reset' ]] && { G_EXEC rm -Rf /tmp/apt "$fp" "$fp_compress"; return 0; }

[[ -f $fp ]] || echo '# Please use "dietpi-config" > "Advanded Options" > "APT" to edit these settings.' > "$fp"

Expand All @@ -154,23 +160,22 @@ deb $INPUT_MODE_VALUE $G_DISTRO_NAME-backports main contrib non-free' > /etc/apt
case $INPUT_ADDITIONAL_1 in
'disable')
G_CONFIG_INJECT 'Dir::Cache[[:blank:]]' 'Dir::Cache "/tmp/apt";' "$fp"
# Leave archives on disk by default
GCI_PRESERVE=1 G_CONFIG_INJECT 'Dir::Cache::archives[[:blank:]]' 'Dir::Cache::archives "/var/cache/apt/archives";' "$fp"
GCI_PRESERVE=1 G_CONFIG_INJECT 'Dir::Cache::archives[[:blank:]]' 'Dir::Cache::archives "/var/cache/apt/archives";' "$fp" # Leave archives on disk by default
G_CONFIG_INJECT 'Dir::Cache::pkgcache[[:blank:]]' 'Dir::Cache::pkgcache "";' "$fp"
G_CONFIG_INJECT 'Dir::Cache::srcpkgcache[[:blank:]]' 'Dir::Cache::srcpkgcache "";' "$fp"
[[ -d '/var/cache/apt' ]] && G_EXEC rm -R /var/cache/apt
G_EXEC rm -Rf /var/cache/apt
;;
'ram')
G_CONFIG_INJECT 'Dir::Cache[[:blank:]]' 'Dir::Cache "/tmp/apt";' "$fp"
GCI_PRESERVE=1 G_CONFIG_INJECT 'Dir::Cache::archives[[:blank:]]' 'Dir::Cache::archives "/var/cache/apt/archives";' "$fp"
G_EXEC_NOHALT=1 G_EXEC sed --follow-symlinks -i '/pkgcache[[:blank:]]/d' "$fp"
[[ -d '/var/cache/apt' ]] && G_EXEC rm -R /var/cache/apt
G_EXEC sed --follow-symlinks -i '/pkgcache[[:blank:]]/d' "$fp"
G_EXEC rm -Rf /var/cache/apt
;;
'disk')
G_EXEC_NOHALT=1 G_EXEC sed --follow-symlinks -i '/^Dir::Cache/d' "$fp"
[[ -d '/tmp/apt' ]] && G_EXEC rm -R /tmp/apt
G_EXEC sed --follow-symlinks -i '/^Dir::Cache/d' "$fp"
G_EXEC rm -Rf /tmp/apt
;;
*) :;;
*) Unknown_Input_Additional 1;;
esac;;
'lists')
case $INPUT_ADDITIONAL_1 in
Expand All @@ -181,16 +186,15 @@ deb $INPUT_MODE_VALUE $G_DISTRO_NAME-backports main contrib non-free' > /etc/apt
G_EXEC rm -Rf /var/lib/apt/{lists,mirrors,periodic,cdroms.list}
;;
'disk')
G_EXEC_NOHALT=1 G_EXEC sed --follow-symlinks -i '/^Dir::State/d' "$fp"
[[ -d '/tmp/apt' ]] && G_EXEC rm -R /tmp/apt
G_EXEC sed --follow-symlinks -i '/^Dir::State/d' "$fp"
G_EXEC rm -Rf /tmp/apt
;;
*) :;;
*) Unknown_Input_Additional 1;;
esac;;
'archives')
case $INPUT_ADDITIONAL_1 in
'ram')
# Cache needs to be in RAM as well for this to work reliable
G_CONFIG_INJECT 'Dir::Cache[[:blank:]]' 'Dir::Cache "/tmp/apt";' "$fp"
G_CONFIG_INJECT 'Dir::Cache[[:blank:]]' 'Dir::Cache "/tmp/apt";' "$fp" # Cache needs to be in RAM as well for this to work reliable
G_CONFIG_INJECT 'Dir::Cache::archives[[:blank:]]' 'Dir::Cache::archives "/tmp/apt/archives";' "$fp"
[[ -d '/var/cache/apt' ]] && G_EXEC rm -R /var/cache/apt
;;
Expand All @@ -199,14 +203,16 @@ deb $INPUT_MODE_VALUE $G_DISTRO_NAME-backports main contrib non-free' > /etc/apt
[[ -d '/tmp/apt/archives' ]] && G_EXEC rm -R /tmp/apt/archives
;;

*) :;;
*) Unknown_Input_Additional 1;;
esac;;
'compress')
case $INPUT_ADDITIONAL_1 in
1|'enable') [[ -f '/etc/apt/apt.conf.d/98dietpi-nocompress' ]] && G_EXEC rm "$fp_compress";;
1|'enable') G_EXEC rm -f "$fp_compress";;
0|'disable') echo -e '# Please use "dietpi-config" > "Advanded Options" > "APT" to edit this setting.\nAcquire::GzipIndexes "false";' > "$fp_compress";;
*) Unknown_Input_Additional 1;;
esac;;
*) :;;
'reset') :;;
*) Unknown_Input_Mode;;
esac

[[ -f $fp ]] || return 0
Expand Down

0 comments on commit b481bd6

Please sign in to comment.