Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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