tazpkg view modules/mkdb @ rev 840

Add a bunch of modules with new-style support of 'root' (not all commands are modules yet); strip and compress resources.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Aug 28 16:10:34 2015 +0300 (2015-08-28)
parents 2607b466301c
children d6cbd0c5f273
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 # Preparations
65 # Get config values (CHECKSUM)
66 . /etc/slitaz/slitaz.conf
67 # Connect functions library
68 . /lib/libtaz.sh
71 # Report error and finish work
72 die() { longline "$(_ "$@")" >&2; exit 1; }
75 # Exit if input folder not specified
76 [ -z "$1" ] && die 'Input folder not specified'
78 # Exit if input folder not exists
79 folder=$(realpath "$1") || exit 1
81 # Exit if folder is not writable
82 [ ! -w "$folder" ] && die 'You are not allowed to write to the folder "%s"' "$folder"
84 # Exit if input folder does not contain packages
85 [ -z "$(find "$folder" -maxdepth 1 -name '*.tazpkg')" ] && \
86 die 'Folder "%s" does not contain packages' "$folder"
89 # DB file names
90 DBi="$folder/packages.info"
91 DBe="$folder/packages.equiv"
92 DBd="$folder/descriptions.txt"
93 DBf="$folder/files.list"
95 # Pre-remove DB if --forced and DB exists
96 if [ -n "$forced" ]; then
97 [ -e "$DBi" ] && rm "$DBi"
98 [ -e "$DBe" ] && rm "$DBe"
99 [ -e "$DBd" ] && rm "$DBd"
100 [ -e "$DBf.lzma" ] && rm "$DBf.lzma"
101 fi
103 if [ -s "$DBi" ]; then
104 _ 'Packages DB already exists.' >&2
105 exit 1
106 fi
108 # Random temporary folder
109 tempd="$(mktemp -d)"
111 # Make temporary list of packages checksum (usually md5sum)
112 _n 'Calculate %s...' "$CHECKSUM"
113 cd "$folder"; $CHECKSUM *.tazpkg > "$tempd/$SUM"
114 status
116 cd "$tempd"
118 # Loop for every package
119 while read pkgsum pkgfile; do
120 # Current processed package
121 echo -n "$pkgfile"
123 # Extract receipt from package
124 cpio -F "$folder/$pkgfile" -i receipt >/dev/null 2>&1
126 # Unset variables that may absent in the receipt
127 unset EXTRAVERSION TAGS DEPENDS PROVIDE
128 # Get values
129 . receipt; rm receipt
132 # Make packages.info
133 echo -en "$PACKAGE\t$VERSION$EXTRAVERSION\t$CATEGORY\t" >> "$DBi"
134 echo -en "$SHORT_DESC\t$WEB_SITE\t$TAGS\t" >> "$DBi"
135 echo -en "$PACKED_SIZE $UNPACKED_SIZE\t" | sed 's|\.0||g' >> "$DBi"
136 echo -n $DEPENDS$'\t' >> "$DBi"
137 echo $pkgsum >> "$DBi"
140 # Make packages.equiv
141 for i in $PROVIDE; do
142 # Example from busybox-pam package:
143 # PACKAGE="busybox-pam", PROVIDE="busybox:pam"
144 case $i in
145 # DEST="pam:"
146 *:*) DEST="${i#*:}:";;
147 *) DEST='';;
148 esac
149 # PKG="busybox"
150 PKG="${i%:*}"
151 if grep -qs ^$PKG= "$DBe"; then
152 # Append existing record
153 sed -i "s|^$PKG=|\0 $DEST$PACKAGE|" "$DBe"
154 else
155 # Add new record
156 echo "$PKG=$DEST$PACKAGE" >> "$DBe"
157 fi
158 done
161 # Make descriptions.txt
162 if cpio -F "$folder/$pkgfile" -t 2>/dev/null | fgrep -q 'description.txt'; then
163 # Extract description.txt from package
164 cpio -F "$folder/$pkgfile" -i description.txt >/dev/null 2>&1
165 # Append descriptions DB
166 echo "$PACKAGE" >> "$DBd"
167 cat description.txt | sed 's|^$| |' >> "$DBd"
168 echo >> "$DBd"
169 rm description.txt
170 fi
173 # Make files.list
174 if cpio -F "$folder/$pkgfile" -t 2>/dev/null | fgrep -q 'files.list'; then
175 # Extract files.list from package
176 cpio -F "$folder/$pkgfile" -i files.list >/dev/null 2>&1
177 # Append files list DB
178 sed "s|.*|$PACKAGE: \0|" files.list >> "$DBf"
179 rm files.list
180 fi
182 # End line with the status
183 status
184 done < "$tempd/$SUM"
187 # Sort DB alphabetically
188 sort -o "$tempd/pi" "$DBi"; mv -f "$tempd/pi" "$DBi"
190 # Create empty files if they not exists
191 touch "$DBi" "$DBe" "$DBd" "$DBf"
193 # Compress files.list using lzma
194 sort -k2 -o "$DBf.sorted" "$DBf"
195 lzma e "$DBf.sorted" "$DBf.lzma"
196 rm "$DBf" "$DBf.sorted"
198 # Make DB readable for all
199 chmod a+r "$DBi" "$DBe" "$DBd" "$DBf.lzma"
202 # Make files for DB recharge
203 # --------------------------
205 cd "$folder"
207 # Make IDs: md5 and timestamp
208 ( md5sum "$tempd/$SUM" | cut -d' ' -f1 | tr '\n' ' '; date -ur "$DBi" +%s ) > IDs
211 # Make files-list.md5: decide whether to download files.list.lzma or not
212 md5sum "$DBf.lzma" | cut -d' ' -f1 | tr -d $'\n' > files-list.md5
214 # Make bundle to fast recharge
215 [ -f 'bundle.tar.lzma' ] && rm 'bundle.tar.lzma'
216 busybox tar -chaf bundle.tar.lzma \
217 files-list.md5 packages.info descriptions.txt packages.equiv
219 # Clean up
220 rm files-list.md5
221 rm -r "$tempd"