Contents of /branches/mage-next/src/up2date/up2date.in
Parent Directory | Revision Log
Revision 2607 -
(show annotations)
(download)
Tue Mar 4 14:57:09 2014 UTC (10 years, 6 months ago) by niro
File size: 5423 byte(s)
Tue Mar 4 14:57:09 2014 UTC (10 years, 6 months ago) by niro
File size: 5423 byte(s)
-mage use of common.functions.sh
1 | #!/bin/bash |
2 | |
3 | die() { echo "Error: $@"; exit 1; } |
4 | |
5 | # include all needed files |
6 | [ -f /etc/mage.rc.global ] && source /etc/mage.rc.global || die "/etc/mage.rc.global missing" |
7 | [ -f ${MAGERC} ] && source ${MAGERC} || die "Your ${MAGERC} is missing. Aborting." |
8 | # overrides die() function |
9 | [ -f ${MLIBDIR}/common.functions.sh ] && source ${MLIBDIR}/common.functions.sh || die "common mage functions missing" |
10 | [ -f ${MLIBDIR}/mage4.functions.sh ] && source ${MLIBDIR}/mage4.functions.sh || die "mage functions missing" |
11 | [ -f ${MLIBDIR}/smage2.functions.sh ] && source ${MLIBDIR}/smage2.functions.sh || die "smage functions missing" |
12 | [ -f /etc/up2date.conf ] && source /etc/up2date.conf || die "/etc/up2date.conf missing" |
13 | |
14 | # respect repos from env or load repos from config file |
15 | if [[ -z ${REPOS} ]] && [[ -n ${SMAGE_REPOS} ]] |
16 | then |
17 | REPOS="${SMAGE_REPOS}" |
18 | fi |
19 | # sane default |
20 | : ${REPOS="${SMAGESCRIPTSDIR}/core ${SMAGESCRIPTSDIR}/extras ${SMAGESCRIPTSDIR}/nonfree ${SMAGESCRIPTSDIR}/todo"} |
21 | |
22 | # always be silent |
23 | SILENT=1 |
24 | FVERBOSE=off |
25 | |
26 | # load all up2date includes |
27 | for inc in ${MLIBDIR}/up2date/*.sh |
28 | do |
29 | source ${inc} |
30 | done |
31 | |
32 | updatecmd() |
33 | { |
34 | local uppver |
35 | local useragent |
36 | [[ ! -z ${UP2USERAGENT} ]] && useragent="-useragent '${UP2USERAGENT}'" |
37 | |
38 | uppver=$(lynx -connect_timeout=${LYNX_CONNECT_TIMEOUT} -read_timeout=${LYNX_READ_TIMEOUT} -dump "${useragent}" $@) |
39 | if [[ $? -ne 0 ]] |
40 | then |
41 | echo "Error connecting '$@'" |
42 | sleep 1 |
43 | return 1 |
44 | fi |
45 | |
46 | if [[ ! -z ${UP2SUBSTITUTE} ]] |
47 | then |
48 | echo "${uppver}" | sed "s:${UP2SUBSTITUTE}::g" |
49 | else |
50 | echo "${uppver}" |
51 | fi |
52 | } |
53 | |
54 | updateme() |
55 | { |
56 | local smage="$1" |
57 | local ONLY_PRINT_UPSTREAM |
58 | |
59 | if [[ $1 = --upstream ]] || [[ $1 = -u ]] |
60 | then |
61 | if [[ -z $2 ]] || [[ ${2##*.} != smage2 ]] |
62 | then |
63 | echo "you must give me a smagefile." |
64 | exit 1 |
65 | fi |
66 | ONLY_PRINT_UPSTREAM=1 |
67 | smage="$2" |
68 | fi |
69 | |
70 | local PNAME |
71 | local PCATEGORIE |
72 | local PCAT |
73 | local PVER |
74 | local UP2DATE |
75 | local UP2PVER |
76 | local UP2TARBALL |
77 | local UP2SUBDIR |
78 | local UP2SUBSTITUTE |
79 | local UP2USERAGENT |
80 | local UP2EXCLUDE |
81 | local UP2SEPERATOR |
82 | local UP2OPTS |
83 | local UPSTREAM_PVER |
84 | |
85 | PNAME="$(get_value_from_magefile PNAME ${smage})" |
86 | PCATEGORIE="$(get_value_from_magefile PCATEGORIE ${smage})" |
87 | PCAT="$(get_value_from_magefile PCAT ${smage})" |
88 | PVER="$(get_value_from_magefile PVER ${smage})" |
89 | UP2PVER="$(get_value_from_magefile UP2PVER ${smage})" |
90 | UP2TARBALL="$(get_value_from_magefile UP2TARBALL ${smage})" |
91 | UP2SUBDIR="$(get_value_from_magefile UP2SUBDIR ${smage})" |
92 | UP2SUBSTITUTE="$(get_value_from_magefile UP2SUBSTITUTE ${smage})" |
93 | UP2USERAGENT="$(get_value_from_magefile UP2USERAGENT ${smage})" |
94 | UP2EXCLUDE="$(get_value_from_magefile UP2EXCLUDE ${smage})" |
95 | UP2SEPERATOR="$(get_value_from_magefile UP2SEPERATOR ${smage})" |
96 | UP2OPTS="$(get_value_from_magefile UP2OPTS ${smage})" |
97 | |
98 | [[ -z ${UP2PVER} ]] && UP2PVER="${PVER}" |
99 | |
100 | UP2DATE=$(get_value_from_magefile UP2DATE ${smage}) |
101 | |
102 | if [[ -z ${UP2DATE} ]] |
103 | then |
104 | continue |
105 | fi |
106 | |
107 | UPSTREAM_PVER=$(eval "${UP2DATE}") |
108 | if [[ ${ONLY_PRINT_UPSTREAM} = 1 ]] |
109 | then |
110 | echo "${UPSTREAM_PVER}" |
111 | else |
112 | local retval |
113 | retval=$(${MLIBDIR}/vercomp "${UP2PVER}" "${UPSTREAM_PVER}") |
114 | [ ${retval} -eq 0 ] && echo -e "${PNAME}: ${COLGREEN}'${UP2PVER}' = '${UPSTREAM_PVER}'${COLDEFAULT}" |
115 | [ ${retval} -lt 0 ] && echo -e "${PNAME}: ${COLRED}'${UP2PVER}' < '${UPSTREAM_PVER}'${COLDEFAULT}" |
116 | [ ${retval} -gt 0 ] && echo -e "${PNAME}: ${COLYELLOW}'${UP2PVER}' > '${UPSTREAM_PVER}'${COLDEFAULT}" |
117 | fi |
118 | } |
119 | |
120 | updateall() |
121 | { |
122 | #local REPOS |
123 | local PACKAGE |
124 | local smage |
125 | local repo |
126 | local UP2DATE_SLEEP_COUNT=15 |
127 | local UP2DATE_SLEEP_TIMEOUT=3 |
128 | local ONLY_PRINT_UPSTREAM=0 |
129 | local c |
130 | |
131 | PACKAGE="*" |
132 | [[ ! -z $1 ]] && PACKAGE="$1" |
133 | |
134 | if [[ $1 = --upstream ]] || [[ $1 = -u ]] |
135 | then |
136 | if [[ -z $2 ]] || [[ ${2##*.} != smage2 ]] |
137 | then |
138 | echo "you must give me a smagefile." |
139 | exit 1 |
140 | fi |
141 | updateme $1 $2 |
142 | return 0 |
143 | fi |
144 | |
145 | ############################################################################## |
146 | # recurse all depends if requested |
147 | # |
148 | if [[ $1 = --depend ]] || [[ $1 = -d ]] |
149 | then |
150 | if [[ -z $2 ]] || [[ ${2##*.} != smage2 ]] |
151 | then |
152 | echo "you must give me a smagefile." |
153 | exit 1 |
154 | fi |
155 | |
156 | SMAGEFILE="$2" |
157 | PACKAGE="$(magename2pname ${SMAGEFILE})" |
158 | |
159 | echo "processing '${SMAGEFILE}' ..." |
160 | echo "running dependency checks for package '${PACKAGE}'..." |
161 | |
162 | DEPEND=$(get_value_from_magefile DEPEND ${SMAGEFILE}) |
163 | SDEPEND=$(get_value_from_magefile SDEPEND ${SMAGEFILE}) |
164 | |
165 | declare -i c=0 |
166 | while read sign dep |
167 | do |
168 | case ${dep} in |
169 | "") continue;; |
170 | esac |
171 | |
172 | # sleep every 15 packages for 5 seconds |
173 | (( c++ )) |
174 | if [[ ${c} -eq ${UP2DATE_SLEEP_COUNT} ]] |
175 | then |
176 | declare -i c=0 |
177 | echo "DEBUG: Sleep Count (${UP2DATE_SLEEP_COUNT}x) reached, sleeping for ${UP2DATE_SLEEP_TIMEOUT} seconds ..." |
178 | sleep ${UP2DATE_SLEEP_TIMEOUT} |
179 | fi |
180 | #echo "debug: ${dep}" |
181 | updateme "$(dep2pname ${dep})" |
182 | done << EOF |
183 | ${DEPEND} |
184 | ${SDEPEND} |
185 | EOF |
186 | fi |
187 | # |
188 | # eof recurse |
189 | ############################################################################## |
190 | |
191 | for repo in ${REPOS} |
192 | do |
193 | # exclude not existing |
194 | [[ ${PACKAGE} != \* ]] && [[ ! -d ${repo}/${PACKAGE} ]] && continue |
195 | |
196 | declare -i c=0 |
197 | for smage in ${repo}/${PACKAGE}/*.smage2 |
198 | do |
199 | updateme ${smage} |
200 | |
201 | # sleep every 15 packages for 5 seconds |
202 | (( c++ )) |
203 | if [[ ${c} -eq ${UP2DATE_SLEEP_COUNT} ]] |
204 | then |
205 | declare -i c=0 |
206 | echo "DEBUG: Sleep Count (${UP2DATE_SLEEP_COUNT}x) reached, sleeping for ${UP2DATE_SLEEP_TIMEOUT} seconds ..." |
207 | sleep ${UP2DATE_SLEEP_TIMEOUT} |
208 | fi |
209 | done |
210 | done |
211 | } |
212 | |
213 | updateall $@ |