3 changed files with 126 additions and 3 deletions
@ -1,3 +1,38 @@
|
||||
# pkgupdate |
||||
# Presentation |
||||
|
||||
OpenBSD efficient stable updater |
||||
**pkgupdate** is a simple shell script meant for OpenBSD users of the stable branchs (people following releases) to easily keep their packages up to date. |
||||
|
||||
It is meant to be run daily by cron on servers on at boot time for workstations (you can obviously configure it how you prefer). |
||||
|
||||
# How? |
||||
|
||||
**pkgupdate** uses 3 tricks to speed up the process, this is particularily important for workstations updating during the boot process: |
||||
|
||||
- fetch the index of packages and compare it between runs (using a cache in `/var/cache/pkgupdate/`) |
||||
- if the index changed, which mean everytime a new package is updated, then it only try to update the packages available in the `packages-stable` directory |
||||
- if curl is installed, use curl instead of ftp(1) command |
||||
|
||||
# Why? |
||||
|
||||
This tool is based on solene@ previous work [faster packages updates](https://dataswamp.org/~solene/2021-08-06-openbsd-pkgadd-tuning-updates.html) and [pkg_add performance analysis](https://dataswamp.org/~solene/2021-07-08-openbsd-pkg_add_performance_analysis.html). |
||||
|
||||
In my opinion, workstations should be updated as soon as possible, at boot time, to update packages at boot before using anything from the user session, avoiding a boring reboot. |
||||
|
||||
As for servers, making the process faster is always welcome. |
||||
|
||||
# Setup |
||||
|
||||
First, use `git clone https://tildegit.org/solene/pkgupdate.git` and copy `pkgupdate` in `/usr/local/bin/`. |
||||
|
||||
Best way to manage this is to use root's crontab. As root, type `crontab -e` to edit its tab. |
||||
|
||||
``` |
||||
# for updating on boot |
||||
@reboot /usr/local/bin/pkgupdate |
||||
|
||||
# for updating every hour |
||||
@hourly /usr/local/bin/pkgupdate |
||||
|
||||
# for updating every 6 hours |
||||
0 */6 * * * /usr/local/bin/pkgupdate |
||||
``` |
||||
|
@ -0,0 +1,88 @@
|
||||
#!/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 |
Loading…
Reference in new issue