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