]> pd.if.org Git - zpackage/blob - zpm-preserve
documentation improvements
[zpackage] / zpm-preserve
1 #!/bin/sh
2
3 # preserve a packages libraries
4
5 verbose=0
6 all=0
7 script=0
8 check=0
9
10 while getopts avs arg; do
11         case $arg in
12                 a) all=1;;
13                 v) verbose=1;;
14         c) check=1;;
15         s) script=1;;
16         ?) printf 'usage: zpm-preserve [-av] <pkgname>\n'
17                 exit 1
18                 ;;
19         esac
20 done
21
22 pkgname="$1"
23
24 pacman -Qlq "$pkgname" | while read file; do
25         if [ ! -f "$file" ]; then continue; fi
26         base=$(basename "$file")
27         if [ $all -eq 0 ] && [ "$base" = "${base#lib}" ]; then continue; fi
28
29         if [ $check -eq 1 ]; then
30                 elftype -e "$file"
31                 rv=$?
32                 if [ $rv -ne 0 ]; then continue; fi
33                 for lib in $(zpm getlibs $file | grep preserve); do
34                         echo $pkgname $file $lib
35                 done
36                 continue
37         fi
38
39         soname=$(zpm soname $file)
40         if [ $? -eq 0 ] && [ -n "$soname" ]; then
41                 dir=$(dirname "$file")
42                 if [ "$script" -ne 0 ]; then
43                         printf 'mkdir -p "%s"\n' "$dir/preserve"
44                         printf 'ln -f "%s" "%s"\n' "$file" "$dir/preserve/"
45                 else
46                         mkdir -p "$dir/preserve"
47                         if [ "$verbose" -gt 0 ]; then
48                                 printf '# preserving %s\n' "$file"
49                         fi
50                         ln -f "$file" "$dir/preserve/"
51                 fi
52         fi
53 done