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=""
|
|
|
|
|
|
|
|
# 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() {
|
|
|
|
echo "Usage $0 [OPTION]..."
|
|
|
|
echo "Updates the APT package cache for PackageInfo"
|
|
|
|
echo ""
|
|
|
|
echo "-h, --help Display this message and exit."
|
|
|
|
echo "-v, --verbose Be more verbose than normal."
|
|
|
|
echo "-V, --very-verbose Be even more verbose than normal."
|
|
|
|
echo "-d, --dir[=DIR] Sets the directory to use when updating the APT package cache."
|
|
|
|
echo ""
|
|
|
|
echo "Note:"
|
|
|
|
echo " Please separate each option with a space, eg:"
|
|
|
|
echo " $0 -v -d /home/bot/aptdir"
|
|
|
|
echo " Rather than:"
|
|
|
|
echo " $0 -vd /home/bot/aptdir"
|
|
|
|
echo ""
|
|
|
|
echo "This script is intended to be ran automatically (eg: cron), so it shows no output by default."
|
|
|
|
echo "You can make the script more verbose with either the -v/--verbose or -V/--very-verbose options."
|
|
|
|
echo "The -d/--dir option sets the directory where this script looks for *.list files for apt-get."
|
|
|
|
}
|
|
|
|
|
|
|
|
# Prints an error message, usage (above), then exit 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() {
|
|
|
|
local apt_dir="$1"
|
|
|
|
local dist="$2"
|
|
|
|
local apt_args=""
|
|
|
|
|
|
|
|
if [ $VERBOSE -eq 0 ]; then
|
|
|
|
apt_args="-qq"
|
|
|
|
elif [ $VERBOSE -eq 1 ]; then
|
|
|
|
apt_args="-q"
|
|
|
|
fi
|
|
|
|
|
|
|
|
apt-get $apt_args -o="APT::Architecture=i386" \
|
|
|
|
-o="APT::Architectures::=i386" \
|
|
|
|
-o "APT::Architectures::=amd64" \
|
|
|
|
-o="Dir::State::Lists=$apt_dir/$dist" \
|
|
|
|
-o="Dir::State::Status=$apt_dir/$dist.status" \
|
|
|
|
-o="Dir::Cache=$apt_dir/cache" \
|
|
|
|
-o="Dir::Etc::SourceList=$apt_dir/$dist.list" \
|
|
|
|
update
|
|
|
|
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
# main()
|
2009-10-12 18:26:35 +00:00
|
|
|
|
2012-04-09 16:28:49 +00:00
|
|
|
# Acepted arguments are:
|
|
|
|
# -h,--help
|
|
|
|
# -v,--verbose
|
|
|
|
# -V,--very-verbose
|
|
|
|
# -d,--dir[=DIR]
|
2009-10-12 18:26:35 +00:00
|
|
|
|
2011-05-28 06:33:21 +00:00
|
|
|
# Check command-line arguments
|
2012-04-09 16:28:49 +00:00
|
|
|
while [ $# -gt 0 ]; do
|
2009-10-12 18:26:35 +00:00
|
|
|
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
|
2010-04-13 01:12:54 +00:00
|
|
|
;;
|
|
|
|
-V|--very-verbose)
|
2012-04-09 16:28:49 +00:00
|
|
|
VERBOSE=2
|
2009-10-12 18:26:35 +00:00
|
|
|
;;
|
|
|
|
-d|--dir)
|
2012-04-09 16:28:49 +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}"
|
|
|
|
[ -z "$DIR" ] && error 1 "\"--dir\" requires an argument."
|
|
|
|
;;
|
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
|
|
|
;;
|
|
|
|
*)
|
2012-04-09 16:28:49 +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
|
|
|
|
2012-04-09 16:28:49 +00:00
|
|
|
apt_get=$(which apt-get 2>/dev/null)
|
|
|
|
|
|
|
|
# Check that apt-get exists and bail if it doesn't.
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "ERROR: apt-get not found. Please install apt-get in your \$PATH." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
#TODO: Remove this section and error out if DIR is not set,
|
|
|
|
# This could hide errors where DIR/-d was not set, an error message.
|
|
|
|
if [ -z "$DIR" ]; then
|
|
|
|
DIR=/home/bot/aptdir
|
|
|
|
echo "WARNING: No DIR set and no -d/--dir option given, defaulting to \"$DIR\"" >&2
|
|
|
|
echo "WARNING: Please set DIR on line 5 of $(readlink -f $0) or use the -d/--dir option" >&2
|
|
|
|
fi
|
|
|
|
|
|
|
|
#[ -z "$DIR" ] && error 1 "ERROT: Please set DIR on line 5 of $(readlink -f $0) or use the -d/--dir option"
|
|
|
|
|
|
|
|
DIR="$(echo $DIR | sed 's,/*$,,')" # Normalize $DIR
|
|
|
|
|
|
|
|
items=$(ls "${DIR}"/*.list 2>/dev/null)
|
|
|
|
[ $? -ne 0 ] && error 1 "Could not find \"*.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:${#DIR}}"
|
|
|
|
DIST="${DIST/.list}"
|
|
|
|
DIST="${DIST:1}"
|
|
|
|
|
|
|
|
touch "${DIR}/${DIST}.status" # Create APT status file
|
|
|
|
mkdir -p "${DIR}/${DIST}/partial" # APT needs this to exist
|
|
|
|
update_apt "$DIR" "$DIST" # Update the package list with apt-get
|
2007-02-04 17:35:40 +00:00
|
|
|
done
|
2012-04-09 16:28:49 +00:00
|
|
|
|