tazpkg annotate modules/mkdb @ rev 838

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