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