pkgupdate/pkgupdate

89 lines
1.8 KiB
Bash

#!/bin/sh
INSTALLURL=$(grep -v ^# /etc/installurl | head -n 1)
export PKG_PATH="${INSTALLURL}/$(uname -r)/packages-stable/$(machine)/"
CACHE_DIR=/var/cache/pkgupdate/
def_curl() {
if type curl 2> /dev/null >/dev/null
then
export FETCH_CMD="/usr/local/bin/curl -L -s -q -N"
fi
}
check_cache() {
# creating cache directory
if ! install -d -o root -g wheel -m 755 ${CACHE_DIR}
then
echo "Error when creating the cache directory ${CACHE_DIR}"
exit 1
fi
ftp -o - "$PKG_PATH" 2>/dev/null | grep tgz > ${CACHE_DIR}/index.now
if [ $? -eq 0 ]
then
# check if we already used pkgupdate
if [ ! -f ${CACHE_DIR}/index.previous ]
then
# first time we use it
mv ${CACHE_DIR}/index.now ${CACHE_DIR}/index.previous
else
# compare current output with the previous one
# if they are identical, no changes has been done
if cmp ${CACHE_DIR}/index.now ${CACHE_DIR}/index.previous
then
rm ${CACHE_DIR}/index.now
echo "No changes on the mirror."
exit 0
fi
fi
else
echo "error when downloading the index, return $?"
exit 1
fi
}
do_http() {
echo "Updating using $1 protocol"
check_cache
def_curl
pkg_add -u 2>&1 | grep -v "^Couldn't find updates for "
}
do_https() {
do_http "https://"
}
unsupported() {
echo "protocol not supported: $1"
exit 1
}
unknown() {
echo "protocol not known for $1"
exit 1
}
if sysctl kern.version | grep -- "-current" >/dev/null
then
echo "You can't use this on -current"
exit 1
fi
case "$INSTALLURL" in
http://*) do_http "http://"
;;
https://*) do_https "https://"
;;
ftp://*) unsupported ftp
;;
scp://*) unsupported scp
;;
*) unknown "$INSTALLURL"
;;
esac