tazpkg annotate modules/getenv @ 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.
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 | b6daeaa95431 |
rev | line source |
---|---|
al@840 | 1 #!/bin/sh |
al@840 | 2 # TazPkg - Tiny autonomous zone packages manager, hg.slitaz.org/tazpkg |
al@840 | 3 # getenv - TazPkg module |
al@840 | 4 # Get TazPkg working environment |
al@840 | 5 |
al@840 | 6 |
al@844 | 7 # Set up the aliases to guaranteed to work with Busybox applets rather with the GNU Coreutils ones |
al@844 | 8 # due to some incompatibilities. |
al@844 | 9 # Please don't hesitate to expand or shrink this list (with justification). |
al@844 | 10 for i in awk basename bzcat cat chmod chroot clear cmp cp cpio cut date dd diff dirname dpkg-deb \ |
al@844 | 11 du egrep fgrep find grep gzip head httpd id ln ls lzcat md5sum mkdir mktemp mv readlink \ |
al@844 | 12 realpath rm rmdir rpm rpm2cpio sed sort stat su tac tail tar tee touch tr tty uniq unlzma wc \ |
al@844 | 13 wget which xzcat zcat; do |
al@844 | 14 alias $i="busybox $i" |
al@844 | 15 done |
al@844 | 16 |
al@844 | 17 |
al@844 | 18 . /lib/libtaz.sh |
al@844 | 19 |
al@844 | 20 # Report error and finish work |
al@844 | 21 die() { longline "$(_ "$@")" >&2; exit 1; } |
al@844 | 22 |
al@844 | 23 # Show debug messages |
al@846 | 24 debug() { |
al@846 | 25 if [ -n "$debug" ]; then |
al@846 | 26 colorize 036 "$@" >&2 |
al@846 | 27 echo -e "$(date +%f) $@" >> "${LOG/.log/.debug}" |
al@846 | 28 fi |
al@846 | 29 } |
al@844 | 30 |
al@844 | 31 debug "\n========\n$0 '$1' '$2' '$3' '$4'" |
al@844 | 32 |
al@840 | 33 # Check and re-create files and folders (if permissions enough) |
al@844 | 34 missing_file() { |
al@844 | 35 if [ ! -f "$1" ]; then |
al@844 | 36 case $(id -u) in |
al@844 | 37 0) mkdir -p "$(dirname "$1")"; touch "$1" |
al@844 | 38 [ -n "$2" ] && cp -a "$2" "$(dirname "$1")" |
al@844 | 39 ;; |
al@844 | 40 *) _ 'Missing: %s' "$1" >&2; die 'Please run tazpkg as root.';; |
al@844 | 41 esac |
al@844 | 42 fi |
al@844 | 43 } |
al@844 | 44 missing_dir() { |
al@844 | 45 if [ ! -d "$1" ]; then |
al@844 | 46 case $(id -u) in |
al@844 | 47 0) mkdir -p "$1";; |
al@844 | 48 *) _ 'Missing: %s' "$1" >&2; die 'Please run tazpkg as root.';; |
al@844 | 49 esac |
al@844 | 50 fi |
al@840 | 51 } |
al@840 | 52 |
al@840 | 53 # Fill empty file with value |
al@840 | 54 fill() { |
al@840 | 55 if [ ! -s "$1" ]; then |
al@840 | 56 case $(id -u) in |
al@840 | 57 0) echo "$2" > "$1";; |
al@844 | 58 *) _ 'File "%s" empty.' "$1" >&2; die 'Please run tazpkg as root.';; |
al@840 | 59 esac |
al@840 | 60 fi |
al@840 | 61 } |
al@840 | 62 |
al@840 | 63 |
al@840 | 64 |
al@840 | 65 |
al@844 | 66 # Normalize $root |
al@844 | 67 root="${root%/}" |
al@844 | 68 debug "root = '$root'" |
al@844 | 69 |
al@840 | 70 # Setup main config files |
al@844 | 71 missing_dir "$root/etc/slitaz/" |
al@844 | 72 missing_file "$root/etc/slitaz/slitaz.conf" '/etc/slitaz/slitaz.conf' |
al@844 | 73 missing_file "$root/etc/slitaz/tazpkg.conf" '/etc/slitaz/tazpkg.conf' |
al@844 | 74 missing_file "$root/etc/slitaz-release"; fill "$root/etc/slitaz-release" 'cooking' |
al@840 | 75 |
al@840 | 76 # Read configuration |
al@840 | 77 if [ -n "$root" ]; then |
al@840 | 78 # Patch external conf files to correctly handle --root value |
al@840 | 79 slitaz_conf=$(mktemp); cp "$root/etc/slitaz/slitaz.conf" "$slitaz_conf" |
al@840 | 80 tazpkg_conf=$(mktemp); cp "$root/etc/slitaz/tazpkg.conf" "$tazpkg_conf" |
al@840 | 81 sed -i "s| /| $root/|g; s|\"/|\"$root/|g" "$slitaz_conf" "$tazpkg_conf" |
al@840 | 82 . "$slitaz_conf"; . "$tazpkg_conf" |
al@840 | 83 rm "$slitaz_conf" "$tazpkg_conf" |
al@840 | 84 else |
al@840 | 85 . /etc/slitaz/slitaz.conf; . /etc/slitaz/tazpkg.conf |
al@840 | 86 fi |
al@840 | 87 |
al@844 | 88 debug "PKGS_DB = '$PKGS_DB'" |
al@844 | 89 debug "INSTALLED = '$INSTALLED'" |
al@844 | 90 debug "SLITAZ_LOGS = '$SLITAZ_LOGS'" |
al@844 | 91 debug "LOG = '$LOG'" |
al@844 | 92 |
al@840 | 93 BLOCKED="$PKGS_DB/blocked-packages.list" |
al@844 | 94 debug "BLOCKED = '$BLOCKED'" |
al@840 | 95 UP_LIST="$PKGS_DB/packages.up" |
al@844 | 96 debug "UP_LIST = '$UP_LIST'" |
al@844 | 97 debug "CACHE_DIR = '$CACHE_DIR'" |
al@844 | 98 SAVE_CACHE_DIR="$CACHE_DIR" |
al@844 | 99 |
al@840 | 100 |
al@840 | 101 # Re-create TazPkg working folders and files |
al@840 | 102 for dir in "$PKGS_DB" "$CACHE_DIR" "$INSTALLED" "$SLITAZ_LOGS"; do |
al@844 | 103 missing_dir "$dir" |
al@840 | 104 done |
al@840 | 105 for file in "$BLOCKED" "$UP_LIST" "$LOG" "$PKGS_DB/packages.info" "$PKGS_DB/mirror"; do |
al@844 | 106 missing_file "$file" |
al@840 | 107 done |
al@840 | 108 fill "$PKGS_DB/mirror" "${ONLINE_PKGS%/}/" |
al@840 | 109 |
al@844 | 110 |
al@840 | 111 # Check for installed.info |
al@840 | 112 info_path="$PKGS_DB/installed.info" |
al@844 | 113 missing_file "$info_path" |
al@840 | 114 if [ ! -s "$info_path" ]; then |
al@840 | 115 # Empty installed.info |
al@844 | 116 if [ -n "$(ls "$INSTALLED")" ]; then |
al@844 | 117 # Some packages are installed |
al@844 | 118 if [ "$(id -u)" -eq 0 ]; then |
al@844 | 119 # Root can re-create installed.info |
al@844 | 120 _ 'File "%s" generated. Please wait...' 'installed.info' >&2 |
al@844 | 121 for pkg in $(find "$INSTALLED" -name receipt); do |
al@844 | 122 unset PACKAGE VERSION EXTRAVERSION CATEGORY SHORT_DESC WEB_SITE \ |
al@844 | 123 TAGS PACKED_SIZE UNPACKED_SIZE DEPENDS |
al@844 | 124 . $pkg |
al@844 | 125 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g') |
al@844 | 126 # remove newlines from some receipts |
al@844 | 127 DEPENDS=$(echo $DEPENDS) |
al@844 | 128 MD5="$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$PKGS_DB/installed.md5" | awk '{print $1}')" |
al@844 | 129 cat >> "$info_path" << EOT |
al@840 | 130 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $MD5 |
al@840 | 131 EOT |
al@844 | 132 done |
al@844 | 133 else |
al@844 | 134 # User can't re-create installed.info |
al@844 | 135 fill "$info_path" |
al@844 | 136 fi |
al@840 | 137 fi |
al@840 | 138 else |
al@840 | 139 # Non-empty installed.info |
al@840 | 140 |
al@840 | 141 # Check for md5 field (#9) in the installed.info: older version missed it |
al@840 | 142 if [ -n "$(awk -F$'\t' 'BEGIN{ n = "" } { if(NF != 9){ n = "o"; } } END{ print n }' $info_path)" ]; then |
al@840 | 143 if [ "$(id -u)" -eq 0 ]; then |
al@840 | 144 # Root can re-create it |
al@844 | 145 _n 'File "%s" generated. Please wait...' 'installed.info.new' >&2 |
al@840 | 146 awk -F$'\t' -vm="$PKGS_DB/installed.md5" 'BEGIN{OFS="\t"} |
al@840 | 147 { |
al@840 | 148 if (NF != 9) { |
al@840 | 149 pkg = $1 "-" $2 ".tazpkg"; |
al@840 | 150 "fgrep " pkg " " m " | cut -c-32" | getline $9; |
al@840 | 151 $9 = ($9 == "") ? "00000000000000000000000000000000" : $9; |
al@840 | 152 } |
al@840 | 153 print; |
al@840 | 154 }' $info_path > $info_path.new |
al@840 | 155 mv -f $info_path.new $info_path |
al@840 | 156 status |
al@840 | 157 else |
al@840 | 158 # User can't re-create it |
al@844 | 159 _ 'Old "%s".' 'installed.info' >&2; die 'Please run tazpkg as root.' |
al@840 | 160 fi |
al@840 | 161 fi |
al@840 | 162 fi |
al@840 | 163 |
al@840 | 164 |
al@844 | 165 # Check for packages.info |
al@844 | 166 if [ ! -s "$PKGS_DB/packages.info" -a "$(id -u)" -eq 0 -a "$0" != '@@MODULES@@/recharge' ]; then |
al@844 | 167 @@MODULES@@/recharge >&2 |
al@840 | 168 fi |
al@844 | 169 |
al@844 | 170 |
al@844 | 171 |
al@844 | 172 # Get repositories priority using $PKGS_DB/priority. |
al@844 | 173 # In this file undigest repos are called by their names and main mirror by 'main' |
al@844 | 174 |
al@844 | 175 PRIORITY="$( |
al@844 | 176 { |
al@844 | 177 [ -s "$PKGS_DB/priority" ] && cat "$PKGS_DB/priority" |
al@844 | 178 echo 'main' |
al@844 | 179 [ -d "$PKGS_DB/undigest" ] && ls "$PKGS_DB/undigest" |
al@844 | 180 } | awk -vv="$PKGS_DB/undigest/" '{ |
al@844 | 181 if(arr[$0] != 1) { arr[$0]=1; print v $0; } |
al@844 | 182 }' | sed 's|/undigest/main||')" |
al@844 | 183 debug "PRIORITY = '$PRIORITY'" |
al@844 | 184 |
al@844 | 185 |
al@844 | 186 # TazPkg version |
al@844 | 187 export VERSION=$(awk -F$'\t' '$1=="tazpkg"{print $2;exit}' "$PKGS_DB/installed.info") |
al@844 | 188 # User Agent |
al@844 | 189 export UA="TazPkg-${VERSION:-Unknown}" |
al@844 | 190 debug "UA = '$UA'" |
al@844 | 191 |
al@844 | 192 CUR_DIR="$(pwd)" |
al@844 | 193 |
al@844 | 194 debug '-- end getenv --' |