2010-05-19 13:11:16 +00:00
|
|
|
#!/usr/bin/env bash
|
2007-02-04 17:35:40 +00:00
|
|
|
|
2012-04-09 16:28:49 +00:00
|
|
|
# Either set DIR to the same value as supybot.plugins.PackageInfo.aptdir,
|
|
|
|
# or use the --dir command-line option.
|
|
|
|
DIR=""
|
2010-05-24 13:38:06 +00:00
|
|
|
|
2018-03-09 18:56:04 +00:00
|
|
|
# Be quiet by default.
|
2012-04-09 16:28:49 +00:00
|
|
|
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() {
|
2018-03-09 18:56:04 +00:00
|
|
|
cat <<EOF
|
|
|
|
Usage: $0 [OPTION]...
|
|
|
|
|
|
|
|
Updates the apt-file cache for PackageInfo.
|
|
|
|
|
|
|
|
-d, --dir <DIR> Specify directory for apt-file cache.
|
|
|
|
-v, --verbose Be 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 option.
|
|
|
|
The -d/--dir option sets the directory where this script looks for *.list files for apt-file.
|
|
|
|
EOF
|
2012-04-09 16:28:49 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 18:56:04 +00:00
|
|
|
# Prints an error message, usage (above), then exits with the specified exit value.
|
2012-04-09 16:28:49 +00:00
|
|
|
error() {
|
|
|
|
local exit_val=$1
|
|
|
|
shift
|
2018-03-09 18:56:04 +00:00
|
|
|
echo "$@" >&2
|
2012-04-09 16:28:49 +00:00
|
|
|
usage >&2
|
|
|
|
exit $exit_val
|
|
|
|
}
|
|
|
|
|
2018-03-09 18:56:04 +00:00
|
|
|
# Runs apt-file update in the specified directory for the specified distribution.
|
|
|
|
update_apt_file() {
|
2012-04-09 16:28:49 +00:00
|
|
|
if [ $VERBOSE -eq 0 ]; then
|
2018-03-09 18:56:04 +00:00
|
|
|
apt-file -N -l -c "$DIR/apt-file/$DIST" -s "$DIR/$DIST.list" -a amd64 update >/dev/null 2>&1
|
2012-04-09 16:28:49 +00:00
|
|
|
else
|
2018-03-09 18:56:04 +00:00
|
|
|
apt-file -N -l -c "$DIR/apt-file/$DIST" -s "$DIR/$DIST.list" -a amd64 update
|
2012-04-09 16:28:49 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2011-05-28 06:33:21 +00:00
|
|
|
# Check command-line arguments
|
2018-03-09 18:56:04 +00:00
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case $1 in
|
2012-04-09 16:28:49 +00:00
|
|
|
-h|--help)
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
;;
|
2009-10-12 18:26:35 +00:00
|
|
|
-v|--verbose)
|
2012-04-09 16:28:49 +00:00
|
|
|
VERBOSE=1
|
2009-10-12 18:26:35 +00:00
|
|
|
;;
|
|
|
|
-d|--dir)
|
2018-03-09 18:56:04 +00:00
|
|
|
[ -z "$2" ] && error 1 '"-d/--dir" requires an argument.'
|
2009-10-12 18:26:35 +00:00
|
|
|
shift
|
|
|
|
DIR="$1"
|
|
|
|
;;
|
2012-04-09 16:28:49 +00:00
|
|
|
--dir=*)
|
|
|
|
DIR="${1:6}"
|
2018-03-09 18:56:04 +00:00
|
|
|
[ -z "$DIR" ] && error 1 '"--dir" requires an argument.'
|
2012-04-09 16:28:49 +00:00
|
|
|
;;
|
2009-10-12 18:26:35 +00:00
|
|
|
-*)
|
2012-04-09 16:28:49 +00:00
|
|
|
error 1 "Unknown option \"$1\"."
|
2009-10-12 18:26:35 +00:00
|
|
|
;;
|
|
|
|
*)
|
2018-03-09 18:56:04 +00:00
|
|
|
error 1 "This script takes no non-argument parameters."
|
2009-10-12 18:26:35 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
2007-02-04 17:35:40 +00:00
|
|
|
|
2018-03-09 18:56:04 +00:00
|
|
|
# Check if apt-file is installed and bail if not.
|
|
|
|
if ! which apt-file >/dev/null 2>&1; then
|
|
|
|
echo "ERROR: apt-file not found. Please install apt-file in your PATH." >&2
|
2012-04-09 16:28:49 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$DIR" ]; then
|
2018-03-09 18:56:04 +00:00
|
|
|
error 1 "ERROR: No DIR set in the script and no -d/--dir option given."
|
2012-04-09 16:28:49 +00:00
|
|
|
fi
|
|
|
|
|
2018-03-09 18:56:04 +00:00
|
|
|
items=("$DIR"/*.list)
|
|
|
|
[ ! -e "${items[0]}" ] && error 1 "ERROR: Could not find any *.list files in \"$DIR\"."
|
2012-04-09 16:28:49 +00:00
|
|
|
|
2018-03-09 18:56:04 +00:00
|
|
|
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}
|
2012-04-09 16:28:49 +00:00
|
|
|
|
2018-03-09 18:56:04 +00:00
|
|
|
[ $VERBOSE -gt 0 ] && echo "INFO: Processing $DIST"
|
|
|
|
mkdir -p "$DIR/apt-file/$DIST" # Create apt-file directory if it doesn't exist
|
|
|
|
update_apt_file # Update apt-file cache
|
2012-04-09 16:28:49 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
[ $VERBOSE -eq 0 ] && echo "Try passing -v to get the error message." >&2
|
2018-03-09 18:56:04 +00:00
|
|
|
echo "ERROR: apt-file update failed for $DIST." >&2
|
|
|
|
exit_val=$?
|
2007-02-04 17:35:40 +00:00
|
|
|
fi
|
|
|
|
done
|
2018-03-09 18:56:04 +00:00
|
|
|
exit $exit_val
|