Merge pull request #684 from zhaostu/master
Update type `__package_update_index`
This commit is contained in:
commit
fbc129e2ef
5 changed files with 69 additions and 40 deletions
|
@ -17,18 +17,24 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
os="$("$__explorer/os")"
|
type="$($__type_explorer/type)"
|
||||||
|
|
||||||
case "$os" in
|
case "$type" in
|
||||||
debian|ubuntu|devuan)
|
apt)
|
||||||
if [ -f "/var/cache/apt/pkgcache.bin" ]; then
|
if [ -f "/var/cache/apt/pkgcache.bin" ]; then
|
||||||
echo $(($(date +"%s")-$(stat --format '%Y' /var/cache/apt/pkgcache.bin)))
|
echo $(($(date +"%s")-$(stat --format '%Y' /var/cache/apt/pkgcache.bin)))
|
||||||
else
|
else
|
||||||
echo 0
|
echo 0
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
*) echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2
|
pacman)
|
||||||
|
if [ -d "/var/lib/pacman/sync" ]; then
|
||||||
|
echo $(($(date +"%s")-$(stat --format '%Y' /var/lib/pacman/sync)))
|
||||||
|
else
|
||||||
|
echo 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*) echo "Your specified type ($type) is currently not supported." >&2
|
||||||
echo "Please contribute an implementation for it if you can." >&2
|
echo "Please contribute an implementation for it if you can." >&2
|
||||||
exit 1
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
34
cdist/conf/type/__package_update_index/explorer/type
Normal file
34
cdist/conf/type/__package_update_index/explorer/type
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# 2018 Stu Zhao (z12y12l12 at gmail.com)
|
||||||
|
#
|
||||||
|
# This file is part of cdist.
|
||||||
|
#
|
||||||
|
# cdist is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# cdist is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
if [ -f "$__object/parameter/type" ]; then
|
||||||
|
cat "$__object/parameter/type"
|
||||||
|
else
|
||||||
|
# By default determine package manager based on operating system
|
||||||
|
os="$($__explorer/os)"
|
||||||
|
case "$os" in
|
||||||
|
amazon|scientific|centos|fedora|redhat) echo "yum" ;;
|
||||||
|
debian|ubuntu|devuan) echo "apt" ;;
|
||||||
|
archlinux) echo "pacman" ;;
|
||||||
|
*)
|
||||||
|
echo "Don't know how to manage packages on: $os" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
|
@ -21,49 +21,34 @@
|
||||||
# Update the package index with the appropriate package manager
|
# Update the package index with the appropriate package manager
|
||||||
#
|
#
|
||||||
|
|
||||||
type="$__object/parameter/type"
|
type=$(cat "$__object/explorer/type")
|
||||||
|
currage="$(cat "$__object/explorer/currage")"
|
||||||
if [ -f "$__object/parameter/maxage" ]; then
|
if [ -f "$__object/parameter/maxage" ]; then
|
||||||
maxage="$(cat "$__object/parameter/maxage")"
|
maxage="$(cat "$__object/parameter/maxage")"
|
||||||
currage="$(cat "$__object/explorer/currage")"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "$type" ]; then
|
if [ -n "$maxage" ]; then
|
||||||
type="$(cat "$type")"
|
if [ "$type" != "apt" -a "$type" != "pacman" ]; then
|
||||||
else
|
echo "ERROR: \"--maxage\" only supported for \"apt\" or \"pacman\" pkg-manager." >&2
|
||||||
# By default determine package manager based on operating system
|
exit 1
|
||||||
os="$(cat "$__global/explorer/os")"
|
elif [ $currage -lt $maxage ]; then
|
||||||
case "$os" in
|
exit 0 # no need to update
|
||||||
amazon|scientific|centos|fedora|redhat) type="yum" ;;
|
fi
|
||||||
debian|ubuntu|devuan) type="apt" ;;
|
|
||||||
archlinux) type="pacman" ;;
|
|
||||||
*)
|
|
||||||
echo "Don't know how to manage packages on: $os" >&2
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$maxage" ] && [ "$type" != "apt" ]; then
|
|
||||||
echo "ERROR: \"--maxage\" only supported for \"apt\" pkg-manager." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
case "$type" in
|
case "$type" in
|
||||||
yum) ;;
|
yum) ;;
|
||||||
apt) if [ -n "$maxage" ]; then
|
apt)
|
||||||
## check if we need to update:
|
echo "apt-get --quiet update"
|
||||||
if [ $currage -ge $maxage ]; then
|
echo "apt-cache updated (age was: $currage)" >> "$__messages_out"
|
||||||
echo "apt-get --quiet update"
|
;;
|
||||||
echo "apt-cache updated (age was: $currage)" >> "$__messages_out"
|
pacman)
|
||||||
fi
|
echo "pacman --noprogressbar --sync --refresh"
|
||||||
else
|
echo "pacman package database synced (age was: $currage)" >> "$__messages_out"
|
||||||
echo "apt-get --quiet update"
|
;;
|
||||||
echo "apt-cache updated (age was: $currage)" >> "$__messages_out"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
pacman) echo "pacman --noprogressbar --sync --refresh" ;;
|
|
||||||
*)
|
*)
|
||||||
echo "Don't know how to manage packages on: $os" >&2
|
echo "Don't know how to manage packages for type: $type" >&2
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -28,8 +28,8 @@ type
|
||||||
* pacman for Arch Linux
|
* pacman for Arch Linux
|
||||||
|
|
||||||
maxage
|
maxage
|
||||||
Available for package manager apt, max time in seconds since last update.
|
Available for package manager apt and pacman, max time in seconds since
|
||||||
Repo update is skipped if maxage is not reached yet.
|
last update. Repo update is skipped if maxage is not reached yet.
|
||||||
|
|
||||||
MESSAGES
|
MESSAGES
|
||||||
--------
|
--------
|
||||||
|
@ -51,6 +51,7 @@ EXAMPLES
|
||||||
|
|
||||||
# Only update every hour:
|
# Only update every hour:
|
||||||
__package_update_index --maxage 3600 --type apt
|
__package_update_index --maxage 3600 --type apt
|
||||||
|
|
||||||
# same as above (on apt-type systems):
|
# same as above (on apt-type systems):
|
||||||
__package_update_index --maxage 3600
|
__package_update_index --maxage 3600
|
||||||
|
|
||||||
|
@ -58,6 +59,7 @@ AUTHORS
|
||||||
-------
|
-------
|
||||||
| Ricardo Catalinas Jiménez <jimenezrick--@--gmail.com>
|
| Ricardo Catalinas Jiménez <jimenezrick--@--gmail.com>
|
||||||
| Thomas Eckert <tom--@--it-eckert.de>
|
| Thomas Eckert <tom--@--it-eckert.de>
|
||||||
|
| Stu Zhao <z12y12l12--@--gmail.com>
|
||||||
|
|
||||||
|
|
||||||
COPYING
|
COPYING
|
||||||
|
|
|
@ -6,6 +6,8 @@ next:
|
||||||
* Type __systemd_unit: Fix minor issues and add masking unit files support (Adam Dej)
|
* Type __systemd_unit: Fix minor issues and add masking unit files support (Adam Dej)
|
||||||
* Type __grafana_dashboard: Fix devuan ascii support (Dominique Roux)
|
* Type __grafana_dashboard: Fix devuan ascii support (Dominique Roux)
|
||||||
* Type __apt_source: Add nonparallel marker (Darko Poljak)
|
* Type __apt_source: Add nonparallel marker (Darko Poljak)
|
||||||
|
* Type __package_update_index: Fix error when using OS not using apt (Stu Zhao)
|
||||||
|
* Type __package_update_index: Support --maxage for type pacman (Stu Zhao)
|
||||||
|
|
||||||
4.10.1: 2018-06-21
|
4.10.1: 2018-06-21
|
||||||
* Type __letsencrypt_cert: Fix temp file location and removal (Darko Poljak)
|
* Type __letsencrypt_cert: Fix temp file location and removal (Darko Poljak)
|
||||||
|
|
Loading…
Reference in a new issue