The debian-archive-keyring package on Ubuntu doesn't automatically add its keys to APT's trust keyring, likewise for the Ubuntu package on Debian.
130 lines
3.7 KiB
Bash
Executable File
130 lines
3.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Either set DIR to the same value as supybot.plugins.PackageInfo.aptdir,
|
|
# or use the --dir command-line option.
|
|
DIR=""
|
|
|
|
# Be quiet by default.
|
|
VERBOSE=0
|
|
|
|
## Please don't change anything below this line, unless you really know what
|
|
## you are doing and don't bother me with whatever errors it produces :)
|
|
|
|
# Print usage information.
|
|
usage() {
|
|
cat <<EOF
|
|
Usage: $0 [OPTION]...
|
|
|
|
Updates the APT package cache for PackageInfo.
|
|
|
|
-d, --dir <DIR> Specify directory for APT package cache.
|
|
-v, --verbose Be more verbose than normal.
|
|
-V, --very-verbose Be even more verbose than normal.
|
|
-h, --help Display this message and exit.
|
|
|
|
Note:
|
|
Please separate each option with a space, eg:
|
|
$0 -v -d /home/bot/aptdir
|
|
Rather than:
|
|
$0 -vd /home/bot/aptdir
|
|
|
|
This script is intended to be run automatically (eg: cron), so it shows no output by default.
|
|
You can make the script more verbose with the -v/--verbose or -V/--very-verbose options.
|
|
The -d/--dir option sets the directory where this script looks for *.list files for apt-get.
|
|
EOF
|
|
}
|
|
|
|
# Prints an error message, usage (above), then exits with the specified exit value.
|
|
error() {
|
|
local exit_val=$1
|
|
shift
|
|
echo "$@" >&2
|
|
usage >&2
|
|
exit $exit_val
|
|
}
|
|
|
|
# Runs apt-get update in the specified directory for the specified distribution.
|
|
update_apt() {
|
|
if [ $VERBOSE -eq 0 ]; then
|
|
apt_args="-qq"
|
|
elif [ $VERBOSE -eq 1 ]; then
|
|
apt_args="-q"
|
|
fi
|
|
|
|
apt-get $apt_args \
|
|
-o="APT::Architecture=amd64" \
|
|
-o="APT::Architectures::=i386" \
|
|
-o="APT::Architectures::=amd64" \
|
|
-o="Dir::State::Lists=$DIR/$DIST" \
|
|
-o="Dir::State::Status=$DIR/$DIST.status" \
|
|
-o="Dir::Etc::SourceList=$DIR/$DIST.list" \
|
|
-o="Dir::Etc::SourceParts=''" \
|
|
-o="Dir::Etc::trusted=/usr/share/keyrings/debian-archive-keyring.gpg" \
|
|
-o="Dir::Etc::trusted=/usr/share/keyrings/ubuntu-archive-keyring.gpg" \
|
|
-o="Dir::Cache=$DIR/cache" \
|
|
update
|
|
}
|
|
|
|
# Check command-line arguments
|
|
while [ $# -gt 0 ]; do
|
|
case $1 in
|
|
-h|--help)
|
|
usage
|
|
exit 0
|
|
;;
|
|
-v|--verbose)
|
|
VERBOSE=1
|
|
;;
|
|
-V|--very-verbose)
|
|
VERBOSE=2
|
|
;;
|
|
-d|--dir)
|
|
[ -z "$2" ] && error 1 '"-d/--dir" requires an argument.'
|
|
shift
|
|
DIR="$1"
|
|
;;
|
|
--dir=*)
|
|
DIR="${1:6}"
|
|
[ -z "$DIR" ] && error 1 '"--dir" requires an argument.'
|
|
;;
|
|
-*)
|
|
error 1 "Unknown option \"$1\"."
|
|
;;
|
|
*)
|
|
error 1 "This script takes no non-argument parameters."
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
# Check if apt-get is installed and bail if not.
|
|
if ! which apt-get >/dev/null 2>&1; then
|
|
echo "ERROR: apt-get not found. Please install apt-get in your PATH." >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [ -z "$DIR" ]; then
|
|
error 1 "ERROR: No DIR set in the script and no -d/--dir option given."
|
|
fi
|
|
|
|
items=("$DIR"/*.list)
|
|
[ ! -e "${items[0]}" ] && error 1 "ERROR: Could not find any *.list files in \"$DIR\"."
|
|
|
|
for DIST in "${items[@]}"; do
|
|
[ -h "$DIST" ] && continue # Ignore symbolic links
|
|
# Extract the distribution name from the .list file name.
|
|
DIST=${DIST##*/}
|
|
DIST=${DIST%.list}
|
|
|
|
[ $VERBOSE -gt 0 ] && echo "INFO: Processing $DIST"
|
|
touch "$DIR/$DIST.status" # Create APT status file
|
|
mkdir -p "$DIR/$DIST/partial" # APT needs this to exist
|
|
update_apt # Update APT package cache
|
|
if [ $? -ne 0 ]; then
|
|
[ $VERBOSE -eq 0 ] && echo "Try passing -v or -V to get the error message." >&2
|
|
echo "ERROR: apt-get update failed for $DIST." >&2
|
|
exit_val=$?
|
|
fi
|
|
done
|
|
exit $exit_val
|