tazpkg view modules/mkdb @ rev 846

Remove "busybox" "prefixes" (thanks llev)
We used "busybox wget", etc. to be sure we called Busybox's "wget", not any other "wget". Workaround already done in "getenv" module.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Oct 09 13:14:01 2015 +0300 (2015-10-09)
parents d6cbd0c5f273
children 4802158453e1
line source
1 #!/bin/sh
2 # TazPkg - Tiny autonomous zone packages manager, hg.slitaz.org/tazpkg
3 # mkdb - TazPkg module
4 # Make TazPkg database for folder with *.tazpkg packages
7 # Input: $1 - path to folder contains *.tazpkg packages
8 # Output files in the $1 folder:
9 # packages.info
10 # packages.equiv
11 # descriptions.txt
12 # files.list.lzma
13 # IDs
14 # Do nothing if database already exists; force rebuild it with --forced option.
16 # DB format:
17 # ==========
19 # packages.info
20 # -------------
21 # Record is line; fields are tab-separated. Fields description:
22 # 1: package name
23 # 2: version with extra-version
24 # 3: category
25 # 4: short description
26 # 5: upstream web site
27 # 6: tags (space-separated)
28 # 7: packed and unpacked sizes (space-separated) in human readable format
29 # 8: depends
30 # 9: checksum
32 # packages.equiv
33 # --------------
34 # This DB file used before package installation
35 # Record is line. Separator is "="
36 # Field 1 is package name to install (pkg1)
37 # Field 2 is space-separated list of items in the special format:
38 # a) pkg2:pkg3
39 # If pkg2 is installed, then install pkg3 instead of pkg1. Example:
40 # busybox=pam:busybox-pam
41 # If 'pam' is installed, then install 'busybox-pam' instead of 'busybox'
42 # b) pkg2
43 # If pkg2 already installed, then pkg1 will not be installed. Example:
44 # mysql=mariadb
45 # If 'mariadb' already installed, then 'mysql' will not be installed
46 # Complex rule example:
47 # ssh=pam:openssh-pam openssh pam:dropbear-pam dropbear
49 # descriptions.txt
50 # ----------------
51 # Field is line; record separator is empty line.
52 # First field is package name, rest - description itself.
53 # Empty lines in the description appended with space (" ") to avoid mess
54 # with end of record.
56 # files.list.lzma
57 # ---------------
58 # It is "files.list" compressed using lzma due to it's big size.
59 # Format of the files.list: record is line; field separator is ": ".
60 # First field is package name, second field is file path.
61 # There are DB records for all files installed with the package.
64 # Connect function libraries
65 . /lib/libtaz.sh
67 # Get TazPkg working environment
68 . @@MODULES@@/getenv
73 # Exit if input folder not specified
74 [ -z "$1" ] && die 'Input folder not specified'
76 # Exit if input folder not exists
77 folder=$(realpath "$root$1") || exit 1
79 # Exit if folder is not writable
80 [ ! -w "$folder" ] && die 'You are not allowed to write to the folder "%s"' "$folder"
82 # Exit if input folder does not contain packages
83 [ -z "$(find "$folder" -maxdepth 1 -name '*.tazpkg')" ] && \
84 die 'Folder "%s" does not contain packages' "$folder"
87 # DB file names
88 DBi="$folder/packages.info"
89 DBe="$folder/packages.equiv"
90 DBd="$folder/descriptions.txt"
91 DBf="$folder/files.list"
93 # Pre-remove DB if --forced and DB exists
94 if [ -n "$forced" ]; then
95 [ -e "$DBi" ] && rm "$DBi"
96 [ -e "$DBe" ] && rm "$DBe"
97 [ -e "$DBd" ] && rm "$DBd"
98 [ -e "$DBf.lzma" ] && rm "$DBf.lzma"
99 fi
101 if [ -s "$DBi" ]; then
102 _ 'Packages DB already exists.' >&2
103 exit 1
104 fi
106 # Random temporary folder
107 tempd="$(mktemp -d)"
109 # Make temporary list of packages checksum (usually md5sum)
110 _n 'Calculate %s...' "$CHECKSUM"
111 cd "$folder"; $CHECKSUM *.tazpkg > "$tempd/$SUM"
112 status
114 cd "$tempd"
116 # Loop for every package
117 while read pkgsum pkgfile; do
118 # Current processed package
119 echo -n "$pkgfile"
121 # Extract receipt from package
122 cpio -F "$folder/$pkgfile" -i receipt >/dev/null 2>&1
124 # Unset variables that may absent in the receipt
125 unset EXTRAVERSION TAGS DEPENDS PROVIDE
126 # Get values
127 . receipt; rm receipt
130 # Make packages.info
131 echo -en "$PACKAGE\t$VERSION$EXTRAVERSION\t$CATEGORY\t" >> "$DBi"
132 echo -en "$SHORT_DESC\t$WEB_SITE\t$TAGS\t" >> "$DBi"
133 echo -en "$PACKED_SIZE $UNPACKED_SIZE\t" | sed 's|\.0||g' >> "$DBi"
134 echo -n $DEPENDS$'\t' >> "$DBi"
135 echo $pkgsum >> "$DBi"
138 # Make packages.equiv
139 for i in $PROVIDE; do
140 # Example from busybox-pam package:
141 # PACKAGE="busybox-pam", PROVIDE="busybox:pam"
142 case $i in
143 # DEST="pam:"
144 *:*) DEST="${i#*:}:";;
145 *) DEST='';;
146 esac
147 # PKG="busybox"
148 PKG="${i%:*}"
149 if grep -qs ^$PKG= "$DBe"; then
150 # Append existing record
151 sed -i "s|^$PKG=|\0 $DEST$PACKAGE|" "$DBe"
152 else
153 # Add new record
154 echo "$PKG=$DEST$PACKAGE" >> "$DBe"
155 fi
156 done
159 # Make descriptions.txt
160 if cpio -F "$folder/$pkgfile" -t 2>/dev/null | fgrep -q 'description.txt'; then
161 # Extract description.txt from package
162 cpio -F "$folder/$pkgfile" -i description.txt >/dev/null 2>&1
163 # Append descriptions DB
164 echo "$PACKAGE" >> "$DBd"
165 cat description.txt | sed 's|^$| |' >> "$DBd"
166 echo >> "$DBd"
167 rm description.txt
168 fi
171 # Make files.list
172 if cpio -F "$folder/$pkgfile" -t 2>/dev/null | fgrep -q 'files.list'; then
173 # Extract files.list from package
174 cpio -F "$folder/$pkgfile" -i files.list >/dev/null 2>&1
175 # Append files list DB
176 sed "s|.*|$PACKAGE: \0|" files.list >> "$DBf"
177 rm files.list
178 fi
180 # End line with the status
181 status
182 done < "$tempd/$SUM"
185 # Sort DB alphabetically
186 sort -o "$tempd/pi" "$DBi"; mv -f "$tempd/pi" "$DBi"
188 # Create empty files if they not exists
189 touch "$DBi" "$DBe" "$DBd" "$DBf"
191 # Compress files.list using lzma
192 sort -k2 -o "$DBf.sorted" "$DBf"
193 lzma e "$DBf.sorted" "$DBf.lzma"
194 rm "$DBf" "$DBf.sorted"
196 # Make DB readable for all
197 chmod a+r "$DBi" "$DBe" "$DBd" "$DBf.lzma"
200 # Make files for DB recharge
201 # --------------------------
203 cd "$folder"
205 # Make IDs: md5 and timestamp
206 ( md5sum "$tempd/$SUM" | cut -d' ' -f1 | tr '\n' ' '; date -ur "$DBi" +%s ) > IDs
209 # Make files-list.md5: decide whether to download files.list.lzma or not
210 md5sum "$DBf.lzma" | cut -d' ' -f1 | tr -d $'\n' > files-list.md5
212 # Make bundle to fast recharge
213 [ -f 'bundle.tar.lzma' ] && rm 'bundle.tar.lzma'
214 tar -chaf bundle.tar.lzma \
215 files-list.md5 packages.info descriptions.txt packages.equiv
217 # Clean up
218 rm files-list.md5
219 rm -r "$tempd"