Magellan Linux

Contents of /branches/mage-next/src/up2date/up2date.in

Parent Directory Parent Directory | Revision Log Revision Log


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