tazpkg diff modules/getenv @ rev 840
Add a bunch of modules with new-style support of 'root' (not all commands are modules yet); strip and compress resources.
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Fri Aug 28 16:10:34 2015 +0300 (2015-08-28) |
parents | |
children | d6cbd0c5f273 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/modules/getenv Fri Aug 28 16:10:34 2015 +0300 1.3 @@ -0,0 +1,136 @@ 1.4 +#!/bin/sh 1.5 +# TazPkg - Tiny autonomous zone packages manager, hg.slitaz.org/tazpkg 1.6 +# getenv - TazPkg module 1.7 +# Get TazPkg working environment 1.8 + 1.9 + 1.10 +# Check and re-create files and folders (if permissions enough) 1.11 +missing() { 1.12 + case $1 in 1.13 + file) 1.14 + if [ ! -f "$2" ]; then 1.15 + case $(id -u) in 1.16 + 0) mkdir -p "$(dirname "$2")"; touch "$2" 1.17 + [ -n "$3" ] && cp -a "$3" "$(dirname "$2")" 1.18 + ;; 1.19 + *) _ 'Missing: %s' "$2"; _ 'Please run tazpkg as root.'; exit 1;; 1.20 + esac 1.21 + fi;; 1.22 + dir) 1.23 + if [ ! -d "$2" ]; then 1.24 + case $(id -u) in 1.25 + 0) mkdir -p "$2";; 1.26 + *) _ 'Missing: %s' "$2"; _ 'Please run tazpkg as root.'; exit 1;; 1.27 + esac 1.28 + fi;; 1.29 + esac 1.30 +} 1.31 + 1.32 +# Fill empty file with value 1.33 +fill() { 1.34 + if [ ! -s "$1" ]; then 1.35 + case $(id -u) in 1.36 + 0) echo "$2" > "$1";; 1.37 + *) _ 'File "%s" empty.' "$1"; _ 'Please run tazpkg as root.'; exit 1;; 1.38 + esac 1.39 + fi 1.40 +} 1.41 + 1.42 + 1.43 + 1.44 + 1.45 +# Setup main config files 1.46 +missing dir "$root/etc/slitaz/" 1.47 +missing file "$root/etc/slitaz/slitaz.conf" '/etc/slitaz/slitaz.conf' 1.48 +missing file "$root/etc/slitaz/tazpkg.conf" '/etc/slitaz/tazpkg.conf' 1.49 +missing file "$root/etc/slitaz-release"; fill "$root/etc/slitaz-release" 'cooking' 1.50 + 1.51 +# Read configuration 1.52 +if [ -n "$root" ]; then 1.53 + # Patch external conf files to correctly handle --root value 1.54 + slitaz_conf=$(mktemp); cp "$root/etc/slitaz/slitaz.conf" "$slitaz_conf" 1.55 + tazpkg_conf=$(mktemp); cp "$root/etc/slitaz/tazpkg.conf" "$tazpkg_conf" 1.56 + sed -i "s| /| $root/|g; s|\"/|\"$root/|g" "$slitaz_conf" "$tazpkg_conf" 1.57 + . "$slitaz_conf"; . "$tazpkg_conf" 1.58 + rm "$slitaz_conf" "$tazpkg_conf" 1.59 +else 1.60 + . /etc/slitaz/slitaz.conf; . /etc/slitaz/tazpkg.conf 1.61 +fi 1.62 + 1.63 +BLOCKED="$PKGS_DB/blocked-packages.list" 1.64 +UP_LIST="$PKGS_DB/packages.up" 1.65 + 1.66 +# Re-create TazPkg working folders and files 1.67 +for dir in "$PKGS_DB" "$CACHE_DIR" "$INSTALLED" "$SLITAZ_LOGS"; do 1.68 + missing dir "$dir" 1.69 +done 1.70 +for file in "$BLOCKED" "$UP_LIST" "$LOG" "$PKGS_DB/packages.info" "$PKGS_DB/mirror"; do 1.71 + missing file "$file" 1.72 +done 1.73 +fill "$PKGS_DB/mirror" "${ONLINE_PKGS%/}/" 1.74 + 1.75 +# Check for installed.info 1.76 +info_path="$PKGS_DB/installed.info" 1.77 +missing file "$info_path" 1.78 +if [ ! -s "$info_path" ]; then 1.79 + # Empty installed.info 1.80 + if [ "$(id -u)" -eq 0 ]; then 1.81 + # Root can re-create installed.info 1.82 + _ 'File "%s" generated. Please wait...' 'installed.info' 1.83 + for pkg in $(find "$INSTALLED" -name receipt); do 1.84 + unset PACKAGE VERSION EXTRAVERSION CATEGORY SHORT_DESC WEB_SITE \ 1.85 + TAGS PACKED_SIZE UNPACKED_SIZE DEPENDS 1.86 + . $pkg 1.87 + SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g') 1.88 + # remove newlines from some receipts 1.89 + DEPENDS=$(echo $DEPENDS) 1.90 + MD5="$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$PKGS_DB/installed.md5" | awk '{print $1}')" 1.91 + cat >> "$info_path" << EOT 1.92 +$PACKAGE $VERSION$EXTRAVERSION $CATEGORY $SHORT_DESC $WEB_SITE $TAGS $SIZES $DEPENDS $MD5 1.93 +EOT 1.94 + done 1.95 + else 1.96 + # User can't re-create installed.info 1.97 + fill "$info_path" 1.98 + fi 1.99 +else 1.100 + # Non-empty installed.info 1.101 + 1.102 + # Check for md5 field (#9) in the installed.info: older version missed it 1.103 + if [ -n "$(awk -F$'\t' 'BEGIN{ n = "" } { if(NF != 9){ n = "o"; } } END{ print n }' $info_path)" ]; then 1.104 + if [ "$(id -u)" -eq 0 ]; then 1.105 + # Root can re-create it 1.106 + _n 'File "%s" generated. Please wait...' 'installed.info.new' 1.107 + awk -F$'\t' -vm="$PKGS_DB/installed.md5" 'BEGIN{OFS="\t"} 1.108 + { 1.109 + if (NF != 9) { 1.110 + pkg = $1 "-" $2 ".tazpkg"; 1.111 + "fgrep " pkg " " m " | cut -c-32" | getline $9; 1.112 + $9 = ($9 == "") ? "00000000000000000000000000000000" : $9; 1.113 + } 1.114 + print; 1.115 + }' $info_path > $info_path.new 1.116 + mv -f $info_path.new $info_path 1.117 + status 1.118 + else 1.119 + # User can't re-create it 1.120 + _ 'Old "%s".' 'installed.info' 1.121 + _ 'Please run tazpkg as root.' 1.122 + exit 1 1.123 + fi 1.124 + fi 1.125 +fi 1.126 + 1.127 + 1.128 +if [ -n "$debug" ]; then 1.129 + cat <<EOT 1.130 +root = "$root" 1.131 +PKGS_DB = "$PKGS_DB" 1.132 +CACHE_DIR = "$CACHE_DIR" 1.133 +INSTALLED = "$INSTALLED" 1.134 +BLOCKED = "$BLOCKED" 1.135 +UP_LIST = "$UP_LIST" 1.136 +SLITAZ_LOGS = "$SLITAZ_LOGS" 1.137 +LOG = "$LOG" 1.138 +EOT 1.139 +fi