ns-update - ns-tools - Namespace utilities to reuse Open Source packaging efforts.
(HTM) git clone git://r-36.net/ns-tools
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
ns-update (1378B)
---
1 #!/bin/sh
2
3 usage() {
4 printf "usage: %s [-r] ns\n" "$(basename $1)" >&2
5 exit 1
6 }
7
8 dorecursive=0
9 while getopts "r" opt;
10 do
11 case $opt in
12 r)
13 dorecursive=1
14 ;;
15 *)
16 usage $0
17 ;;
18 esac
19 done
20 shift $(($OPTIND - 1))
21
22 [ $# -lt 1 ] && usage $0
23
24 nsroot="$(ns-root "$1")"
25 [ $? -gt 0 ] && exit $?
26
27 updatens() {
28 fnsroot="$1"
29
30 # custom
31 UPDATECMD=""
32 [ -e "$fnsroot/.ns/rc.conf" ] && . "$fnsroot/.ns/rc.conf"
33 if [ -n "$UPDATECMD" ];
34 then
35 ns-chroot "$fnsroot" "$UPDATECMD"
36 return $?
37 fi
38
39 # pacman
40 ppath="$(ns-path "$fnsroot" pacman 2>/dev/null)"
41 if [ $? -eq 0 ];
42 then
43 ns-chroot "$fnsroot" pacman -Syu
44 return $?
45 fi
46
47 # apt-get
48 apath="$(ns-path "$fnsroot" apt-get 2>/dev/null)"
49 if [ $? -eq 0 ];
50 then
51 ns-chroot "$fnsroot" apt-get update
52 [ $? -gt 0 ] && return $?
53 ns-chroot "$fnsroot" apt-get upgrade
54 return $?
55 fi
56
57 # yum
58 ypath="$(ns-path "$fnsroot" yum 2>/dev/null)"
59 if [ $? -eq 0 ];
60 then
61 ns-chroot "$fnsroot" yum update
62 return $?
63 fi
64
65 printf "Could not find update command for namespace %s.\n" "$fnsroot" >&2
66 return 1
67 }
68
69 rerrno=0
70 if [ $dorecursive -eq 1 ];
71 then
72 cd "$nsroot"
73 for ns in $(ls -1d */);
74 do
75 updatens "$nsroot/$(printf "%s\n" "$ns" | tr -d "/")"
76 [ $? -gt 0 ] && rerrno=1
77 done
78 else
79 updatens "$nsroot"
80 rerrno=$?
81 fi
82
83 if [ $rerrno -gt 0 ];
84 then
85 printf "Could not update namespace %s.\n" "$nsroot" >&2
86 exit 1
87 else
88 exit 0
89 fi
90