Share your Debian SCRIPTS
- fabien
- Forum Helper
- Posts: 1138
- Joined: 2019-12-03 12:51
- Location: Anarres (Toulouse, France actually)
- Has thanked: 99 times
- Been thanked: 257 times
Share your Debian SCRIPTS
Share your Debian scripts!
Why keep those valuable pieces of code out of sight?
Being of personal use, their polish is perhaps not as high as if you'd made them to be published (which takes time for sure): that's no matter, you wrote them because they are of some use for you, they may be so for others. And maybe someone will find the idea of interest, be inspired, and share a more accomplished version in turn (it's amazing how small scripts can become huge). Also, it will show to those who don't script yet that even without real programming knowledge everyone can achieve things that enhance day-to-day computer experience.
Again, it's their usefulness that makes their value, not the skills put on them nor is it their length or the time they required to be made (could even be a one-liner). If there should be a criterion it would be that you use them regularly.
And a rule of importance: they must be in one way or another Debian related since it is a Debian forum.
I really look forward to seeing new scripts and hope you'll keep this thread alive.
Why keep those valuable pieces of code out of sight?
Being of personal use, their polish is perhaps not as high as if you'd made them to be published (which takes time for sure): that's no matter, you wrote them because they are of some use for you, they may be so for others. And maybe someone will find the idea of interest, be inspired, and share a more accomplished version in turn (it's amazing how small scripts can become huge). Also, it will show to those who don't script yet that even without real programming knowledge everyone can achieve things that enhance day-to-day computer experience.
Again, it's their usefulness that makes their value, not the skills put on them nor is it their length or the time they required to be made (could even be a one-liner). If there should be a criterion it would be that you use them regularly.
And a rule of importance: they must be in one way or another Debian related since it is a Debian forum.
I really look forward to seeing new scripts and hope you'll keep this thread alive.
Share your Debian SCRIPTS
There will be neither barrier nor walls, neither official nor guard, there will be no more desert and the entire world will become a garden. — Anacharsis Cloots
There will be neither barrier nor walls, neither official nor guard, there will be no more desert and the entire world will become a garden. — Anacharsis Cloots
- fabien
- Forum Helper
- Posts: 1138
- Joined: 2019-12-03 12:51
- Location: Anarres (Toulouse, France actually)
- Has thanked: 99 times
- Been thanked: 257 times
Re: Share your Debian SCRIPTS
popopop
human readable popularity-contest and unattended-upgrades logs.
popopop popularity-contest [large image]
popopop unattended-upgrades [large image]
edit 2023-01-16: updated popopop from no version to v.1.0
- better color compatibility with some terminals
- better popcon legibility
- faster unattended-upgrades function
- more unattended-upgrades messages highlighted
edit 2023-11-09: updated popopop from v.1.0 to v.1.1
- slight code improvement
disroot pastebin
Debian pastebin
human readable popularity-contest and unattended-upgrades logs.
popopop popularity-contest [large image]
popopop unattended-upgrades [large image]
edit 2023-01-16: updated popopop from no version to v.1.0
- better color compatibility with some terminals
- better popcon legibility
- faster unattended-upgrades function
- more unattended-upgrades messages highlighted
edit 2023-11-09: updated popopop from v.1.0 to v.1.1
- slight code improvement
disroot pastebin
Debian pastebin
Code: Select all
#!/usr/bin/env bash
### popopop ### v.1.1 ### human readable popularity-contest local reports - https://popcon.debian.org ######
### plus: human readable unattended-upgrades logs (-u option) - https://wiki.debian.org/UnattendedUpgrades #
### takes one argument (report's number) or no argument (last report) #
### Usage: [popopop] [popopop 0] [popopop -u] [popopop -u 3] #
################################################################## of1_À_disroot_POINT_org ### 2021-2023 ###
CAT="cat" PROGNAME="${0##*/}"
[[ "$*" != "${*/#-u}" ]] && { FILE="/var/log/unattended-upgrades/unattended-upgrades.log" SHUNT="UUP"
(( EUID == 0 )) || {
printf '\n%s\n\n' "$PROGNAME: you must be root to read ${FILE%\/*}/" >&2
exec su --login root --command="$0 $*"; }
read -d '' -ra ARGS <<<"${@/#-u}"; set -- "${ARGS[@]}"; } \
|| FILE="/var/log/popularity-contest" SHUNT="POP"
declare -a AVLBL=( "$FILE"* ); [[ -f "${AVLBL[0]}" ]] || AVLBL=()
[[ -n "$1" ]] && { [[ "$1" == [0-9]*([0-9]) ]] || {
printf '\n%s\n\n' "$PROGNAME: wrong argument: “$1”" >&2; exit 1; }
declare -i NBR="$1"; FILE="$FILE.$NBR"
(( NBR > 0 )) && CAT="zcat" FILE="$FILE.gz"; }
[[ -f "$FILE" ]] && unset -v ARGS AVLBL NBR \
|| { AVLBL=( "${AVLBL[@]//[^[:digit:]]}" )
until [[ "${AVLBL[*]:(( ${#AVLBL[@]} - 1 ))}" || ${#AVLBL[@]} -le 1 ]]; do
AVLBL=( "${AVLBL[@]:0:(( ${#AVLBL[@]} - 1 ))}" )
done
AVAILABLE="${AVLBL[*]/%/|}" AVAILABLE="${AVAILABLE// }"
AVAILABLE="${AVAILABLE/#|/ |}"
printf '\n%s\n' "$PROGNAME: $FILE: No such file"
printf '%s\n\n' "${PROGNAME//[[:print:]]/ } Available files: [${AVAILABLE%|}]"
exit 1; } >&2
f_popcon() {
local FIRST="true" FMT="+%A %-e %B %Y, %H:%M:%S %Z (UTC%z)" OLD="false" WORD
declare -a LINE
declare -i COUNT=1 F=3
{ printf '%s\n' "$PROGNAME $FILE - $(uname -nrmo)"
while read -ra LINE; do
"$OLD" || { [[ "${LINE[*]:(( ${#LINE[@]} - 1 ))}" == "<OLD>" ]] && { OLD="true"; echo; }; }
for WORD in "${LINE[@]}"; do
[[ $COUNT -lt $F && "$WORD" =~ [[:digit:]]{10}$ ]] && {
WORD="${WORD%"${BASH_REMATCH[0]}"}$(date -d @"${BASH_REMATCH[0]}" "$FMT")"; }
[[ $(( ++COUNT > 3 )) && "$WORD" =~ ^\<.*\>$ ]] && { printf '%s' $'\e[1;90m'"${WORD}"$'\e[0m '
continue; }
(( COUNT == 3 )) && { [[ "$WORD" =~ ^lib && ! "$WORD" =~ ^libreoffice ]] \
&& printf '%s' $'\e[0;37m'"$WORD"$'\e[0m ' \
|| printf '%s' $'\e[0;1m'"$WORD"$'\e[0m '
} || printf '%s' "$WORD "
done
"$FIRST" && { F=2 FIRST="false" FMT="+%F %H:%M "
echo -e "\nLast Access Time Last Change Time\n(atime) (ctime)\c"; }
echo; COUNT=0
done < <("$CAT" "$FILE"); } | less -RM
}
f_unupgd() {
local C1="\e[0;37m" C2="\e[0;1;90m" C3="\e[0;33m" C4="\e[0;1m" DATE DATEPREV HEAD LINE \
MSG1 MSG2 MSG3 MSG4 MSG5 NBSP="$(printf '%b' "\xC2\xA0")" REST RS="\e[0m"
### please localize MSGs according to messages found in your unattended-upgrades.log
### don't forget that MSGs are regexes https://en.wikipedia.org/wiki/Regular_expression
### replace non-breaking spaces with $NBSP if needed
### feel free to highlight more messages, the infrastructure is there
true && { ### English
declare -r NOTERR=" INFO " || {
printf '\n%s\n\n' "$PROGNAME: ${FUNCNAME[0]}: “NOTERR” assigned two times, exit" >&2; exit 1; }
MSG1="${NOTERR# }Starting unattended upgrades script"
MSG2="${NOTERR# }No packages found that can be upgraded unattended and no pending auto-removals"
MSG3="${NOTERR# }Packages that will be upgraded: "
MSG4="${NOTERR# }Packages that were successfully auto-removed: "
MSG5="${NOTERR# }Packages that are kept back: "; }
false && { ### French
declare -r NOTERR=" INFO " || {
printf '\n%s\n\n' "$PROGNAME: ${FUNCNAME[0]}: “NOTERR” assigned two times, exit" >&2; exit 1; }
MSG1="${NOTERR# }Démarrage du script de mise à niveau automatique"
MSG2="${NOTERR# }Aucun paquet à mettre à niveau automatiquement ni à supprimer automatiquement"
MSG3="${NOTERR# }Paquets mis à niveau$NBSP?: "
MSG4="${NOTERR# }Ces paquets ont été supprimés automatiquement correctement$NBSP?: "
MSG5="${NOTERR# }Paquets qui sont conservés$NBSP?: "; }
false && { ### Your own locale
declare -r NOTERR="" || {
printf '\n%s\n\n' "$PROGNAME: ${FUNCNAME[0]}: “NOTERR” assigned two times, exit" >&2; exit 1; }
MSG1="${NOTERR# }"
MSG2="${NOTERR# }"
MSG3="${NOTERR# }"
MSG4="${NOTERR# }"
MSG5="${NOTERR# }"; }
[[ "$NOTERR" == \ +([^[:space:]])\ ]] || {
printf '\n%s\n\n' "$PROGNAME: ${FUNCNAME[0]}: “NOTERR” ill-configured, exit" >&2; exit 1; }
{ printf '%s' "$PROGNAME $FILE - $(uname -nrmo)"
while IFS='' read -r LINE; do
DATE="${LINE%% *}"; [[ "$DATE" == "$DATEPREV" ]] || { DATEPREV="$DATE"; echo; }
[[ "$LINE" == "${LINE/"$NOTERR"}" ]] && {
sed 's/\(^'"$DATE"' [^ ]\+ \)\(.\+$\)/\x1b[0;37m\1 \x1b[1;31m\2\x1b[0m/' <<<"$LINE"
continue; }
[[ "$LINE" =~ ^$DATE\ [^\ ]+\ ]] && HEAD="${BASH_REMATCH[0]}" REST="${LINE#"${BASH_REMATCH[0]}"}"
[[ "$LINE" =~ \ $MSG1$ ]] && { LINE="${C1@P}$HEAD${C2@P}${BASH_REMATCH[0]}${RS@P}"
} || { [[ "$LINE" =~ \ $MSG2$ ]] && LINE="${C1@P}$HEAD${BASH_REMATCH[0]}${RS@P}"
} || { [[ "$LINE" =~ \ $MSG3 || "$LINE" =~ \ $MSG4 ]] && \
LINE="${C1@P}$HEAD${C3@P}${BASH_REMATCH[0]}${C4@P}${LINE#"${HEAD% }${BASH_REMATCH[0]}"}${RS@P}"
} || { [[ "$LINE" =~ \ $MSG5 && "${LINE#"${HEAD% }${BASH_REMATCH[0]}"}" ]] && \
LINE="${C1@P}$HEAD${C3@P}${BASH_REMATCH[0]}${C4@P}${LINE#"${HEAD% }${BASH_REMATCH[0]}"}${RS@P}"
} || LINE="${C1@P}$HEAD${RS@P} $REST"
printf '%s\n' "$LINE"
done < <("$CAT" "$FILE"); } | less -RM
}
case "$SHUNT" in
POP) unset -f f_unupgd; f_popcon;;
UUP) unset -f f_popcon; f_unupgd;;
*) ;;
esac
### md5sum/shasum - last line of the script ### popopop v.1.1 ###
- Attachments
-
- popopop popularity-contest
- md_popopop.png (150.47 KiB) Viewed 25782 times
-
- popopop unattended-upgrades
- md_popopop-unattended-upgrades.png (117.36 KiB) Viewed 29689 times
Last edited by fabien on 2023-11-09 21:48, edited 2 times in total.
Share your Debian SCRIPTS
There will be neither barrier nor walls, neither official nor guard, there will be no more desert and the entire world will become a garden. — Anacharsis Cloots
There will be neither barrier nor walls, neither official nor guard, there will be no more desert and the entire world will become a garden. — Anacharsis Cloots
- fabien
- Forum Helper
- Posts: 1138
- Joined: 2019-12-03 12:51
- Location: Anarres (Toulouse, France actually)
- Has thanked: 99 times
- Been thanked: 257 times
Re: Share your Debian SCRIPTS
apt-fly
an interface for apt-file.
apt-fly help [large image]
apt-fly search [large image]
apt-fly binaries search [large image]
apt-fly shared files [large image]
apt-fly alternative sources [large image]
apt-fly work on packages [large image]
edit 2023-01-16: updated apt-fly from v.2.4 to v.3.0
- can now query alternative sources thanks to the schow-pkg framework
- it is now possible to select arbitrary packages to work on
- readline completion is now available
- several important fixes and improvements
edit 2023-11-09: updated apt-fly from v.3.0 to v.3.1
- licensed under GPLv3+
- some improvements and edge case fixes
- can now query "All available sources" (can be memory exacting)
edit 2023-11-13: updated apt-fly from v.3.1 to v.3.2
- working on arbitrary packages is no longer limited by the maximum length of system arguments,
in other words, it is now possible to work with as many packages as one likes
(this was previously possible, but extremely slow)
edit 2024-02-06: updated apt-fly from v.3.2 to v.3.3
- if the Release file of a Debian (apt) repository does not contain the
'No-Support-for-Architecture-all: Packages' field, clients split the Packages files between
'binary-all_Packages' and 'binary-$ARCH_Packages'. This is not yet the case for Debian
repositories, but it is for some repositories. This version takes this into account, and
this has also been corrected in schow-pkg v.5.1 and why-pkg v.0.11a.
- the Debian Policy Manual does not stipulate that the Package: field must be placed in the first
position in the stanza, and some (non-Debian) repositories actually place it elsewhere.
This can have consequences and has been corrected in this version as well as in schow-pkg v.5.1
and why-pkg v.0.11a.
edit 2024-02-24: updated apt-fly from v.3.3 to v.3.4
- fixed a regression introduced in v.3.3
edit 2024-09-24: updated apt-fly from v.3.4 to v.3.5
- edge case fix
disroot pastebin
Debian pastebin
an interface for apt-file.
apt-fly help [large image]
apt-fly search [large image]
apt-fly binaries search [large image]
apt-fly shared files [large image]
apt-fly alternative sources [large image]
apt-fly work on packages [large image]
edit 2023-01-16: updated apt-fly from v.2.4 to v.3.0
- can now query alternative sources thanks to the schow-pkg framework
- it is now possible to select arbitrary packages to work on
- readline completion is now available
- several important fixes and improvements
edit 2023-11-09: updated apt-fly from v.3.0 to v.3.1
- licensed under GPLv3+
- some improvements and edge case fixes
- can now query "All available sources" (can be memory exacting)
edit 2023-11-13: updated apt-fly from v.3.1 to v.3.2
- working on arbitrary packages is no longer limited by the maximum length of system arguments,
in other words, it is now possible to work with as many packages as one likes
(this was previously possible, but extremely slow)
edit 2024-02-06: updated apt-fly from v.3.2 to v.3.3
- if the Release file of a Debian (apt) repository does not contain the
'No-Support-for-Architecture-all: Packages' field, clients split the Packages files between
'binary-all_Packages' and 'binary-$ARCH_Packages'. This is not yet the case for Debian
repositories, but it is for some repositories. This version takes this into account, and
this has also been corrected in schow-pkg v.5.1 and why-pkg v.0.11a.
- the Debian Policy Manual does not stipulate that the Package: field must be placed in the first
position in the stanza, and some (non-Debian) repositories actually place it elsewhere.
This can have consequences and has been corrected in this version as well as in schow-pkg v.5.1
and why-pkg v.0.11a.
edit 2024-02-24: updated apt-fly from v.3.3 to v.3.4
- fixed a regression introduced in v.3.3
edit 2024-09-24: updated apt-fly from v.3.4 to v.3.5
- edge case fix
disroot pastebin
Debian pastebin
- Attachments
-
- apt-fly binaries search
- md_apt-fly_binaries_search.png (56.37 KiB) Viewed 25781 times
-
- apt-fly help
- md_apt-fly_help.png (90.02 KiB) Viewed 25781 times
-
- apt-fly search
- md_apt-fly_search.png (177.23 KiB) Viewed 25781 times
Last edited by fabien on 2023-11-13 20:45, edited 3 times in total.
Share your Debian SCRIPTS
There will be neither barrier nor walls, neither official nor guard, there will be no more desert and the entire world will become a garden. — Anacharsis Cloots
There will be neither barrier nor walls, neither official nor guard, there will be no more desert and the entire world will become a garden. — Anacharsis Cloots
- fabien
- Forum Helper
- Posts: 1138
- Joined: 2019-12-03 12:51
- Location: Anarres (Toulouse, France actually)
- Has thanked: 99 times
- Been thanked: 257 times
Re: Share your Debian SCRIPTS
schow-pkg
human readable 'apt-cache show package' — and more
schow-pkg loop mode [large image]
schow-pkg versions [large image]
schow-pkg virtuals providers [large image]
schow-pkg virtuals providers alternative sources [large image]
schow-pkg search [large image]
schow-pkg show source packages [large image]
schow-pkg vulnerabilities and remote versions [large image]
schow-pkg apt-listbugs [large image]
schow-pkg apt policy [large image]
schow-pkg alternative sources [large image]
schow-pkg alternative sources all [large image]
schow-pkg alternative sources summary and management [large image]
schow-pkg pass arguments to why-pkg [large image]
schow-pkg help and documentation [large image]
edit 2022-07-05: updated schow-pkg from 3.2 to 4.0 (Added ability to use alternative sources, see screenshots. Plus some improvements.)
edit 2022-07-09: updated schow-pkg from 4.0 to 4.1 (Added search function.)
edit 2022-07-17: updated schow-pkg from 4.1 to 4.2 (Added virtual packages providers resolution.)
edit 2023-01-16: updated schow-pkg from 4.2 to 4.3
- updated to meet apt-fly v.3.0 requirements (Contents files acquisition)
- new Bash completion function (added architectures completion)
- new -d option: allows fetching manuals and changelogs from alternative sources via debmany
- new -i option: show installed packages only
- new -U option: display alternative sources summary
edit 2023-11-09: updated schow-pkg from 4.3 to 5.0
- licensed under GPLv3+
- now allows compound short options (e.g. -fSiv instead of -f -S -i -v)
- now supports ASCII-armored format keys (.asc) and allows ReleaseInfoChange
- it is now possible to deactivate/reactivate each of the alternative sources using -U=ID[,ID]
- there is a new cache that speeds up downloadable versions display (-v) (CUSTOMDIR must exist)
- the "All available sources" environment has been greatly improved
- new search capabilities (learn more using the -D option)
- new -b option: fetches packages vulnerabilities from security-tracker.debian.org
- new -D option: displays some documentation
- new -p option: allows arguments to be treated as apt-patterns (man 7 apt-patterns)
- new -q option: searches the binary packages that match the given source package names
- new -r option: searches the source packages that match the given binary package names
- new -R option: show source packages (apt-cache showsrc support)
- new -w option: lists downloadable package versions in remote repositories
edit 2024-02-06: updated schow-pkg from 5.0 to 5.1
- new -I option: show not installed packages only
- new -W option: pass the arguments to why-pkg
edit 2024-09-24: updated schow-pkg from 5.1 to 5.2
- new -B option: human readable “apt-listbugs”
- new -c option: retrieve package changelog
- new -P option: human readable “apt-cache policy”
- The -d option now defaults to fetching manpages from manpages.debian.org. This is a
rewrite of dman from the debian-goodies package. debmany integration is still available.
- showsrc (-R option) now emulates --no-all-versions (show only the highest version unless
the -a switch is used).
disroot pastebin
human readable 'apt-cache show package' — and more
schow-pkg loop mode [large image]
schow-pkg versions [large image]
schow-pkg virtuals providers [large image]
schow-pkg virtuals providers alternative sources [large image]
schow-pkg search [large image]
schow-pkg show source packages [large image]
schow-pkg vulnerabilities and remote versions [large image]
schow-pkg apt-listbugs [large image]
schow-pkg apt policy [large image]
schow-pkg alternative sources [large image]
schow-pkg alternative sources all [large image]
schow-pkg alternative sources summary and management [large image]
schow-pkg pass arguments to why-pkg [large image]
schow-pkg help and documentation [large image]
edit 2022-07-05: updated schow-pkg from 3.2 to 4.0 (Added ability to use alternative sources, see screenshots. Plus some improvements.)
edit 2022-07-09: updated schow-pkg from 4.0 to 4.1 (Added search function.)
edit 2022-07-17: updated schow-pkg from 4.1 to 4.2 (Added virtual packages providers resolution.)
edit 2023-01-16: updated schow-pkg from 4.2 to 4.3
- updated to meet apt-fly v.3.0 requirements (Contents files acquisition)
- new Bash completion function (added architectures completion)
- new -d option: allows fetching manuals and changelogs from alternative sources via debmany
- new -i option: show installed packages only
- new -U option: display alternative sources summary
edit 2023-11-09: updated schow-pkg from 4.3 to 5.0
- licensed under GPLv3+
- now allows compound short options (e.g. -fSiv instead of -f -S -i -v)
- now supports ASCII-armored format keys (.asc) and allows ReleaseInfoChange
- it is now possible to deactivate/reactivate each of the alternative sources using -U=ID[,ID]
- there is a new cache that speeds up downloadable versions display (-v) (CUSTOMDIR must exist)
- the "All available sources" environment has been greatly improved
- new search capabilities (learn more using the -D option)
- new -b option: fetches packages vulnerabilities from security-tracker.debian.org
- new -D option: displays some documentation
- new -p option: allows arguments to be treated as apt-patterns (man 7 apt-patterns)
- new -q option: searches the binary packages that match the given source package names
- new -r option: searches the source packages that match the given binary package names
- new -R option: show source packages (apt-cache showsrc support)
- new -w option: lists downloadable package versions in remote repositories
edit 2024-02-06: updated schow-pkg from 5.0 to 5.1
- new -I option: show not installed packages only
- new -W option: pass the arguments to why-pkg
edit 2024-09-24: updated schow-pkg from 5.1 to 5.2
- new -B option: human readable “apt-listbugs”
- new -c option: retrieve package changelog
- new -P option: human readable “apt-cache policy”
- The -d option now defaults to fetching manpages from manpages.debian.org. This is a
rewrite of dman from the debian-goodies package. debmany integration is still available.
- showsrc (-R option) now emulates --no-all-versions (show only the highest version unless
the -a switch is used).
disroot pastebin
- Attachments
-
- schow-pkg versions
- md_schow-pkg_versions.png (43.98 KiB) Viewed 29687 times
-
- schow-pkg loop mode
- md_schow-pkg_loop_mode.png (63.04 KiB) Viewed 29687 times
Last edited by fabien on 2023-11-09 22:38, edited 6 times in total.
Share your Debian SCRIPTS
There will be neither barrier nor walls, neither official nor guard, there will be no more desert and the entire world will become a garden. — Anacharsis Cloots
There will be neither barrier nor walls, neither official nor guard, there will be no more desert and the entire world will become a garden. — Anacharsis Cloots
- fabien
- Forum Helper
- Posts: 1138
- Joined: 2019-12-03 12:51
- Location: Anarres (Toulouse, France actually)
- Has thanked: 99 times
- Been thanked: 257 times
Re: Share your Debian SCRIPTS
why-pkg
an interface for 'aptitude why' (with handy 'aptitude search' interface), plus a function that displays recursive dependencies, and a function that examines system packages state.
why-pkg [large image]
why-pkg loop mode [large image]
why-pkg search with --showpatterns [large image]
why-pkg recursive dependencies [large image]
why-pkg recursive dependencies with installed reverse dependencies count [large image]
why-pkg audit [large image]
why-pkg help [large image]
edit 2022-05-29: updated why-pkg from 0.8b to 0.8c (added APT pinning test to --audit function)
edit 2022-11-20: Howto change why-pkg name:
edit 2023-01-16: updated why-pkg from v.0.8c to v.0.9a
- updated to welcome changes in upcoming Bookworm
- new Bash completion function, please update /etc/bash_completion.d/why-pkg
- virtual packages are now highlighted in search results (f_why)
- new -E option: exclude virtual packages from search results (f_why)
- new -U option: apply pin priority 990 to given suite (f_why, f_reverse)
- new -V option: display not installed dependencies vertically (f_reverse)
- added missing enhancement packages detection (f_audit)
edit 2023-11-09: updated why-pkg from v.0.9a to v.0.10a
- cleanup and improvement of some parts of the code, some fixes too
- new Bash completion function, please update /etc/bash_completion.d/why-pkg
- new -A option: display aptitude search patterns (f_why)
- new -M option: query alternative sources among those provided by schow-pkg (f_why, f_reverse)
- new -P option: display colored output of apt-rdepends recursive reverse dependency listings (f_why)
- new -X option: like -x, but outlines the reasons for the checks and points the way for further study (f_audit)
edit 2024-02-06: updated why-pkg from v.0.10a to v.0.11a
- due to occurrences, a warning is issued if the APT database has not been correctly updated (f_audit)
- remaining dependencies on debtags have been removed and its installation is discouraged
- new Bash completion function, please update /etc/bash_completion.d/why-pkg
- added 'provided by' information for real packages when using c/C/y/Y options (f_why)
- new -Z option: count all possible installed reverse dependencies for each package (f_reverse)
edit 2024-09-24: updated why-pkg from v.0.11a to v.0.11b
- some improvements
disroot pastebin
an interface for 'aptitude why' (with handy 'aptitude search' interface), plus a function that displays recursive dependencies, and a function that examines system packages state.
why-pkg [large image]
why-pkg loop mode [large image]
why-pkg search with --showpatterns [large image]
why-pkg recursive dependencies [large image]
why-pkg recursive dependencies with installed reverse dependencies count [large image]
why-pkg audit [large image]
why-pkg help [large image]
edit 2022-05-29: updated why-pkg from 0.8b to 0.8c (added APT pinning test to --audit function)
edit 2022-11-20: Howto change why-pkg name:
- [>] Changing why-pkg's name implies some easy but not so obvious steps.
- line 4: replace why-pkg with new-name (limitation: new-name must not end with a digit)
- line 139: replace _why-pkg() { with _new-name() {
- line 250: replace complete -F _why-pkg why-pkg with complete -F _new-name new-name
- and also replace them in /etc/bash_completion.d/why-pkg if relevant
- mv /etc/bash_completion.d/why-pkg /etc/bash_completion.d/new-name if relevant
- run new-name and replace new-name last line as stated: new-name v.x sha256sum
- run new-name -N to check application
- please note that apt-fly and schow-pkg have calls to why-pkg, so you'll have to change it there too
edit 2023-01-16: updated why-pkg from v.0.8c to v.0.9a
- updated to welcome changes in upcoming Bookworm
- new Bash completion function, please update /etc/bash_completion.d/why-pkg
- virtual packages are now highlighted in search results (f_why)
- new -E option: exclude virtual packages from search results (f_why)
- new -U option: apply pin priority 990 to given suite (f_why, f_reverse)
- new -V option: display not installed dependencies vertically (f_reverse)
- added missing enhancement packages detection (f_audit)
edit 2023-11-09: updated why-pkg from v.0.9a to v.0.10a
- cleanup and improvement of some parts of the code, some fixes too
- new Bash completion function, please update /etc/bash_completion.d/why-pkg
- new -A option: display aptitude search patterns (f_why)
- new -M option: query alternative sources among those provided by schow-pkg (f_why, f_reverse)
- new -P option: display colored output of apt-rdepends recursive reverse dependency listings (f_why)
- new -X option: like -x, but outlines the reasons for the checks and points the way for further study (f_audit)
edit 2024-02-06: updated why-pkg from v.0.10a to v.0.11a
- due to occurrences, a warning is issued if the APT database has not been correctly updated (f_audit)
- remaining dependencies on debtags have been removed and its installation is discouraged
- new Bash completion function, please update /etc/bash_completion.d/why-pkg
- added 'provided by' information for real packages when using c/C/y/Y options (f_why)
- new -Z option: count all possible installed reverse dependencies for each package (f_reverse)
edit 2024-09-24: updated why-pkg from v.0.11a to v.0.11b
- some improvements
disroot pastebin
- Attachments
-
- why-pkg recursive dependencies
- md_why-pkg_recursive_dependencies.png (84.44 KiB) Viewed 29685 times
-
- why-pkg audit
- md_why-pkg_audit.png (84.11 KiB) Viewed 29685 times
-
- why-pkg
- md_why-pkg.png (34.3 KiB) Viewed 29685 times
Last edited by fabien on 2023-11-09 22:59, edited 4 times in total.
Share your Debian SCRIPTS
There will be neither barrier nor walls, neither official nor guard, there will be no more desert and the entire world will become a garden. — Anacharsis Cloots
There will be neither barrier nor walls, neither official nor guard, there will be no more desert and the entire world will become a garden. — Anacharsis Cloots
- fabien
- Forum Helper
- Posts: 1138
- Joined: 2019-12-03 12:51
- Location: Anarres (Toulouse, France actually)
- Has thanked: 99 times
- Been thanked: 257 times
Re: Share your Debian SCRIPTS
that's all for me. A tar.gz of the four scripts is available here
or as attachment below
sha224sum 1ee609a546d345791257b3c8596c9371c9274ef88b9b82f942ee2457
edit 2022-05-29: added DebianScripts.tar.gz as attachment
edit 2022-07-05: schow-pkg updated from 3.2 to 4.0
edit 2022-07-09: schow-pkg updated from 4.0 to 4.1
edit 2022-07-17: schow-pkg updated from 4.1 to 4.2
edit 2023-01-16: popopop updated from no version to 1.0, apt-fly updated from 2.4 to 3.0, schow-pkg updated from 4.2 to 4.3, why-pkg updated from 0.8c to 0.9a
edit 2023-11-09: popopop updated from version 1.0 to 1.1, apt-fly updated from 3.0 to 3.1, schow-pkg updated from 4.3 to 5.0, why-pkg updated from 0.9a to 0.10a
edit 2023-11-13: apt-fly updated from 3.1 to 3.2
edit 2024-02-06: apt-fly updated from 3.2 to 3.3, schow-pkg updated from 5.0 to 5.1, why-pkg updated from 0.10a to 0.11a
edit 2024-02-24: apt-fly updated from 3.3 to 3.4
edit 2024-09-24: apt-fly updated from 3.4 to 3.5, schow-pkg updated from 5.1 to 5.2, why-pkg updated from 0.11a to 0.11b
or as attachment below
sha224sum 1ee609a546d345791257b3c8596c9371c9274ef88b9b82f942ee2457
edit 2022-05-29: added DebianScripts.tar.gz as attachment
edit 2022-07-05: schow-pkg updated from 3.2 to 4.0
edit 2022-07-09: schow-pkg updated from 4.0 to 4.1
edit 2022-07-17: schow-pkg updated from 4.1 to 4.2
edit 2023-01-16: popopop updated from no version to 1.0, apt-fly updated from 2.4 to 3.0, schow-pkg updated from 4.2 to 4.3, why-pkg updated from 0.8c to 0.9a
edit 2023-11-09: popopop updated from version 1.0 to 1.1, apt-fly updated from 3.0 to 3.1, schow-pkg updated from 4.3 to 5.0, why-pkg updated from 0.9a to 0.10a
edit 2023-11-13: apt-fly updated from 3.1 to 3.2
edit 2024-02-06: apt-fly updated from 3.2 to 3.3, schow-pkg updated from 5.0 to 5.1, why-pkg updated from 0.10a to 0.11a
edit 2024-02-24: apt-fly updated from 3.3 to 3.4
edit 2024-09-24: apt-fly updated from 3.4 to 3.5, schow-pkg updated from 5.1 to 5.2, why-pkg updated from 0.11a to 0.11b
- Attachments
-
- DebianScripts.tar.gz
- popopop, apt-fly, schow-pkg, why-pkg
- (138.44 KiB) Downloaded 4480 times
Last edited by fabien on 2023-11-13 20:50, edited 7 times in total.
Share your Debian SCRIPTS
There will be neither barrier nor walls, neither official nor guard, there will be no more desert and the entire world will become a garden. — Anacharsis Cloots
There will be neither barrier nor walls, neither official nor guard, there will be no more desert and the entire world will become a garden. — Anacharsis Cloots
-
- Posts: 339
- Joined: 2015-06-07 14:38
- Has thanked: 14 times
- Been thanked: 46 times
Re: Share your Debian SCRIPTS
Most of my scripts - https://gitlab.com/jmgibson1981/homescr ... ster/shell
My Router config script to be run on boot - https://gitlab.com/jmgibson1981/homescr ... ter/router
Aren't much but they get it done.
*EDIT* And just now looking over them I have my sql dump script missing something. I probably removed the emergency email function and forgot to remove that variable.
My Router config script to be run on boot - https://gitlab.com/jmgibson1981/homescr ... ter/router
Aren't much but they get it done.
*EDIT* And just now looking over them I have my sql dump script missing something. I probably removed the emergency email function and forgot to remove that variable.
Re: Share your Debian SCRIPTS
I'm a fan of keeping things lightweight. clockspeed.sh, monitor CPU clockspeed:
video2gif.sh, convert video segments into animated gifs:
Takes arguments as video2gif.sh input.mp4 output.gif <resolution width> <fps> <start time> <duration>
Code: Select all
#!/bin/bash
watch -n.5 "grep \"MHz\" /proc/cpuinfo"
Code: Select all
#!/bin/bash
ffmpeg -i "$1" -ss "$5" -t "$6" -filter_complex "[0:v] fps="$4",scale="$3":-1" "$2" -hide_banner
- fabien
- Forum Helper
- Posts: 1138
- Joined: 2019-12-03 12:51
- Location: Anarres (Toulouse, France actually)
- Has thanked: 99 times
- Been thanked: 257 times
Re: Share your Debian SCRIPTS
thanks for your input @jmgibson1981, good examples of system scripts, and some are even Debian related.
It selects the maximum frequency of all cores. This has to be adapted to the number of cores (here for 8 cores) and the particularities of 'sensors' output. The output is:
Sometimes I wish I was like you, I can't help building big machines. This is why-pkg tiny quick and dirty first version:
Code: Select all
#!/bin/bash
[[ -z "$@" ]] && { echo -e "\n$(basename "$0"): cette commande a besoin d'au moins un paramètre (le paquet à rechercher).\n"
exit 1; }
for PKG in "$@" ; do
PKGINFO=$(aptitude --disable-columns -F "%c%M %p > %d %I %P" search "?exact-name($PKG)" |\
sed 's/\(^.A\)\( \)/\1/')
[[ -n "$PKGINFO" ]] && { echo "$PKGINFO" | grep -q "^i" && STATE="\ue008" || STATE="\e[0;90m\ue008\e[0m"; }
[[ -n "$PKGINFO" ]] && echo -e "$(echo "\n\n$STATE $PKGINFO" | mawk 'sub($3,"\e[4m&\e[0m")')" ||\
echo -e "\n\n\ue469 -- $PKG - inconnu"
RAW="$(aptitude -v why "$PKG")\n"
[[ $(echo "$RAW" | grep "No dependencies require to install $PKG") ]] && { echo -e "\n$RAW" | sed 's/\(^.\)/ \1/'; continue; }
echo -e "\n$(echo -e "$RAW" | grep -B1 "^$" | grep -v "^$" | grep -v "^--$" |\
sed 's/\(^.\)\( \)\(.\)/\1\3/' | sed 's/[[:space:]]\+/ /g' | sed 's/[[:space:]]\+$//' | sed 's/ | /|/g' | sort -u |\
mawk 'sub($2,"\e[1;37m&\e[0m"){printf " %-4s %-45s %-0s %-0s\n",$1,$2,$3,$4}' |\
sed 's/Dépend/\\e[1;35m&\\e[0m/' | sed 's/Recommande/\\e[1;36m&\\e[0m/' | sed 's/Suggère/\\e[0;36m&\\e[0m/')\n\n"
done
I use:
Code: Select all
mawk 'NR<9{if ($1>maxfreq){maxfreq=$1}}
NR>8{{if (/^Package id 0:/){$0=$4; sub(/^\+/,""); tp=$1}}
{if (/^cpu fan:/){rpm="☢"$3; exit}}}
END {printf ("%.1f%s\n%s\n%s\n",maxfreq/1000000,"Ghz",tp,rpm)}' /sys/bus/cpu/devices/cpu*/cpufreq/scaling_cur_freq - < <(sensors)
Code: Select all
1,6Ghz
32.0°C
☢1073
Share your Debian SCRIPTS
There will be neither barrier nor walls, neither official nor guard, there will be no more desert and the entire world will become a garden. — Anacharsis Cloots
There will be neither barrier nor walls, neither official nor guard, there will be no more desert and the entire world will become a garden. — Anacharsis Cloots
Re: Share your Debian SCRIPTS
I used to build big scripts, such as backup utilities, but found that they quickly became hard for me to identify and fix their eventual issues. And asked myself why was I putting effort into so much abstraction when I knew I would be the only person running that script, on some very familiar hardware.
-
- Posts: 339
- Joined: 2015-06-07 14:38
- Has thanked: 14 times
- Been thanked: 46 times
Re: Share your Debian SCRIPTS
Yep. Sorry. Didn't catch the part for Debian specific stuff. I only use Debian so just popped em up.some are even Debian related.
- craigevil
- Posts: 5399
- Joined: 2006-09-17 03:17
- Location: heaven
- Has thanked: 28 times
- Been thanked: 43 times
Re: Share your Debian SCRIPTS
None that I have created. I do use nvm, fzf-extras.
https://github.com/atweiden/fzf-extras
https://github.com/nvm-sh/nvm
Oh and Surfraw, https://gitlab.com/surfraw/Surfraw
https://github.com/atweiden/fzf-extras
https://github.com/nvm-sh/nvm
Oh and Surfraw, https://gitlab.com/surfraw/Surfraw
Raspberry PI 400 Distro: Raspberry Pi OS Base: Debian Sid Kernel: 5.15.69-v8+ aarch64 DE: MATE Ram 4GB
Debian - "If you can't apt install something, it isn't useful or doesn't exist"
My Giant Sources.list
Debian - "If you can't apt install something, it isn't useful or doesn't exist"
My Giant Sources.list
- fabien
- Forum Helper
- Posts: 1138
- Joined: 2019-12-03 12:51
- Location: Anarres (Toulouse, France actually)
- Has thanked: 99 times
- Been thanked: 257 times
Re: Share your Debian SCRIPTS
updated why-pkg from 0.8b to 0.8c (added APT pinning detection test to --audit function). See above.
Share your Debian SCRIPTS
There will be neither barrier nor walls, neither official nor guard, there will be no more desert and the entire world will become a garden. — Anacharsis Cloots
There will be neither barrier nor walls, neither official nor guard, there will be no more desert and the entire world will become a garden. — Anacharsis Cloots
- fabien
- Forum Helper
- Posts: 1138
- Joined: 2019-12-03 12:51
- Location: Anarres (Toulouse, France actually)
- Has thanked: 99 times
- Been thanked: 257 times
Re: Share your Debian SCRIPTS
anything scripted. Perl, Python, Tcl/Tk, Zsh, Ruby, ... anything easily run by just putting it in a file and making it executable, and easily editable by the user as well.
I wonder what kind of script wouldn't work on deb The idea is (was?) to collect scripts that help users with aspects of the Debian system, Debian related as I said in the introduction (sorry if it wasn't clear enough, I thought it was but my English is approximate). For example, I started working on apt-fly one day when I couldn't remember what package provided the 'play' command: 'apt-file search play' outputs over 30000 lines and it takes a long time to find out the answer that is found in seconds with apt-fly. Anyway, I find any input in this thread nice after all. However, maybe someone should take the initiative to open a new thread in Offtopic for non-Debian related scripts
Share your Debian SCRIPTS
There will be neither barrier nor walls, neither official nor guard, there will be no more desert and the entire world will become a garden. — Anacharsis Cloots
There will be neither barrier nor walls, neither official nor guard, there will be no more desert and the entire world will become a garden. — Anacharsis Cloots
- Head_on_a_Stick
- Posts: 14114
- Joined: 2014-06-01 17:46
- Location: London, England
- Has thanked: 81 times
- Been thanked: 135 times
Re: Share your Debian SCRIPTS
@fabian: thanks for the contributions, very interesting. You might want to pass them through https://shellcheck.net, I use it for all my (lame) scripts, it's great for picking up shell script bugs and other problems.
For example, from apt-fly:
So perhaps consider
HTH
EDIT:
For example, from apt-fly:
Code: Select all
Line 42:
DECOMPRESSIONMETHOD="$(ls -1 /var/lib/apt/lists/*_Contents-* 2>/dev/null |\
^-- SC2010 (warning): Don't use ls | grep. Use a glob or a for loop with a condition to allow non-alphanumeric filenames.
Code: Select all
files=(/var/lib/apt/lists/*_Contents-*)
DECOMPRESSIONMETHOD="${files[@]##*.}"
EDIT:
How aboutfabian wrote:I couldn't remember what package provided the 'play' command: 'apt-file search play' outputs over 30000 lines
Code: Select all
apt-file search "/usr/bin/play" # or perhaps "/(?:usr/bin/play)"
deadbang
- fabien
- Forum Helper
- Posts: 1138
- Joined: 2019-12-03 12:51
- Location: Anarres (Toulouse, France actually)
- Has thanked: 99 times
- Been thanked: 257 times
Re: Share your Debian SCRIPTS
Thanks for your interest and your comments. I have shellcheck package installed and its analysis I have already questioned and addressed. It is actually useful but often fastidious and you have to take it with a grain of salt. For example, SC2010 rationale points out a real question that must be pondered:Head_on_a_Stick wrote: ↑2022-05-30 15:00@fabian: thanks for the contributions, very interesting. You might want to pass them through https://shellcheck.net, I use it for all my (lame) scripts, it's great for picking up shell script bugs and other problems.
For example, from apt-fly:Code: Select all
Line 42: DECOMPRESSIONMETHOD="$(ls -1 /var/lib/apt/lists/*_Contents-* 2>/dev/null |\ ^-- SC2010 (warning): Don't use ls | grep. Use a glob or a for loop with a condition to allow non-alphanumeric filenames.
But the files in /var/lib/apt/lists/ are very unlikely to have special characters in them and even if it were the case I'm only interested in file extensions already defined as "\.bz2$\|\.gz$\|\.lz4$\|\.lzma$\|\.xz$\|\.zst$" so the probability of a glitch is zero.Parsing ls is generally a bad idea because the output is fragile and human readable.
I like full Bash solutions very much (take a look at the beginning of why-pkg for instance) and tend to use them as much as possible. But here using grep is the right choice since it ensures that no extension other than bz2, gz, lz4, lzma, xz, or zst are kept. Using find instead of ls will satisfy shellcheck.Head_on_a_Stick wrote: ↑2022-05-30 15:00So perhaps considerCode: Select all
files=(/var/lib/apt/lists/*_Contents-*) DECOMPRESSIONMETHOD="${files[@]##*.}"
Code: Select all
$> FILES=( /var/lib/apt/lists/*_Contents-* ); FILES=( "${FILES[@]##*.}" )
$> sort -u -k1,1 -- <<<"${FILES[@]/#/$'\n'}"
diff_Index
lz4
$> find /var/lib/apt/lists/ -maxdepth 1 -name "*_Contents-*" | grep -o "\.bz2$\|\.gz$\|\.lz4$\|\.lzma$\|\.xz$\|\.zst$" | sort -u
.lz4
This is your reflex, my reflex is to dive headfirst into a giant scriptHead_on_a_Stick wrote: ↑2022-05-30 15:00How aboutfabian wrote:I couldn't remember what package provided the 'play' command: 'apt-file search play' outputs over 30000 linesCode: Select all
apt-file search "/usr/bin/play" # or perhaps "/(?:usr/bin/play)"
And remember
Code: Select all
### What use is apt-fly?
### One day you'll find out, maybe
Share your Debian SCRIPTS
There will be neither barrier nor walls, neither official nor guard, there will be no more desert and the entire world will become a garden. — Anacharsis Cloots
There will be neither barrier nor walls, neither official nor guard, there will be no more desert and the entire world will become a garden. — Anacharsis Cloots
-
- Posts: 19
- Joined: 2022-05-31 16:19
- Has thanked: 5 times
Re: Share your Debian SCRIPTS
Code: Select all
#show all recommended packages of all of the packages you manually insalled with `sudo apt install` or `sudo dpkg -i` or whatever:
for i in `apt-mark showmanual`; do rec="$(dpkg-query -f '${Recommends}' -W $i)"; [ -n "$rec" ] && echo "$i: $rec"; done
- NFT5
- df -h | grep > 20TiB
- Posts: 633
- Joined: 2014-10-10 11:38
- Location: Canberra, Australia
- Has thanked: 10 times
- Been thanked: 47 times
Re: Share your Debian SCRIPTS
If you use MATE or another desktop where the file manager is capable of two panels but doesn't or can't open both automatically then this, as simple as it gets, is a godsend.
Needs xdotool and I use it as the command for an icon on my toolbar. The sleep time does result in a noticeable (barely) gap from application opening to second panel opening and may be reduced,
Code: Select all
#!/bin/bash
# Open caja and then open second pane
caja $1 && sleep 0.5 ; xdotool key --clearmodifiers F3
- fabien
- Forum Helper
- Posts: 1138
- Joined: 2019-12-03 12:51
- Location: Anarres (Toulouse, France actually)
- Has thanked: 99 times
- Been thanked: 257 times
Re: Share your Debian SCRIPTS
Nice trick @NFT5, one that is worth remembering to solve hopeless case.
Thanks @user6c57b8, below is a quick prototype inspired by your one-liner.
Thanks @user6c57b8, below is a quick prototype inspired by your one-liner.
Code: Select all
#!/usr/bin/env bash
declare -a DEPS MANUALS PKDEPS
LANG="C" ### better performances and no UTF-8 expected
INSTALLEDPKGS="$(dpkg -l | mawk 'FNR>5{if (/^.i. /){$0=$2; sub(/:.+$/,""); print " "$0" "}}')"
command -v aptitude &>/dev/null && VIRTUALS="$(aptitude -F " %p " search "?virtual(^)" | grep -v ":")"
read -d '' -ra MANUALS < <(apt-mark showmanual)
readarray -t PKDEPS < <(dpkg-query -f '[\\e[1;31m${binary:Package}\\e[0m] ${Recommends}\n' -W "${MANUALS[@]}" |\
sed 's/ ([^)]\+)//g')
for PKG in "${PKDEPS[@]}"; do
[[ "${PKG#* }" ]] || continue
echo -en "${PKG%% *} "
read -d '' -ra DEPS <<<"${PKG#* }"
for DEP in "${DEPS[@]}"; do
[[ "$DEP" == "|" ]] && { echo -en "\e[0;33m$DEP\e[0m"; SPACE=""; continue; }
[[ "$INSTALLEDPKGS" =~ " ${DEP%,} " ]] && { echo -en "$SPACE\e[0;37m$DEP\e[0m"; SPACE=" "; continue; }
[[ "$VIRTUALS" =~ " ${DEP%,} " ]] && { echo -en "$SPACE\e[38;5;21m$DEP\e[0m"; SPACE=" "; continue; }
echo -en "$SPACE\e[1m$DEP\e[0m"; SPACE=" "
done
echo
done
Share your Debian SCRIPTS
There will be neither barrier nor walls, neither official nor guard, there will be no more desert and the entire world will become a garden. — Anacharsis Cloots
There will be neither barrier nor walls, neither official nor guard, there will be no more desert and the entire world will become a garden. — Anacharsis Cloots
-
- Posts: 19
- Joined: 2022-05-31 16:19
- Has thanked: 5 times
Output the /BIN/ commands of all the packages you have "manually" installed on your Debian system
(see: post subject)
VERSION 2 (latest) (2022-07-10) (changes: added blue color to the output command.) (open bugs: some people reported some bin paths are invalid bin paths.)
VERSION 1 (2022-06-10)
VERSION 2 (latest) (2022-07-10) (changes: added blue color to the output command.) (open bugs: some people reported some bin paths are invalid bin paths.)
Code: Select all
for str_package_name in $(apt-mark showmanual); do str_package_filelist_bin="$(dpkg --listfiles "$str_package_name" 2>/dev/null | egrep bin/ | sed 's/^/ /')"; [[ "$str_package_filelist_bin" ]] && { echo "<$str_package_name>"; echo "$str_package_filelist_bin" | sed 's/\/\([a-zA-Z0-9._-]\+\)$/\/\x1b[34m\1\x1b[39m/'; echo "</$str_package_name>"; } ; done
VERSION 1 (2022-06-10)
Code: Select all
#list the *bin/* (ie. command-line/terminal-executable/tty-executable programs) of all of the manually installed (apt install or dpkg -i) packages installed on your computer/PC
for str_package_name in $(apt-mark showmanual); do str_package_filelist_bin="$(dpkg --listfiles "$str_package_name" 2>/dev/null | egrep bin/ | sed 's/^/ /')"; [[ "$str_package_filelist_bin" ]] && { echo "<$str_package_name>"; echo "$str_package_filelist_bin"; echo "</$str_package_name>"; } ; done
Last edited by user6c57b8 on 2022-07-10 19:26, edited 1 time in total.