More slight refactoring; shows root file system free space before upgrade; deals with older hardlink.

This commit is contained in:
Daltux 2024-06-13 11:11:45 -03:00
parent 20c11248dc
commit 933788e3dc
Signed by: daltux
GPG key ID: 28E9680DCA761480
2 changed files with 24 additions and 13 deletions

View file

@ -17,8 +17,13 @@ using **`apt`** and also, when present, `snap`, `flatpak` and `fwupdmgr`.
- [`flatpak`](https://packages.debian.org/stable/flatpak)
- [`fwupd`](https://packages.debian.org/stable/fwupd)
- from [`util-linux`](https://packages.debian.org/stable/util-linux):
- [`ionice`](https://manpages.debian.org/stable/util-linux/ionice.1) for running the tool with lowest I/O priority
- [`hardlink`](https://manpages.debian.org/stable/util-linux/hardlink.1) for linking identical files in APT lists directory, saving space
- [`ionice`](https://manpages.debian.org/stable/util-linux/ionice.1)
for running the tool with lowest I/O priority.
- [`hardlink`](https://manpages.debian.org/stable/util-linux/hardlink.1)
for linking identical files in APT lists directory, saving space.
- Until Debian 11 "bullseye" (or [Ubuntu 20.04](https://packages.ubuntu.com/focal/hardlink)),
this was a different program, from package [`hardlink`](https://packages.debian.org/bullseye/hardlink) ([manpage](https://manpages.debian.org/bullseye/hardlink/hardlink.1.en.html)),
less tested here.
## Usage

View file

@ -19,11 +19,13 @@
# with this program. If not, see <http://www.gnu.org/licenses/>.
FORCE_IPV4="-o Acquire::ForceIPv4=true"
ORIG_UID=${ORIG_UID:-$UID}
PARAMETERS="${*:-\"\"}"
[[ "$PARAMETERS" == *'-v'* ]] && echo "Script called with parameters: $PARAMETERS"
if [ -z "$MY_USER" ] ; then
[[ "$*" == *'-v'* ]] && echo "ORIG_UID=$ORIG_UID"
[[ "$PARAMETERS" == *'-v'* ]] && echo "ORIG_UID=$ORIG_UID"
if [ "$ORIG_UID" -ne 0 ] ; then
MY_USER=$(logname 2> /dev/null)
@ -31,6 +33,8 @@ if [ -z "$MY_USER" ] ; then
fi
fi
export FORCE_IPV4 ORIG_UID PARAMETERS MY_USER
check_apt () {
APT_CMD="${APT_CMD:-apt}"
@ -46,7 +50,7 @@ check_apt () {
[[ "$PARAMETERS" == *'-nu'* ]] || [[ "$PARAMETERS" == *'--no-update'* ]]
SKIP_UPDATE=$?
if [ "$SKIP_UPDATE" = 0 ] ; then
if [ "$SKIP_UPDATE" -eq 0 ] ; then
echo "Skipping $APT_CMD update as requested."
else
[[ "$APT_CMD" == 'nala' ]] && UPD_PARAMS="$UPD_PARAMS -v"
@ -78,7 +82,8 @@ check_apt () {
if command -v hardlink > /dev/null 2>&1 && [ -e "$APT_LISTS_DIR" ] ; then
echo "* Linking identical files in APT lists directory \"$APT_LISTS_DIR\" ..."
echo
hardlink --ignore-time --respect-xattrs --reflink=auto "$APT_LISTS_DIR"
hardlink --ignore-time --respect-xattrs "$APT_LISTS_DIR"
# --reflink=auto is available only on util-linux' hardlink
else
echo "WARNING: there is no command \"hardlink\" or directory \"$APT_LISTS_DIR\"."
fi
@ -104,6 +109,9 @@ check_apt () {
echo "Warning: unexpected APT_CMD \"$APT_CMD\""
;;
esac
echo
echo "$FREE_MSG $(free_space||true)"
[[ "$PARAMETERS" == *'-4'* ]] && APT_PARAMS="$APT_PARAMS $FORCE_IPV4"
[[ "$PARAMETERS" == *'-y'* ]] && APT_PARAMS="$APT_PARAMS -y"
@ -213,13 +221,13 @@ check_fwupd () {
# fi
#}
freeSpace () {
free_space () {
df --sync --output=avail -h / | tail -1
}
startup () {
UPTIME_BEGIN=$(uptime)
DF_BEGIN=$(freeSpace)
DF_BEGIN=$(free_space)
echo
check_apt && { check_snap ; check_flatpak ; check_fwupd ; }
#flashToFirefoxSnap # deprecated
@ -227,14 +235,11 @@ startup () {
echo "Start:$UPTIME_BEGIN"
echo " end:$(uptime)"
echo
echo Root file system free space:
echo "$FREE_MSG"
echo "$DF_BEGIN before"
echo "$(freeSpace||true) after"
echo "$(free_space||true) after"
}
export PARAMETERS="${*:-\"\"}"
[[ "$PARAMETERS" == *'-v'* ]] && echo "Script called with parameters: $PARAMETERS"
if [[ "$PARAMETERS" == *'--help'* ]] ; then
echo "Updates the system: apt [or nala if present] (update/upgrade/autoremove/clean), snap, flatpak and fwupdmgr (if present)."
echo
@ -253,6 +258,7 @@ if [[ "$PARAMETERS" == *'--help'* ]] ; then
echo " [ -vv ] . . . . . . . Also use \"bash -x\" to run the script."
echo " [ --help ] . . . . . Display this help text and exits."
else
export FREE_MSG='Root file system free space:'
startup
fi