tazpkg annotate modules/getenv @ rev 953
revision of german messages
author | Hans-G?nter Theisgen |
---|---|
date | Mon Oct 09 17:16:43 2017 +0100 (2017-10-09) |
parents | 45d90da42ede |
children | 03544b89ac81 |
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 |
paul@943 | 7 # Set up the aliases 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 # Show debug messages |
al@846 | 21 debug() { |
al@846 | 22 if [ -n "$debug" ]; then |
al@846 | 23 colorize 036 "$@" >&2 |
al@849 | 24 # $LOG is unavailable at the early stage on 'getenv' |
al@849 | 25 [ -n "$LOG" ] && echo -e "$(date +%f) $@" >> "${LOG/.log/.debug}" |
al@846 | 26 fi |
al@846 | 27 } |
al@844 | 28 |
al@844 | 29 debug "\n========\n$0 '$1' '$2' '$3' '$4'" |
al@844 | 30 |
al@840 | 31 # Check and re-create files and folders (if permissions enough) |
al@844 | 32 missing_file() { |
al@844 | 33 if [ ! -f "$1" ]; then |
al@844 | 34 case $(id -u) in |
al@844 | 35 0) mkdir -p "$(dirname "$1")"; touch "$1" |
al@844 | 36 [ -n "$2" ] && cp -a "$2" "$(dirname "$1")" |
al@844 | 37 ;; |
al@844 | 38 *) _ 'Missing: %s' "$1" >&2; die 'Please run tazpkg as root.';; |
al@844 | 39 esac |
al@844 | 40 fi |
al@844 | 41 } |
al@844 | 42 missing_dir() { |
al@844 | 43 if [ ! -d "$1" ]; then |
al@844 | 44 case $(id -u) in |
al@844 | 45 0) mkdir -p "$1";; |
al@844 | 46 *) _ 'Missing: %s' "$1" >&2; die 'Please run tazpkg as root.';; |
al@844 | 47 esac |
al@844 | 48 fi |
al@840 | 49 } |
al@840 | 50 |
al@840 | 51 # Fill empty file with value |
al@840 | 52 fill() { |
al@840 | 53 if [ ! -s "$1" ]; then |
al@840 | 54 case $(id -u) in |
al@840 | 55 0) echo "$2" > "$1";; |
al@844 | 56 *) _ 'File "%s" empty.' "$1" >&2; die 'Please run tazpkg as root.';; |
al@840 | 57 esac |
al@840 | 58 fi |
al@840 | 59 } |
al@840 | 60 |
al@840 | 61 |
al@840 | 62 |
al@840 | 63 |
al@844 | 64 # Normalize $root |
al@844 | 65 root="${root%/}" |
al@844 | 66 debug "root = '$root'" |
al@844 | 67 |
al@840 | 68 # Setup main config files |
al@844 | 69 missing_dir "$root/etc/slitaz/" |
al@844 | 70 missing_file "$root/etc/slitaz/slitaz.conf" '/etc/slitaz/slitaz.conf' |
al@844 | 71 missing_file "$root/etc/slitaz/tazpkg.conf" '/etc/slitaz/tazpkg.conf' |
al@844 | 72 missing_file "$root/etc/slitaz-release"; fill "$root/etc/slitaz-release" 'cooking' |
al@840 | 73 |
al@840 | 74 # Read configuration |
al@840 | 75 if [ -n "$root" ]; then |
al@840 | 76 # Patch external conf files to correctly handle --root value |
al@840 | 77 slitaz_conf=$(mktemp); cp "$root/etc/slitaz/slitaz.conf" "$slitaz_conf" |
al@840 | 78 tazpkg_conf=$(mktemp); cp "$root/etc/slitaz/tazpkg.conf" "$tazpkg_conf" |
al@840 | 79 sed -i "s| /| $root/|g; s|\"/|\"$root/|g" "$slitaz_conf" "$tazpkg_conf" |
al@840 | 80 . "$slitaz_conf"; . "$tazpkg_conf" |
al@840 | 81 rm "$slitaz_conf" "$tazpkg_conf" |
al@840 | 82 else |
al@840 | 83 . /etc/slitaz/slitaz.conf; . /etc/slitaz/tazpkg.conf |
al@840 | 84 fi |
al@840 | 85 |
al@844 | 86 debug "PKGS_DB = '$PKGS_DB'" |
al@844 | 87 debug "INSTALLED = '$INSTALLED'" |
al@844 | 88 debug "SLITAZ_LOGS = '$SLITAZ_LOGS'" |
al@844 | 89 debug "LOG = '$LOG'" |
al@844 | 90 |
al@840 | 91 BLOCKED="$PKGS_DB/blocked-packages.list" |
al@844 | 92 debug "BLOCKED = '$BLOCKED'" |
al@840 | 93 UP_LIST="$PKGS_DB/packages.up" |
al@844 | 94 debug "UP_LIST = '$UP_LIST'" |
al@844 | 95 debug "CACHE_DIR = '$CACHE_DIR'" |
al@844 | 96 SAVE_CACHE_DIR="$CACHE_DIR" |
al@844 | 97 |
al@840 | 98 |
al@840 | 99 # Re-create TazPkg working folders and files |
al@840 | 100 for dir in "$PKGS_DB" "$CACHE_DIR" "$INSTALLED" "$SLITAZ_LOGS"; do |
al@844 | 101 missing_dir "$dir" |
al@840 | 102 done |
al@840 | 103 for file in "$BLOCKED" "$UP_LIST" "$LOG" "$PKGS_DB/packages.info" "$PKGS_DB/mirror"; do |
al@844 | 104 missing_file "$file" |
al@840 | 105 done |
al@840 | 106 fill "$PKGS_DB/mirror" "${ONLINE_PKGS%/}/" |
al@840 | 107 |
al@844 | 108 |
al@840 | 109 # Check for installed.info |
al@840 | 110 info_path="$PKGS_DB/installed.info" |
al@844 | 111 missing_file "$info_path" |
al@840 | 112 if [ ! -s "$info_path" ]; then |
al@840 | 113 # Empty installed.info |
al@864 | 114 if [ -n "$(find "$INSTALLED" -name 'receipt')" ]; then |
al@844 | 115 # Some packages are installed |
al@844 | 116 if [ "$(id -u)" -eq 0 ]; then |
al@844 | 117 # Root can re-create installed.info |
al@844 | 118 _ 'File "%s" generated. Please wait...' 'installed.info' >&2 |
al@844 | 119 for pkg in $(find "$INSTALLED" -name receipt); do |
al@844 | 120 unset PACKAGE VERSION EXTRAVERSION CATEGORY SHORT_DESC WEB_SITE \ |
al@844 | 121 TAGS PACKED_SIZE UNPACKED_SIZE DEPENDS |
al@844 | 122 . $pkg |
al@844 | 123 SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g') |
al@844 | 124 # remove newlines from some receipts |
al@844 | 125 DEPENDS=$(echo $DEPENDS) |
al@844 | 126 MD5="$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$PKGS_DB/installed.md5" | awk '{print $1}')" |
al@844 | 127 cat >> "$info_path" << EOT |
al@840 | 128 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $MD5 |
al@840 | 129 EOT |
al@844 | 130 done |
al@844 | 131 else |
al@844 | 132 # User can't re-create installed.info |
al@844 | 133 fill "$info_path" |
al@844 | 134 fi |
al@840 | 135 fi |
al@840 | 136 else |
al@840 | 137 # Non-empty installed.info |
al@840 | 138 |
al@840 | 139 # Check for md5 field (#9) in the installed.info: older version missed it |
al@840 | 140 if [ -n "$(awk -F$'\t' 'BEGIN{ n = "" } { if(NF != 9){ n = "o"; } } END{ print n }' $info_path)" ]; then |
al@840 | 141 if [ "$(id -u)" -eq 0 ]; then |
al@840 | 142 # Root can re-create it |
al@844 | 143 _n 'File "%s" generated. Please wait...' 'installed.info.new' >&2 |
al@840 | 144 awk -F$'\t' -vm="$PKGS_DB/installed.md5" 'BEGIN{OFS="\t"} |
al@840 | 145 { |
al@840 | 146 if (NF != 9) { |
al@840 | 147 pkg = $1 "-" $2 ".tazpkg"; |
al@840 | 148 "fgrep " pkg " " m " | cut -c-32" | getline $9; |
al@840 | 149 $9 = ($9 == "") ? "00000000000000000000000000000000" : $9; |
al@840 | 150 } |
al@840 | 151 print; |
al@840 | 152 }' $info_path > $info_path.new |
al@840 | 153 mv -f $info_path.new $info_path |
al@840 | 154 status |
al@840 | 155 else |
al@840 | 156 # User can't re-create it |
al@844 | 157 _ 'Old "%s".' 'installed.info' >&2; die 'Please run tazpkg as root.' |
al@840 | 158 fi |
al@840 | 159 fi |
al@840 | 160 fi |
al@840 | 161 |
al@840 | 162 |
al@844 | 163 # Check for packages.info |
al@844 | 164 if [ ! -s "$PKGS_DB/packages.info" -a "$(id -u)" -eq 0 -a "$0" != '@@MODULES@@/recharge' ]; then |
al@844 | 165 @@MODULES@@/recharge >&2 |
al@840 | 166 fi |
al@844 | 167 |
al@844 | 168 |
al@844 | 169 |
al@844 | 170 # Get repositories priority using $PKGS_DB/priority. |
al@844 | 171 # In this file undigest repos are called by their names and main mirror by 'main' |
al@844 | 172 |
al@844 | 173 PRIORITY="$( |
al@844 | 174 { |
al@844 | 175 [ -s "$PKGS_DB/priority" ] && cat "$PKGS_DB/priority" |
al@844 | 176 echo 'main' |
al@844 | 177 [ -d "$PKGS_DB/undigest" ] && ls "$PKGS_DB/undigest" |
al@844 | 178 } | awk -vv="$PKGS_DB/undigest/" '{ |
al@844 | 179 if(arr[$0] != 1) { arr[$0]=1; print v $0; } |
al@844 | 180 }' | sed 's|/undigest/main||')" |
al@844 | 181 debug "PRIORITY = '$PRIORITY'" |
al@844 | 182 |
al@844 | 183 |
al@844 | 184 # TazPkg version |
al@844 | 185 export VERSION=$(awk -F$'\t' '$1=="tazpkg"{print $2;exit}' "$PKGS_DB/installed.info") |
al@844 | 186 # User Agent |
al@844 | 187 export UA="TazPkg-${VERSION:-Unknown}" |
al@844 | 188 debug "UA = '$UA'" |
al@844 | 189 |
al@844 | 190 CUR_DIR="$(pwd)" |
al@844 | 191 |
al@876 | 192 |
al@844 | 193 debug '-- end getenv --' |