rev |
line source |
al@844
|
1 #!/bin/sh
|
al@844
|
2 # TazPkg - Tiny autonomous zone packages manager, hg.slitaz.org/tazpkg
|
al@844
|
3 # install - TazPkg module
|
al@844
|
4 # Install packages
|
al@844
|
5
|
al@844
|
6
|
al@844
|
7 # Connect function libraries
|
paul@936
|
8 . /lib/libtaz.sh
|
al@844
|
9 . /usr/lib/slitaz/libpkg.sh
|
al@844
|
10
|
al@844
|
11
|
al@844
|
12 # Get TazPkg working environment
|
al@844
|
13 . @@MODULES@@/getenv
|
al@844
|
14 # $CACHE_DIR will change, it based on unchanged value of $SAVE_CACHE_DIR
|
al@844
|
15 SAVE_CACHE_DIR="$CACHE_DIR"
|
al@844
|
16
|
al@844
|
17
|
al@844
|
18 . @@MODULES@@/find-depends
|
al@844
|
19
|
al@844
|
20
|
al@844
|
21
|
al@844
|
22
|
al@844
|
23 # Log TazPkg activity
|
al@844
|
24
|
al@844
|
25 log_pkg() {
|
al@844
|
26 debug "\nlog_pkg('$1')\n PACKAGE='$PACKAGE'\n VERSION='$VERSION'\n EXTRAVERSION='$EXTRAVERSION'"
|
al@844
|
27
|
al@844
|
28 local extra
|
al@844
|
29
|
al@844
|
30 [ "$1" == 'Installed' ] && \
|
al@844
|
31 extra=" - $(fgrep " $PACKAGE-$VERSION" "$PKGS_DB/installed.$SUM" | awk '{print $1}')"
|
al@844
|
32 debug " extra='$extra'"
|
al@844
|
33
|
al@844
|
34 [ -w "$LOG" ] &&
|
al@844
|
35 echo "$(date +'%F %T') - $1 - $PACKAGE ($VERSION$EXTRAVERSION)$extra" >> $LOG
|
al@844
|
36 }
|
al@844
|
37
|
al@844
|
38
|
al@844
|
39 # get an already installed package from packages.equiv
|
al@844
|
40
|
al@844
|
41 equivalent_pkg() {
|
al@945
|
42 # input: $1 = dependency package name (like "nano");
|
al@945
|
43 # $2 = package path/name for which dependency tested
|
al@844
|
44 local i rep rules rule out
|
al@844
|
45
|
al@945
|
46 if [ -n "$local" ]; then
|
al@945
|
47 # Search for virtual packages
|
al@945
|
48 if [ -n "$cookmode" ]; then
|
al@945
|
49 pi='/home/slitaz/packages/packages.info'
|
al@968
|
50 [ -e "$pi" ] || pi="/home/slitaz/packages/packages-$SLITAZ_ARCH.info"
|
al@945
|
51 else
|
al@945
|
52 pi="$(dirname "$2")/packages.info"
|
al@945
|
53 fi
|
al@945
|
54 [ -f "$pi" ] &&
|
al@945
|
55 out=$(awk -F$'\t' -vpkg="$1" '{
|
al@945
|
56 # if package name or provided package name matched
|
al@945
|
57 if ($1 == pkg || index(" " $10 " ", " " pkg " ")) { print $1 }
|
al@945
|
58 }' "$pi")
|
al@945
|
59 for i in $out; do
|
al@945
|
60 # If package installed
|
al@945
|
61 [ -f "$PKGS_DB/installed/$i/receipt" ] && out="$i" && break
|
al@945
|
62 unset out
|
al@945
|
63 done
|
al@945
|
64 else
|
al@945
|
65 rules=$(for rep in $PRIORITY; do
|
al@945
|
66 grep -hs "^$1=" "$rep/packages.equiv"
|
al@945
|
67 done | sed "s|^$1=||")
|
al@945
|
68 debug " >rules='$rules'"
|
al@844
|
69
|
al@945
|
70 for rule in $rules; do
|
al@945
|
71 debug " >rule='$rule'"
|
al@945
|
72 case $rule in
|
al@945
|
73 *:*)
|
al@945
|
74 debug '-- x:x'
|
al@945
|
75 # format 'alternative:newname'
|
al@945
|
76 # if alternative is installed then substitute newname
|
al@945
|
77 out="${rule#*:}"
|
al@945
|
78 awk -F$'\t' -vp="${rule%:*}" '$1==p{exit 1}' "$PKGS_DB/installed.info" || break
|
al@945
|
79 debug '-- x:x /'
|
al@945
|
80 ;;
|
al@945
|
81 *)
|
al@945
|
82 debug '-- x'
|
al@945
|
83 # unconditional substitution
|
al@945
|
84 out="$rule"
|
al@945
|
85 awk -F$'\t' -vp="$rule" '$1==p{exit 1}' "$PKGS_DB/installed.info" || break
|
al@945
|
86 debug '-- x /'
|
al@945
|
87 ;;
|
al@945
|
88 esac
|
al@945
|
89 unset out
|
al@945
|
90 done
|
al@945
|
91 fi
|
al@844
|
92 debug '--'
|
al@844
|
93 # if not found in packages.equiv then no substitution
|
al@844
|
94 echo "${out:-$1}"
|
al@844
|
95 }
|
al@844
|
96
|
al@844
|
97
|
al@844
|
98 # Check and install all missing deps.
|
al@844
|
99 # Auto install or ask user then install all missing deps from local dir, CD-ROM,
|
al@844
|
100 # media or from the mirror.
|
al@844
|
101
|
al@846
|
102 install_all_deps() {
|
al@844
|
103 # input: $1 = package file to check/install missing dependencies
|
al@844
|
104 # ROOT READY
|
al@844
|
105 # dep: equivalent_pkg.
|
al@844
|
106
|
al@844
|
107 debug "\ninstall_all_deps('$1')"
|
al@844
|
108
|
al@844
|
109 local TMP_DIR DEPENDS num missing_packages equiv pkg answer dir found pkgfile
|
al@844
|
110
|
al@844
|
111 # Check for missing deps listed in a receipt packages.
|
al@844
|
112
|
al@844
|
113 # Get the receipt's variable DEPENDS
|
al@844
|
114 DEPENDS=$(
|
al@844
|
115 TMP_DIR=$(mktemp -d); cd "$TMP_DIR"
|
al@957
|
116 cpio --quiet -i receipt < "$1" >/dev/null 2>&1
|
al@950
|
117 . ./receipt; echo $DEPENDS
|
al@844
|
118 rm -rf "$TMP_DIR"
|
al@957
|
119 )
|
al@844
|
120
|
al@844
|
121 unset num missing_packages
|
al@844
|
122 for depend in $DEPENDS; do
|
al@844
|
123 debug " depend='$depend'"
|
al@945
|
124 equiv=$(equivalent_pkg $depend "$1")
|
al@844
|
125 debug " equiv='$equiv'\n"
|
al@844
|
126 if [ ! -d "$INSTALLED/$equiv" ]; then
|
al@844
|
127 missing_packages="$missing_packages $equiv"
|
al@844
|
128 num=$((num+1))
|
al@844
|
129 elif [ ! -f "$INSTALLED/$equiv/receipt" ]; then
|
al@880
|
130 [ -z "$quiet" ] && _ 'WARNING! Dependency loop between "%s" and "%s".' "$PACKAGE" "$equiv"
|
al@844
|
131 fi
|
al@844
|
132 done
|
al@844
|
133
|
al@844
|
134 # Nothing to install, exit function
|
al@844
|
135 [ -z "$num" ] && return
|
al@844
|
136
|
al@844
|
137
|
al@880
|
138 title "$(_ 'Tracking dependencies for package "%s"' "$PACKAGE")"
|
al@844
|
139
|
al@844
|
140 # Individual messages for each missing package
|
al@878
|
141 [ -z "$quiet" ] && \
|
al@844
|
142 for pkg in $missing_packages; do
|
al@844
|
143 _ 'Missing package "%s"' "$pkg"
|
al@844
|
144 done
|
al@844
|
145
|
al@880
|
146 footer "$(_p \
|
al@844
|
147 '%s missing package to install.' \
|
al@844
|
148 '%s missing packages to install.' "$num" \
|
al@844
|
149 "$num")"
|
al@844
|
150
|
al@844
|
151
|
pascal@916
|
152 if [ "$AUTO_INSTALL_DEPS" == 'yes' ] || [ -n "$quiet" ]; then
|
paul@943
|
153 # Quietly not displaying anything. Assume 'yes' unless '--noconfirm' is provided
|
al@844
|
154 answer=0
|
al@913
|
155 [ -n "$noconfirm" ] && answer=1
|
al@844
|
156 else
|
al@913
|
157 # Display question; wait for answer or print auto-answer
|
al@844
|
158 newline
|
al@844
|
159 confirm "$(_ 'Install all missing dependencies? (y/N)')"
|
al@844
|
160 answer=$?
|
al@844
|
161 newline
|
al@844
|
162 fi
|
al@844
|
163 debug " answer='$answer'"
|
al@844
|
164
|
al@844
|
165 dir="$(dirname "$1")"
|
al@844
|
166 debug " dir='$dir'"
|
al@844
|
167
|
paul@943
|
168 # We can install packages from /home/boot/packages at boot time
|
al@844
|
169 # Also we can prefer local packages over mirrored/cached using '--local' option
|
al@844
|
170 [ "$dir" == '/home/boot/packages' ] && local='yes'
|
al@844
|
171 debug " local='$local'"
|
al@844
|
172
|
al@844
|
173 # "--nodeps" option prevents to install dependencies
|
al@844
|
174 if [ "$answer" -eq 0 -a -z "$nodeps" ]; then
|
al@844
|
175 debug " let's install missing packages"
|
al@844
|
176 for pkg in $missing_packages; do
|
al@844
|
177 debug " pkg='$pkg'"
|
al@945
|
178 [ -d "$INSTALLED/$pkg" ] && continue
|
al@945
|
179 # Package not installed
|
al@844
|
180
|
al@945
|
181 found='0'; namever=''; pkgfile=''
|
al@945
|
182 # Prefer local packages
|
al@945
|
183 if [ -n "$local" ]; then
|
al@945
|
184 [ -z "$quiet" ] && _ 'Checking if package "%s" exists in local list...' "$pkg"
|
al@946
|
185 [ -n "$cookmode" ] && dir='/home/slitaz/packages'
|
al@946
|
186 pi="$dir/packages.info"
|
al@968
|
187 [ -e "$pi" ] || pi="$dir/packages-$SLITAZ_ARCH.info"
|
al@945
|
188 # Find local package
|
al@946
|
189 if [ -f "$pi" ]; then
|
al@945
|
190 # Packages database exists (should be everfresh!)
|
al@963
|
191
|
al@963
|
192 # Find local package
|
al@945
|
193 namever=$(awk -F$'\t' -vpkg="$pkg" '{
|
al@963
|
194 if ($1 == pkg) { printf("%s-%s", $1, $2); exit; }
|
al@946
|
195 }' "$pi") # <namever> = <package_name>-<package_version>
|
al@963
|
196
|
al@963
|
197 # Find local provided package
|
al@963
|
198 [ -n "$namever" ] ||
|
al@963
|
199 namever=$(awk -F$'\t' -vpkg="$pkg" '{
|
al@963
|
200 if (index(" " $10 " ", " " pkg " ")) { printf("%s-%s", $1, $2); exit; }
|
al@963
|
201 }' "$pi") # <namever> = <package_name>-<package_version>
|
al@963
|
202
|
al@945
|
203 # Package file may be in form <namever>.tazpkg or <namever>-<arch>.tazpkg, so find one
|
al@945
|
204 [ -n "$namever" ] && pkgfile=$(find "$dir" -name "$namever*.tazpkg")
|
al@945
|
205 [ -n "$pkgfile" ] && found='1'
|
al@945
|
206 else
|
al@945
|
207 # Packages DB missing, proceed to sniff packages
|
al@890
|
208 tempd="$(mktemp -d)"; cd "$tempd"
|
al@890
|
209 for pkgfile in $dir/$pkg-*.tazpkg; do
|
al@927
|
210 [ -e "$pkgfile" ] || continue
|
al@890
|
211 # Extract receipt from each matched package
|
al@890
|
212 cpio -F "$pkgfile" -i receipt >/dev/null 2>&1
|
al@950
|
213 name=$(. ./receipt; echo $PACKAGE)
|
al@945
|
214 [ "$name" == "$pkg" ] && found='1' && break
|
al@945
|
215 # Install the first matched package: normally there is only one package
|
al@945
|
216 # with the $PACKAGE matched in the receipt
|
al@890
|
217 rm receipt
|
al@890
|
218 done
|
al@890
|
219 rm -r "$tempd"
|
al@844
|
220 fi
|
al@945
|
221 fi
|
al@945
|
222 debug " found='$found'"
|
al@844
|
223
|
al@945
|
224 if [ "$found" -eq 1 ]
|
al@945
|
225 then tazpkg install "$pkgfile"
|
al@945
|
226 else tazpkg get-install "$pkg"
|
al@844
|
227 fi
|
al@844
|
228 done
|
al@844
|
229 else
|
al@844
|
230 # Answered 'No' to install dependencies, or '--nodeps' option given
|
al@844
|
231 newline
|
al@844
|
232 _ 'Leaving dependencies for package "%s" unresolved.' "$PACKAGE"
|
al@845
|
233 _ 'The package will be installed but will probably not work.'
|
al@844
|
234 newline
|
al@844
|
235 fi
|
al@844
|
236 }
|
al@844
|
237
|
al@844
|
238
|
al@844
|
239 # Extract a package with cpio and gzip/lzma.
|
al@844
|
240
|
al@844
|
241 extract_package() {
|
al@844
|
242 # input: $1 - path to package to be extracted; package should be in the current dir
|
al@844
|
243 # ROOT INDEPENDENT
|
al@880
|
244 action 'Extracting package...'
|
al@844
|
245
|
al@844
|
246 # Extract "outer layer": cpio; remove the original package file
|
al@844
|
247 cpio -idm --quiet < "$1" && rm -f "$1"
|
al@844
|
248
|
al@844
|
249 # "Inner layer" may vary
|
al@844
|
250 if [ -f fs.cpio.lzma ]; then
|
al@844
|
251 # "Plain" cpio.lzma
|
al@844
|
252 unlzma < fs.cpio.lzma | cpio -idm --quiet && rm fs.cpio.lzma
|
al@844
|
253 elif [ -f fs.cpio.gz ]; then
|
al@844
|
254 # "Fast" cpio.gz (used to pack-then-install process in most of get-packages)
|
al@844
|
255 zcat fs.cpio.gz | cpio -idm --quiet && rm fs.cpio.gz
|
al@844
|
256 fi
|
al@844
|
257
|
al@880
|
258 status
|
al@844
|
259 }
|
al@844
|
260
|
al@844
|
261
|
al@844
|
262 # Print short package description
|
al@844
|
263
|
al@844
|
264 print_short_description() {
|
al@844
|
265 # TODO: undigest repo support? priority...
|
al@844
|
266 # ROOT READY
|
al@844
|
267 local short_desc=''
|
al@844
|
268
|
al@844
|
269 # Try to find localized short description
|
al@844
|
270 for LC in $LANG ${LANG%_*}; do
|
al@844
|
271 [ -e "$PKGS_DB/packages-desc.$LC" ] &&
|
al@844
|
272 short_desc=$(awk -F$'\t' -vp="$1" '$1==p{print $2; exit}' "$PKGS_DB/packages-desc.$LC")
|
al@844
|
273 done
|
al@844
|
274
|
al@844
|
275 # Try to find short description for mirrored package
|
al@968
|
276 if [ -z "$short_desc" ]; then
|
al@968
|
277 if [ -e "$PKGS_DB/packages.info" ]; then
|
al@968
|
278 pi="$PKGS_DB/packages.info"
|
al@968
|
279 else
|
al@968
|
280 "$PKGS_DB/packages-$SLITAZ_ARCH.info"
|
al@968
|
281 fi
|
al@968
|
282 short_desc=$(awk -F$'\t' -vp="$1" '$1==p{print $4; exit}' "$pi")
|
al@968
|
283 fi
|
al@844
|
284
|
al@844
|
285 [ -z "$short_desc" ] && short_desc="$SHORT_DESC"
|
al@844
|
286
|
al@844
|
287 longline "$short_desc"
|
al@844
|
288 }
|
al@844
|
289
|
al@844
|
290
|
al@844
|
291 grepesc() {
|
al@844
|
292 sed 's/\[/\\[/g'
|
al@844
|
293 }
|
al@844
|
294
|
al@844
|
295
|
al@844
|
296
|
al@844
|
297
|
al@844
|
298 #*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*
|
al@844
|
299
|
al@844
|
300 # Block of receipt function callers
|
al@844
|
301 # Why? "Bad" receipt sourcing can redefine some vital TazPkg variables.
|
paul@943
|
302 # Few receipts functions should be patched now.
|
al@844
|
303
|
al@844
|
304 # Input: $1 = path to the receipt to be processed
|
al@844
|
305
|
al@844
|
306 # Pre-install commands
|
al@844
|
307 call_pre_install() {
|
al@844
|
308 local tmp
|
al@844
|
309 if grep -q '^pre_install()' "$1"; then
|
al@880
|
310 action 'Execute pre-install commands...'
|
al@844
|
311 tmp="$(mktemp)"
|
al@844
|
312 cp "$1" "$tmp"
|
al@844
|
313 sed -i 's|$1/*$INSTALLED|$INSTALLED|g' "$tmp"
|
al@844
|
314 ( . "$tmp"; pre_install "$root" )
|
al@880
|
315 status
|
al@844
|
316 rm "$tmp"
|
al@844
|
317 fi
|
al@844
|
318
|
al@844
|
319 }
|
al@846
|
320 # Post-install commands
|
al@844
|
321 call_post_install() {
|
al@844
|
322 local tmp
|
al@844
|
323 if grep -q '^post_install()' "$1"; then
|
al@880
|
324 action 'Execute post-install commands...'
|
al@844
|
325 tmp="$(mktemp)"
|
al@844
|
326 cp "$1" "$tmp"
|
al@844
|
327 sed -i 's|$1/*$INSTALLED|$INSTALLED|g' "$tmp"
|
al@844
|
328 ( . "$tmp"; post_install "$root" )
|
al@880
|
329 status
|
al@844
|
330 rm "$tmp"
|
al@844
|
331 fi
|
al@844
|
332 }
|
al@844
|
333
|
al@844
|
334
|
al@844
|
335 #*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*
|
al@844
|
336
|
al@844
|
337
|
al@844
|
338 # This function installs a package in the rootfs.
|
al@844
|
339
|
al@844
|
340 install_package() {
|
al@844
|
341 # input: $1 = path to package to be installed
|
al@844
|
342 # dep: install_all_deps, print_short_description, extract_package, grepesc.
|
al@844
|
343
|
al@844
|
344 debug "\ninstall_package('$1')"
|
al@844
|
345 local dir
|
al@844
|
346
|
al@844
|
347 PACKAGE_FILE="$1"
|
al@844
|
348 TMP_DIR="$(mktemp -d)"
|
al@844
|
349
|
al@844
|
350 # Get receipt's variables and functions
|
al@957
|
351 { cd "$TMP_DIR"; cpio --quiet -i receipt < "$PACKAGE_FILE" >/dev/null 2>&1; }
|
al@844
|
352 # Why next code? "Bad" receipt sourcing can redefine some vital TazPkg variables.
|
al@844
|
353 (
|
al@844
|
354 . "$TMP_DIR/receipt"
|
al@844
|
355 cat > "$TMP_DIR/receipt.var" <<EOT
|
al@844
|
356 PACKAGE="$PACKAGE"
|
al@844
|
357 VERSION="$VERSION"
|
al@844
|
358 EXTRAVERSION="$EXTRAVERSION"
|
al@844
|
359 CATEGORY="$CATEGORY"
|
al@945
|
360 SHORT_DESC="${SHORT_DESC//\"/\"}"
|
al@844
|
361 WEB_SITE="$WEB_SITE"
|
al@844
|
362 TAGS="$TAGS"
|
al@844
|
363 DEPENDS="$DEPENDS"
|
al@844
|
364 CONFIG_FILES="$CONFIG_FILES"
|
al@844
|
365 PACKED_SIZE="$PACKED_SIZE"
|
al@844
|
366 UNPACKED_SIZE="$UNPACKED_SIZE"
|
al@844
|
367 EOT
|
al@844
|
368 rm "$TMP_DIR/receipt"
|
al@844
|
369 )
|
al@844
|
370 . "$TMP_DIR/receipt.var"
|
al@844
|
371
|
al@844
|
372
|
al@844
|
373 # Make sure folder exists on new installs or upgrades
|
al@844
|
374 mkdir -p "$INSTALLED/$PACKAGE"
|
al@844
|
375
|
al@844
|
376 # Keep "modifiers" and "files.list" on upgrade
|
al@844
|
377 find "$INSTALLED/$PACKAGE" -type f \( ! -name modifiers ! -name files.list \) -delete
|
al@844
|
378
|
al@844
|
379 # Update "installed.md5"
|
al@844
|
380 # TODO: discontinue using 'installed.md5'
|
al@844
|
381 touch "$PKGS_DB/installed.$SUM"
|
al@844
|
382 sed -i "/ $(basename "$PACKAGE_FILE")$/d" "$PKGS_DB/installed.$SUM" 2>/dev/null
|
al@844
|
383 cd "$(dirname "$PACKAGE_FILE")"
|
al@844
|
384 $CHECKSUM "$(basename "$PACKAGE_FILE")" >> "$PKGS_DB/installed.$SUM"
|
al@844
|
385
|
al@844
|
386 # Resolve package dependencies before package installation
|
al@844
|
387 install_all_deps "$PACKAGE_FILE"
|
al@844
|
388
|
al@844
|
389
|
al@844
|
390 # TODO: why this list-processed in the $PKGS_DB?
|
al@844
|
391 #[ -n "$INSTALL_LIST" ] && echo "$PACKAGE_FILE" >> "$PKGS_DB/$INSTALL_LIST-processed"
|
al@844
|
392
|
paul@943
|
393 # Special mode for using in cookutils: clearly show whether freshly used package or cached one
|
al@933
|
394 if [ -n "$cookmode" ]; then
|
al@933
|
395 f=${PACKAGE_FILE%/*}; f=${f%/*}; f=${f##*/}
|
al@933
|
396 if [ "$f" == "$(cat /etc/slitaz-release)" ]; then
|
al@933
|
397 _ 'Installing (web/cache): %s' "$(basename $PACKAGE_FILE .tazpkg)"
|
al@933
|
398 else
|
al@933
|
399 _ 'Installing (pkg/local): %s' "$(basename $PACKAGE_FILE .tazpkg)"
|
al@933
|
400 fi
|
al@933
|
401 fi
|
al@933
|
402
|
al@844
|
403 if [ -n "$sequence" ]; then
|
al@880
|
404 title 'Installation of package "%s" (%s)' "$PACKAGE" "$sequence"
|
al@844
|
405 else
|
al@880
|
406 title 'Installation of package "%s"' "$PACKAGE"
|
al@844
|
407 fi
|
al@844
|
408
|
al@876
|
409 if [ -z "$quiet" ]; then
|
al@876
|
410 print_short_description "$PACKAGE"
|
al@876
|
411 separator '-'
|
al@876
|
412 fi
|
al@844
|
413
|
al@880
|
414 action 'Copying package...'
|
al@844
|
415 cp "$PACKAGE_FILE" "$TMP_DIR"
|
al@880
|
416 status
|
al@844
|
417
|
al@844
|
418 cd "$TMP_DIR"
|
al@844
|
419 extract_package "$(basename "$PACKAGE_FILE")"
|
al@844
|
420
|
al@844
|
421 # Include temporary receipt to get the right variables
|
al@844
|
422 . "$TMP_DIR/receipt.var"
|
al@844
|
423
|
al@844
|
424 cd "$INSTALLED"
|
al@844
|
425
|
al@844
|
426
|
al@844
|
427 # Get files to remove if upgrading
|
al@844
|
428 # IFS here modified temporarily for processing filenames with spaces
|
al@844
|
429 IFS=$'\n'
|
al@844
|
430 if [ -f "$PACKAGE/files.list" ]; then
|
al@844
|
431 while read file; do
|
al@844
|
432 grep -q "^$(echo "$file" | grepesc)$" "$TMP_DIR/files.list" && continue
|
al@844
|
433 for i in $(cat "$PACKAGE/modifiers" 2>/dev/null;
|
al@844
|
434 fgrep -sl "$PACKAGE" */modifiers | cut -d/ -f1); do
|
al@844
|
435 grep -qs "^$(echo "$file" | grepesc)$" "$i/files.list" && continue 2
|
al@844
|
436 done
|
al@844
|
437 echo "$file"
|
al@844
|
438 done < "$PACKAGE/files.list" > "$TMP_DIR/files2remove.list"
|
al@844
|
439 fi
|
al@844
|
440 unset IFS
|
al@844
|
441
|
al@844
|
442
|
al@844
|
443 # Remember modified packages
|
al@880
|
444 action 'Remember modified packages...'
|
al@844
|
445 {
|
al@844
|
446 check=false
|
al@844
|
447 # TODO: why '[' the special?
|
al@844
|
448 # FIXME: we have files with spaces in our packages!
|
al@844
|
449 for i in $(fgrep -v [ $TMP_DIR/files.list); do
|
al@844
|
450 [ -e "$root$i" ] || continue
|
al@844
|
451 [ -d "$root$i" ] && continue
|
al@844
|
452 echo "- $i"
|
al@844
|
453 check=true
|
al@844
|
454 done ;
|
al@844
|
455 $check && \
|
al@844
|
456 for i in *; do
|
al@844
|
457 [ "$i" == "$PACKAGE" ] && continue
|
al@844
|
458 [ -s "$i/files.list" ] || continue
|
al@844
|
459 awk "{ printf \"$i %s\\n\",\$1 }" < "$i/files.list"
|
al@844
|
460 done;
|
al@844
|
461 } | awk '
|
al@844
|
462 {
|
al@844
|
463 if ($1 == "-" || file[$2] != "") {
|
al@844
|
464 file[$2] = file[$2] " " $1
|
al@844
|
465 if ($1 != "-") {
|
al@844
|
466 if (pkg[$1] == "") all = all " " $1
|
al@844
|
467 pkg[$1] = pkg[$1] " " $2
|
al@844
|
468 }
|
al@844
|
469 }
|
al@844
|
470 }
|
al@844
|
471 END {
|
al@844
|
472 for (i = split(all, p, " "); i > 0; i--)
|
al@844
|
473 for (j = split(pkg[p[i]], f, " "); j > 0; j--)
|
al@844
|
474 printf "%s %s\n",p[i],f[j];
|
al@844
|
475 }
|
al@844
|
476 ' | while read dir file; do
|
al@844
|
477 if grep -qs "^$dir$" "$PACKAGE/modifiers"; then
|
al@844
|
478 # Do not overload an overloaded file !
|
al@844
|
479 rm "$TMP_DIR/$file" 2>/dev/null
|
al@844
|
480 continue
|
al@844
|
481 fi
|
al@844
|
482 grep -qs "^$PACKAGE$" "$dir/modifiers" && continue
|
al@844
|
483 if [ -s "$dir/volatile.cpio.gz" ]; then
|
al@844
|
484 # We can modify backed up files without notice
|
al@844
|
485 zcat "$dir/volatile.cpio.gz" | cpio -t --quiet | \
|
al@844
|
486 grep -q "^${file#/}$" && continue
|
al@844
|
487 fi
|
al@844
|
488 echo "$PACKAGE" >> "$dir/modifiers"
|
al@844
|
489 done
|
al@880
|
490 status
|
al@844
|
491
|
al@844
|
492
|
al@844
|
493 cd "$TMP_DIR"
|
al@844
|
494 # Copy receipt, etc.
|
al@844
|
495 for file in receipt files.list description.txt $CHECKSUM; do
|
al@844
|
496 [ -f "$file" ] && cp "$file" "$INSTALLED/$PACKAGE"
|
al@844
|
497 done
|
al@844
|
498
|
al@844
|
499
|
al@844
|
500 # Pre-install commands
|
al@844
|
501 call_pre_install "$INSTALLED/$PACKAGE/receipt"
|
al@844
|
502
|
al@844
|
503
|
al@844
|
504 if [ -n "$CONFIG_FILES" ]; then
|
al@844
|
505 # Save "official" configuration files
|
al@880
|
506 action 'Saving configuration files...'
|
al@844
|
507 debug "\n"
|
al@844
|
508
|
al@844
|
509 cd fs
|
al@844
|
510 local config_file
|
al@844
|
511 for config_file in $CONFIG_FILES; do
|
al@844
|
512 debug " config_file: '$config_file'"
|
al@844
|
513 find ${config_file#/} -type f 2>/dev/null
|
al@844
|
514 done | cpio -o -H newc --quiet | gzip -9 > "$INSTALLED/$PACKAGE/volatile.cpio.gz"
|
al@844
|
515 cd ..
|
al@844
|
516
|
al@844
|
517 if [ -z "$newconf" ]; then
|
al@844
|
518 debug " no '--newconf': clean official config files"
|
al@844
|
519 # Keep user configuration files: remove "official" from fs tree
|
al@844
|
520 for config_file in $CONFIG_FILES; do
|
al@888
|
521 for config_file_official in $(find "fs$config_file" ! -type d 2>/dev/null | sed 's|^fs||'); do
|
al@855
|
522 if [ -e "$root$config_file_official" ]; then
|
al@855
|
523 debug " official '$config_file_official' will be skipped"
|
al@855
|
524 rm "fs$config_file_official"
|
al@855
|
525 else
|
al@855
|
526 debug " official '$config_file_official' will be written"
|
al@855
|
527 fi
|
al@855
|
528 done
|
al@844
|
529 done
|
al@844
|
530 fi
|
al@844
|
531 # always '[ Done ]' status, unless '--newconf' is passed or not
|
al@880
|
532 :; status
|
al@844
|
533 fi
|
al@844
|
534
|
al@844
|
535
|
al@846
|
536 if [ -n "$(ls fs/* 2>/dev/null)" ]; then
|
al@880
|
537 action 'Installing package...'
|
al@845
|
538
|
al@845
|
539 debug '\n resolving destination links in source'
|
al@845
|
540 IFS=$'\n'
|
al@845
|
541 for dir in $(find fs -type d | sed 's|^fs||;/^$/d'); do
|
al@846
|
542 if ldir=$(readlink -n $root$dir); then
|
al@845
|
543 debug " * mv 'fs$dir'\n -> 'fs${dir%/*}/$ldir'"
|
al@845
|
544 mkdir -p "fs${dir%/*}/${ldir%/*}"
|
al@845
|
545 mv "fs$dir" "fs${dir%/*}/$ldir"
|
al@845
|
546 fi
|
al@845
|
547 done
|
al@845
|
548 unset IFS
|
al@845
|
549
|
al@845
|
550 debug ' copying folders and files to destination'
|
al@845
|
551 cp -af fs/* "$root/"
|
al@880
|
552 status
|
al@845
|
553 fi
|
al@844
|
554
|
al@844
|
555
|
al@844
|
556 if [ -s files2remove.list ]; then
|
al@880
|
557 action 'Removing old files...'
|
al@844
|
558 while read file; do
|
al@844
|
559 dir="$root$file"
|
al@844
|
560 # Remove specified file
|
al@844
|
561 rm -f "$dir"
|
al@844
|
562 # Recursive remove non-empty up-dirs
|
al@844
|
563 while [ "$dir" != "$root/" ]; do
|
al@844
|
564 dir=$(dirname "$dir")
|
al@844
|
565 rmdir "$dir" 2>/dev/null || break
|
al@844
|
566 done
|
al@844
|
567 done < files2remove.list
|
al@880
|
568 :; status
|
al@844
|
569 fi
|
al@844
|
570
|
al@844
|
571
|
al@844
|
572 # Remove the temporary random directory.
|
al@880
|
573 action "Removing all tmp files..."
|
al@844
|
574 cd ..; rm -rf "$TMP_DIR"
|
al@880
|
575 status
|
al@844
|
576
|
al@844
|
577
|
al@844
|
578 # Post install commands
|
al@844
|
579 call_post_install "$INSTALLED/$PACKAGE/receipt"
|
al@844
|
580
|
al@844
|
581
|
al@844
|
582
|
al@844
|
583
|
al@844
|
584 # Update system databases
|
al@844
|
585 # Updating DBs is important process, so not to hide such errors (localized):
|
al@844
|
586 # chroot: can't execute '/usr/bin/***': No such file or directory
|
al@844
|
587
|
al@929
|
588 local fl="$INSTALLED/$PACKAGE/files.list" upd=0 udesk umime uicon uschm ukrnl ukrnlfs
|
al@844
|
589
|
al@929
|
590 fgrep /usr/share/applications/ "$fl" | fgrep -q .desktop && udesk='yes'
|
al@929
|
591 fgrep -q /usr/share/mime "$fl" && umime='yes'
|
al@929
|
592 fgrep -q /usr/share/icon/hicolor "$fl" && uicon='yes'
|
al@929
|
593 fgrep /usr/share/glib-2.0/schemas "$fl" | fgrep -q .xml && uschm='yes'
|
al@929
|
594 fgrep /usr/lib/gdk-pixbuf "$fl" | fgrep -q .so && upixb='yes'
|
al@929
|
595 if fgrep -q /lib/modules "$fl"; then
|
al@929
|
596 ukrnl='yes'
|
al@929
|
597 if fgrep -q /kernel/fs/ "$fl"; then
|
al@929
|
598 ukrnlfs='yes'
|
al@929
|
599 fi
|
al@929
|
600 fi
|
al@844
|
601
|
al@844
|
602 if [ -n "$udesk$umime$uicon$uschm$upixb$ukrnl" ]; then
|
al@880
|
603 action 'Update system databases...'
|
al@844
|
604 upd=1
|
al@844
|
605 fi
|
al@844
|
606
|
al@844
|
607 # package 'desktop-file-utils'
|
al@862
|
608 [ -n "$udesk" ] && chroot "$root/" /usr/bin/update-desktop-database /usr/share/applications 2>/dev/null
|
al@844
|
609 # package 'shared-mime-info'
|
al@844
|
610 [ -n "$umime" ] && chroot "$root/" /usr/bin/update-mime-database /usr/share/mime
|
al@844
|
611 # packages 'gtk+', 'gtk+3'
|
al@844
|
612 [ -n "$uicon" ] && chroot "$root/" /usr/bin/gtk-update-icon-cache /usr/share/icons/hicolor
|
al@844
|
613 # package 'glib'
|
al@897
|
614 # hide messages like next because they are unresolved (we may to patch glib to hide them, almost the same)
|
al@897
|
615 # warning: Schema '*' has path '*'. Paths starting with '/apps/', '/desktop/' or '/system/' are deprecated.
|
al@897
|
616 [ -n "$uschm" ] && chroot "$root/" /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas 2>&1 | fgrep -v '/apps/'
|
al@844
|
617 # package 'gdk-pixbuf'
|
al@844
|
618 [ -n "$upixb" ] && chroot "$root/" /usr/bin/gdk-pixbuf-query-loaders --update-cache
|
al@929
|
619
|
al@929
|
620 if [ -n "$ukrnlfs" ]; then
|
al@929
|
621 for i in $(awk -F/ '{if($6=="fs" && $8~$7)print $7}' "$fl" | sort -u); do
|
al@929
|
622 touch "$root/etc/filesystems"
|
al@939
|
623 grep -q "^$i\$" "$root/etc/filesystems" || echo "$i" >> "$root/etc/filesystems"
|
al@929
|
624 done
|
al@929
|
625 fi
|
al@844
|
626 # packages 'busybox', 'kmod', 'depmod'
|
al@865
|
627 [ -n "$ukrnl" ] && grep '/lib/modules' "$fl" | cut -d'/' -f4 | uniq | xargs chroot "$root/" /sbin/depmod -a
|
al@844
|
628
|
al@880
|
629 [ "$upd" -eq 1 ] && status
|
al@844
|
630
|
al@844
|
631
|
al@844
|
632
|
al@844
|
633
|
al@949
|
634 # Update installed.info ----------------------------------------------------
|
al@844
|
635 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
|
al@949
|
636
|
al@844
|
637 # Remove newlines from some receipts
|
al@844
|
638 DEPENDS=$(echo $DEPENDS)
|
mojo@954
|
639 PKG_SUM="$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$PKGS_DB/installed.$SUM" | cut -d' ' -f1)"
|
mojo@954
|
640
|
al@949
|
641 # Calculate "release checksum": md5sum of file containing md5sums of:
|
al@949
|
642 # a) all files, b) receipt, and c) description.txt.
|
al@949
|
643 rsumf=$(mktemp)
|
al@949
|
644 cp $INSTALLED/$PACKAGE/md5sum $rsumf
|
al@949
|
645 md5sum $INSTALLED/$PACKAGE/receipt | sed 's| [^ ]*/| |' >> $rsumf
|
al@949
|
646 [ -e "$INSTALLED/$PACKAGE/description.txt" ] &&
|
al@949
|
647 md5sum $INSTALLED/$PACKAGE/description.txt | sed 's| [^ ]*/| |' >> $rsumf
|
al@949
|
648 RSUM=$(md5sum $rsumf | awk '{print $1}')
|
al@949
|
649 rm $rsumf
|
al@949
|
650
|
al@844
|
651 ii="$PKGS_DB/installed.info"
|
al@949
|
652
|
al@844
|
653 # Remove old entry
|
al@844
|
654 sed -i "/^$PACKAGE /d" "$ii"
|
al@949
|
655
|
al@844
|
656 cat >> "$ii" <<EOT
|
mojo@954
|
657 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $PKG_SUM
|
al@844
|
658 EOT
|
al@949
|
659
|
al@844
|
660 TEMP_FILE="$(mktemp)"
|
al@844
|
661 sort "$ii" > "$TEMP_FILE"; mv -f "$TEMP_FILE" "$ii"; chmod a+r "$ii"; unset ii
|
al@949
|
662 # --------------------------------------------------------------------------
|
al@844
|
663
|
al@844
|
664 cd "$CUR_DIR"
|
al@880
|
665 footer "$(_ 'Package "%s" (%s) is installed.' "$PACKAGE" "$VERSION$EXTRAVERSION")"
|
al@844
|
666
|
al@844
|
667 # Log this activity
|
al@844
|
668 log_pkg Installed
|
al@844
|
669
|
al@844
|
670 # Remove package from upgrade list
|
al@844
|
671 [ -s "$UP_LIST" ] && sed -i "/^$PACKAGE\$/d" "$UP_LIST"
|
al@844
|
672 }
|
al@844
|
673
|
al@844
|
674
|
al@844
|
675
|
al@844
|
676
|
al@844
|
677 #*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*
|
al@844
|
678
|
al@844
|
679
|
al@844
|
680 PACKAGE=$(
|
al@844
|
681 tmp_dir=$(mktemp -d); cd "$tmp_dir"
|
al@957
|
682 cpio --quiet -i receipt < "$1" >/dev/null 2>&1
|
al@950
|
683 . ./receipt; echo $PACKAGE
|
al@844
|
684 rm -rf "$tmp_dir"
|
al@957
|
685 )
|
al@844
|
686
|
al@866
|
687 if grep -qs "^$PACKAGE$" "$BLOCKED"; then
|
al@866
|
688 _ 'Package "%s" blocked.' "$PACKAGE"
|
al@866
|
689 exit 1
|
al@866
|
690 fi
|
al@866
|
691
|
al@844
|
692 if [ -z "$forced" ]; then
|
al@844
|
693 # Check if a package is already installed
|
al@844
|
694 debug "\ncheck for installed package '$PACKAGE'"
|
al@844
|
695
|
al@844
|
696 awk -F$'\t' -vpv="$PACKAGE" '$1==pv { exit 1 }' "$PKGS_DB/installed.info"
|
al@844
|
697
|
al@844
|
698 if [ "$?" -eq 1 ]; then
|
al@881
|
699 if [ -z "$quiet" ]; then
|
al@881
|
700 newline
|
al@881
|
701 _ '"%s" package is already installed.' "$(colorize 34 "$PACKAGE")"
|
al@881
|
702 longline "$(_ 'You can use the --forced option to force installation.')"
|
al@881
|
703 newline
|
al@881
|
704 fi
|
al@844
|
705 exit 1
|
al@844
|
706 fi
|
al@844
|
707 fi
|
al@844
|
708
|
al@844
|
709 install_package "$(realpath "$1")"
|