Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 92 lines (84 sloc) 2.06 KB
#!/bin/bash
# ~/bin/generatePkgList
NAME="generatePkgList"
BLURB="Generate a list of installed Debian/Ubuntu packages on $HOSTNAME"
SOURCE="https://github.com/vonbrownie/homebin/blob/master/generatePkgList"
set -eu
DESTINATION="."
Conf_homebin_lib() {
# A library of functions for shell scripts
local LIB="https://github.com/vonbrownie/homebin/blob/master/Library.sh"
local BINLIB="${HOME}/bin/Library.sh"
if [ -x "$BINLIB" ]; then
# shellcheck source=/dev/null
. "$BINLIB"
else
echo -e "\\n(O<"
echo "(/)_ .: ERROR: I require '$BINLIB' to do my magic!"
echo -e "\\nDownload $LIB and save as '$BINLIB'."
exit 1
fi
}
Hello_you() {
L_echo_yellow "\\n$( L_penguin ) .: Howdy!"
cat << _EOF_
NAME
$NAME
SYNOPSIS
$NAME [ options ]
OPTIONS
-d save to DESTINATION
-h print details
DESCRIPTION
$BLURB.
DEPENDS
bash, apt-show-versions
SOURCE
$SOURCE
More: ""Install (almost) the same list of Debian packages on multiple machines"
https://www.circuidipity.com/debian-package-list/
_EOF_
}
Generate_list() {
local CODENAME
CODENAME=$( L_debian_codename )
#local APT_SHOW="/usr/bin/apt-show-versions"
local PKG_LIST
PKG_LIST="${DESTINATION}/${HOSTNAME}_pkg_list.${CODENAME}.$(date +%F)"
touch "$PKG_LIST"
# Generate list of installed packages
dpkg --get-selections > "$PKG_LIST"
sed -i '/deinstall/d' "$PKG_LIST"
# Remove packages not found in the Debian archives
#if [[ -x $APT_SHOW ]]; then
# local ARRAY_PNF
# ARRAY_PNF=( $($APT_SHOW | grep -v "$CODENAME" | awk -F: '{print $1}') )
# for package in "${ARRAY_PNF[@]}"
# do
# sed -i "/$package/d" "$PKG_LIST"
# done
#else
# L_echo_red "\n$( L_penguin ) .: ERROR: Command '$APT_SHOW' not found."
#fi
}
Run_options() {
while getopts ":hd:" OPT
do
case $OPT in
h)
Hello_you
exit
;;
d)
DESTINATION=$2
;;
?)
L_echo_red "\\n$( L_penguin ) .: ERROR: Invalid option '-$OPTARG'"
exit 1
;;
esac
done
}
Conf_homebin_lib
Run_options "$@"
Generate_list
You can’t perform that action at this time.