tazpkg annotate 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
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@844 64 # Connect function libraries
al@824 65 . /lib/libtaz.sh
al@824 66
al@844 67 # Get TazPkg working environment
al@844 68 . @@MODULES@@/getenv
al@824 69
al@844 70
al@824 71
al@824 72
al@824 73 # Exit if input folder not specified
al@824 74 [ -z "$1" ] && die 'Input folder not specified'
al@824 75
al@824 76 # Exit if input folder not exists
al@844 77 folder=$(realpath "$root$1") || exit 1
al@824 78
al@824 79 # Exit if folder is not writable
al@824 80 [ ! -w "$folder" ] && die 'You are not allowed to write to the folder "%s"' "$folder"
al@824 81
al@824 82 # Exit if input folder does not contain packages
al@824 83 [ -z "$(find "$folder" -maxdepth 1 -name '*.tazpkg')" ] && \
al@824 84 die 'Folder "%s" does not contain packages' "$folder"
al@824 85
al@824 86
al@824 87 # DB file names
al@824 88 DBi="$folder/packages.info"
al@824 89 DBe="$folder/packages.equiv"
al@824 90 DBd="$folder/descriptions.txt"
al@824 91 DBf="$folder/files.list"
al@824 92
al@824 93 # Pre-remove DB if --forced and DB exists
al@824 94 if [ -n "$forced" ]; then
al@824 95 [ -e "$DBi" ] && rm "$DBi"
al@824 96 [ -e "$DBe" ] && rm "$DBe"
al@824 97 [ -e "$DBd" ] && rm "$DBd"
al@824 98 [ -e "$DBf.lzma" ] && rm "$DBf.lzma"
al@824 99 fi
al@824 100
al@824 101 if [ -s "$DBi" ]; then
al@824 102 _ 'Packages DB already exists.' >&2
al@824 103 exit 1
al@824 104 fi
al@824 105
al@824 106 # Random temporary folder
al@824 107 tempd="$(mktemp -d)"
al@824 108
al@824 109 # Make temporary list of packages checksum (usually md5sum)
al@824 110 _n 'Calculate %s...' "$CHECKSUM"
al@824 111 cd "$folder"; $CHECKSUM *.tazpkg > "$tempd/$SUM"
al@824 112 status
al@824 113
al@824 114 cd "$tempd"
al@824 115
al@824 116 # Loop for every package
al@824 117 while read pkgsum pkgfile; do
al@824 118 # Current processed package
al@824 119 echo -n "$pkgfile"
al@824 120
al@824 121 # Extract receipt from package
al@824 122 cpio -F "$folder/$pkgfile" -i receipt >/dev/null 2>&1
al@824 123
al@824 124 # Unset variables that may absent in the receipt
al@824 125 unset EXTRAVERSION TAGS DEPENDS PROVIDE
al@824 126 # Get values
al@824 127 . receipt; rm receipt
al@824 128
al@824 129
al@824 130 # Make packages.info
al@824 131 echo -en "$PACKAGE\t$VERSION$EXTRAVERSION\t$CATEGORY\t" >> "$DBi"
al@824 132 echo -en "$SHORT_DESC\t$WEB_SITE\t$TAGS\t" >> "$DBi"
al@824 133 echo -en "$PACKED_SIZE $UNPACKED_SIZE\t" | sed 's|\.0||g' >> "$DBi"
al@824 134 echo -n $DEPENDS$'\t' >> "$DBi"
al@824 135 echo $pkgsum >> "$DBi"
al@824 136
al@824 137
al@824 138 # Make packages.equiv
al@824 139 for i in $PROVIDE; do
al@824 140 # Example from busybox-pam package:
al@824 141 # PACKAGE="busybox-pam", PROVIDE="busybox:pam"
al@824 142 case $i in
al@824 143 # DEST="pam:"
al@824 144 *:*) DEST="${i#*:}:";;
al@824 145 *) DEST='';;
al@824 146 esac
al@824 147 # PKG="busybox"
al@824 148 PKG="${i%:*}"
al@824 149 if grep -qs ^$PKG= "$DBe"; then
al@824 150 # Append existing record
al@824 151 sed -i "s|^$PKG=|\0 $DEST$PACKAGE|" "$DBe"
al@824 152 else
al@824 153 # Add new record
al@824 154 echo "$PKG=$DEST$PACKAGE" >> "$DBe"
al@824 155 fi
al@824 156 done
al@824 157
al@824 158
al@824 159 # Make descriptions.txt
al@824 160 if cpio -F "$folder/$pkgfile" -t 2>/dev/null | fgrep -q 'description.txt'; then
al@824 161 # Extract description.txt from package
al@824 162 cpio -F "$folder/$pkgfile" -i description.txt >/dev/null 2>&1
al@824 163 # Append descriptions DB
al@824 164 echo "$PACKAGE" >> "$DBd"
al@824 165 cat description.txt | sed 's|^$| |' >> "$DBd"
al@824 166 echo >> "$DBd"
al@824 167 rm description.txt
al@824 168 fi
al@824 169
al@824 170
al@824 171 # Make files.list
al@824 172 if cpio -F "$folder/$pkgfile" -t 2>/dev/null | fgrep -q 'files.list'; then
al@824 173 # Extract files.list from package
al@824 174 cpio -F "$folder/$pkgfile" -i files.list >/dev/null 2>&1
al@824 175 # Append files list DB
al@824 176 sed "s|.*|$PACKAGE: \0|" files.list >> "$DBf"
al@824 177 rm files.list
al@824 178 fi
al@824 179
al@824 180 # End line with the status
al@824 181 status
al@824 182 done < "$tempd/$SUM"
al@824 183
al@824 184
al@824 185 # Sort DB alphabetically
al@824 186 sort -o "$tempd/pi" "$DBi"; mv -f "$tempd/pi" "$DBi"
al@824 187
al@824 188 # Create empty files if they not exists
al@824 189 touch "$DBi" "$DBe" "$DBd" "$DBf"
al@824 190
al@824 191 # Compress files.list using lzma
al@824 192 sort -k2 -o "$DBf.sorted" "$DBf"
al@824 193 lzma e "$DBf.sorted" "$DBf.lzma"
al@824 194 rm "$DBf" "$DBf.sorted"
al@824 195
al@824 196 # Make DB readable for all
al@824 197 chmod a+r "$DBi" "$DBe" "$DBd" "$DBf.lzma"
al@824 198
al@824 199
al@824 200 # Make files for DB recharge
al@824 201 # --------------------------
al@824 202
al@824 203 cd "$folder"
al@824 204
al@824 205 # Make IDs: md5 and timestamp
al@824 206 ( md5sum "$tempd/$SUM" | cut -d' ' -f1 | tr '\n' ' '; date -ur "$DBi" +%s ) > IDs
al@824 207
al@824 208
al@824 209 # Make files-list.md5: decide whether to download files.list.lzma or not
al@824 210 md5sum "$DBf.lzma" | cut -d' ' -f1 | tr -d $'\n' > files-list.md5
al@824 211
al@824 212 # Make bundle to fast recharge
al@824 213 [ -f 'bundle.tar.lzma' ] && rm 'bundle.tar.lzma'
al@846 214 tar -chaf bundle.tar.lzma \
al@824 215 files-list.md5 packages.info descriptions.txt packages.equiv
al@824 216
al@824 217 # Clean up
al@824 218 rm files-list.md5
al@824 219 rm -r "$tempd"
al@824 220