tazpkg diff modules/getenv @ rev 844
Finish modularization. Beta release: still have few FIXMEs and TODOs.
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Mon Oct 05 03:53:47 2015 +0300 (2015-10-05) |
parents | a02e36d44d06 |
children | 8a73a58ed3cb |
line diff
1.1 --- a/modules/getenv Fri Aug 28 16:10:34 2015 +0300 1.2 +++ b/modules/getenv Mon Oct 05 03:53:47 2015 +0300 1.3 @@ -4,26 +4,45 @@ 1.4 # Get TazPkg working environment 1.5 1.6 1.7 +# Set up the aliases to guaranteed to work with Busybox applets rather with the GNU Coreutils ones 1.8 +# due to some incompatibilities. 1.9 +# Please don't hesitate to expand or shrink this list (with justification). 1.10 +for i in awk basename bzcat cat chmod chroot clear cmp cp cpio cut date dd diff dirname dpkg-deb \ 1.11 + du egrep fgrep find grep gzip head httpd id ln ls lzcat md5sum mkdir mktemp mv readlink \ 1.12 + realpath rm rmdir rpm rpm2cpio sed sort stat su tac tail tar tee touch tr tty uniq unlzma wc \ 1.13 + wget which xzcat zcat; do 1.14 + alias $i="busybox $i" 1.15 +done 1.16 + 1.17 + 1.18 +. /lib/libtaz.sh 1.19 + 1.20 +# Report error and finish work 1.21 +die() { longline "$(_ "$@")" >&2; exit 1; } 1.22 + 1.23 +# Show debug messages 1.24 +debug() { if [ -n "$debug" ]; then colorize 036 "$@" >&2; fi; } 1.25 + 1.26 +debug "\n========\n$0 '$1' '$2' '$3' '$4'" 1.27 + 1.28 # Check and re-create files and folders (if permissions enough) 1.29 -missing() { 1.30 - case $1 in 1.31 - file) 1.32 - if [ ! -f "$2" ]; then 1.33 - case $(id -u) in 1.34 - 0) mkdir -p "$(dirname "$2")"; touch "$2" 1.35 - [ -n "$3" ] && cp -a "$3" "$(dirname "$2")" 1.36 - ;; 1.37 - *) _ 'Missing: %s' "$2"; _ 'Please run tazpkg as root.'; exit 1;; 1.38 - esac 1.39 - fi;; 1.40 - dir) 1.41 - if [ ! -d "$2" ]; then 1.42 - case $(id -u) in 1.43 - 0) mkdir -p "$2";; 1.44 - *) _ 'Missing: %s' "$2"; _ 'Please run tazpkg as root.'; exit 1;; 1.45 - esac 1.46 - fi;; 1.47 - esac 1.48 +missing_file() { 1.49 + if [ ! -f "$1" ]; then 1.50 + case $(id -u) in 1.51 + 0) mkdir -p "$(dirname "$1")"; touch "$1" 1.52 + [ -n "$2" ] && cp -a "$2" "$(dirname "$1")" 1.53 + ;; 1.54 + *) _ 'Missing: %s' "$1" >&2; die 'Please run tazpkg as root.';; 1.55 + esac 1.56 + fi 1.57 +} 1.58 +missing_dir() { 1.59 + if [ ! -d "$1" ]; then 1.60 + case $(id -u) in 1.61 + 0) mkdir -p "$1";; 1.62 + *) _ 'Missing: %s' "$1" >&2; die 'Please run tazpkg as root.';; 1.63 + esac 1.64 + fi 1.65 } 1.66 1.67 # Fill empty file with value 1.68 @@ -31,7 +50,7 @@ 1.69 if [ ! -s "$1" ]; then 1.70 case $(id -u) in 1.71 0) echo "$2" > "$1";; 1.72 - *) _ 'File "%s" empty.' "$1"; _ 'Please run tazpkg as root.'; exit 1;; 1.73 + *) _ 'File "%s" empty.' "$1" >&2; die 'Please run tazpkg as root.';; 1.74 esac 1.75 fi 1.76 } 1.77 @@ -39,11 +58,15 @@ 1.78 1.79 1.80 1.81 +# Normalize $root 1.82 +root="${root%/}" 1.83 +debug "root = '$root'" 1.84 + 1.85 # Setup main config files 1.86 -missing dir "$root/etc/slitaz/" 1.87 -missing file "$root/etc/slitaz/slitaz.conf" '/etc/slitaz/slitaz.conf' 1.88 -missing file "$root/etc/slitaz/tazpkg.conf" '/etc/slitaz/tazpkg.conf' 1.89 -missing file "$root/etc/slitaz-release"; fill "$root/etc/slitaz-release" 'cooking' 1.90 +missing_dir "$root/etc/slitaz/" 1.91 +missing_file "$root/etc/slitaz/slitaz.conf" '/etc/slitaz/slitaz.conf' 1.92 +missing_file "$root/etc/slitaz/tazpkg.conf" '/etc/slitaz/tazpkg.conf' 1.93 +missing_file "$root/etc/slitaz-release"; fill "$root/etc/slitaz-release" 'cooking' 1.94 1.95 # Read configuration 1.96 if [ -n "$root" ]; then 1.97 @@ -57,41 +80,55 @@ 1.98 . /etc/slitaz/slitaz.conf; . /etc/slitaz/tazpkg.conf 1.99 fi 1.100 1.101 +debug "PKGS_DB = '$PKGS_DB'" 1.102 +debug "INSTALLED = '$INSTALLED'" 1.103 +debug "SLITAZ_LOGS = '$SLITAZ_LOGS'" 1.104 +debug "LOG = '$LOG'" 1.105 + 1.106 BLOCKED="$PKGS_DB/blocked-packages.list" 1.107 +debug "BLOCKED = '$BLOCKED'" 1.108 UP_LIST="$PKGS_DB/packages.up" 1.109 +debug "UP_LIST = '$UP_LIST'" 1.110 +debug "CACHE_DIR = '$CACHE_DIR'" 1.111 +SAVE_CACHE_DIR="$CACHE_DIR" 1.112 + 1.113 1.114 # Re-create TazPkg working folders and files 1.115 for dir in "$PKGS_DB" "$CACHE_DIR" "$INSTALLED" "$SLITAZ_LOGS"; do 1.116 - missing dir "$dir" 1.117 + missing_dir "$dir" 1.118 done 1.119 for file in "$BLOCKED" "$UP_LIST" "$LOG" "$PKGS_DB/packages.info" "$PKGS_DB/mirror"; do 1.120 - missing file "$file" 1.121 + missing_file "$file" 1.122 done 1.123 fill "$PKGS_DB/mirror" "${ONLINE_PKGS%/}/" 1.124 1.125 + 1.126 # Check for installed.info 1.127 info_path="$PKGS_DB/installed.info" 1.128 -missing file "$info_path" 1.129 +missing_file "$info_path" 1.130 if [ ! -s "$info_path" ]; then 1.131 # Empty installed.info 1.132 - if [ "$(id -u)" -eq 0 ]; then 1.133 - # Root can re-create installed.info 1.134 - _ 'File "%s" generated. Please wait...' 'installed.info' 1.135 - for pkg in $(find "$INSTALLED" -name receipt); do 1.136 - unset PACKAGE VERSION EXTRAVERSION CATEGORY SHORT_DESC WEB_SITE \ 1.137 - TAGS PACKED_SIZE UNPACKED_SIZE DEPENDS 1.138 - . $pkg 1.139 - SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g') 1.140 - # remove newlines from some receipts 1.141 - DEPENDS=$(echo $DEPENDS) 1.142 - MD5="$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$PKGS_DB/installed.md5" | awk '{print $1}')" 1.143 - cat >> "$info_path" << EOT 1.144 + if [ -n "$(ls "$INSTALLED")" ]; then 1.145 + # Some packages are installed 1.146 + if [ "$(id -u)" -eq 0 ]; then 1.147 + # Root can re-create installed.info 1.148 + _ 'File "%s" generated. Please wait...' 'installed.info' >&2 1.149 + for pkg in $(find "$INSTALLED" -name receipt); do 1.150 + unset PACKAGE VERSION EXTRAVERSION CATEGORY SHORT_DESC WEB_SITE \ 1.151 + TAGS PACKED_SIZE UNPACKED_SIZE DEPENDS 1.152 + . $pkg 1.153 + SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g') 1.154 + # remove newlines from some receipts 1.155 + DEPENDS=$(echo $DEPENDS) 1.156 + MD5="$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$PKGS_DB/installed.md5" | awk '{print $1}')" 1.157 + cat >> "$info_path" << EOT 1.158 $PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $MD5 1.159 EOT 1.160 - done 1.161 - else 1.162 - # User can't re-create installed.info 1.163 - fill "$info_path" 1.164 + done 1.165 + else 1.166 + # User can't re-create installed.info 1.167 + fill "$info_path" 1.168 + fi 1.169 fi 1.170 else 1.171 # Non-empty installed.info 1.172 @@ -100,7 +137,7 @@ 1.173 if [ -n "$(awk -F$'\t' 'BEGIN{ n = "" } { if(NF != 9){ n = "o"; } } END{ print n }' $info_path)" ]; then 1.174 if [ "$(id -u)" -eq 0 ]; then 1.175 # Root can re-create it 1.176 - _n 'File "%s" generated. Please wait...' 'installed.info.new' 1.177 + _n 'File "%s" generated. Please wait...' 'installed.info.new' >&2 1.178 awk -F$'\t' -vm="$PKGS_DB/installed.md5" 'BEGIN{OFS="\t"} 1.179 { 1.180 if (NF != 9) { 1.181 @@ -114,23 +151,39 @@ 1.182 status 1.183 else 1.184 # User can't re-create it 1.185 - _ 'Old "%s".' 'installed.info' 1.186 - _ 'Please run tazpkg as root.' 1.187 - exit 1 1.188 + _ 'Old "%s".' 'installed.info' >&2; die 'Please run tazpkg as root.' 1.189 fi 1.190 fi 1.191 fi 1.192 1.193 1.194 -if [ -n "$debug" ]; then 1.195 - cat <<EOT 1.196 -root = "$root" 1.197 -PKGS_DB = "$PKGS_DB" 1.198 -CACHE_DIR = "$CACHE_DIR" 1.199 -INSTALLED = "$INSTALLED" 1.200 -BLOCKED = "$BLOCKED" 1.201 -UP_LIST = "$UP_LIST" 1.202 -SLITAZ_LOGS = "$SLITAZ_LOGS" 1.203 -LOG = "$LOG" 1.204 -EOT 1.205 +# Check for packages.info 1.206 +if [ ! -s "$PKGS_DB/packages.info" -a "$(id -u)" -eq 0 -a "$0" != '@@MODULES@@/recharge' ]; then 1.207 + @@MODULES@@/recharge >&2 1.208 fi 1.209 + 1.210 + 1.211 + 1.212 +# Get repositories priority using $PKGS_DB/priority. 1.213 +# In this file undigest repos are called by their names and main mirror by 'main' 1.214 + 1.215 +PRIORITY="$( 1.216 +{ 1.217 + [ -s "$PKGS_DB/priority" ] && cat "$PKGS_DB/priority" 1.218 + echo 'main' 1.219 + [ -d "$PKGS_DB/undigest" ] && ls "$PKGS_DB/undigest" 1.220 +} | awk -vv="$PKGS_DB/undigest/" '{ 1.221 + if(arr[$0] != 1) { arr[$0]=1; print v $0; } 1.222 +}' | sed 's|/undigest/main||')" 1.223 +debug "PRIORITY = '$PRIORITY'" 1.224 + 1.225 + 1.226 +# TazPkg version 1.227 +export VERSION=$(awk -F$'\t' '$1=="tazpkg"{print $2;exit}' "$PKGS_DB/installed.info") 1.228 +# User Agent 1.229 +export UA="TazPkg-${VERSION:-Unknown}" 1.230 +debug "UA = '$UA'" 1.231 + 1.232 +CUR_DIR="$(pwd)" 1.233 + 1.234 +debug '-- end getenv --'