tazpkg rev 795
pkgs.cgi: change look of "do=command" page; tazpkg: rework "remove" command.
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Thu Apr 30 02:21:14 2015 +0300 (2015-04-30) |
parents | afe32a913bc4 |
children | 547d8bdde963 |
files | tazpanel/pkgs.cgi tazpkg |
line diff
1.1 --- a/tazpanel/pkgs.cgi Wed Apr 29 17:06:31 2015 +0200 1.2 +++ b/tazpanel/pkgs.cgi Thu Apr 30 02:21:14 2015 +0300 1.3 @@ -841,9 +841,9 @@ 1.4 # Describe the command 1.5 bpkgs="<b>$pkgs</b>"; opt='' 1.6 case $cmd in 1.7 - install) MSG="$(_ 'Installing: %s' "$bpkgs")"; opt=--forced; cmd=get-install ;; 1.8 + install) MSG="$(_ 'Installing: %s' "$bpkgs")"; opt='--forced'; cmd='get-install' ;; 1.9 remove) MSG="$(_ 'Removing: %s' "$bpkgs")" ;; 1.10 - link) MSG="$(_ 'Linking: %s' "$bpkgs")"; opt=$(readlink $PKGS_DB/fslink) ;; 1.11 + link) MSG="$(_ 'Linking: %s' "$bpkgs")"; opt="$(readlink $PKGS_DB/fslink)" ;; 1.12 block) MSG="$(_ 'Blocking: %s' "$bpkgs")" ;; 1.13 unblock) MSG="$(_ 'Unblocking: %s' "$bpkgs")" ;; 1.14 chblock) MSG="$(_ '(Un)blocking: %s' "$bpkgs")" ;; 1.15 @@ -852,16 +852,18 @@ 1.16 1.17 cat <<EOT 1.18 <h2>TazPkg: $(GET do)</h2> 1.19 -<section> 1.20 - <div>$MSG</div> 1.21 - <pre class="scroll"> 1.22 + 1.23 +<div>$MSG</div> 1.24 EOT 1.25 # Do the command for all asked packages 1.26 cd /tmp 1.27 + export output='html' 1.28 + 1.29 for pkg in $pkgs; do 1.30 - echo $(_n 'y') | tazpkg $cmd $pkg $opt 2>/dev/null | filter_taztools_msgs 1.31 + #echo $(_n 'y') | 1.32 + tazpkg $cmd $pkg $opt 2>/dev/null | filter_taztools_msgs 1.33 done 1.34 - echo '</pre></section>' ;; 1.35 + ;; 1.36 1.37 1.38 *\ info\ *)
2.1 --- a/tazpkg Wed Apr 29 17:06:31 2015 +0200 2.2 +++ b/tazpkg Thu Apr 30 02:21:14 2015 +0300 2.3 @@ -1,23 +1,24 @@ 2.4 #!/bin/sh 2.5 # 2.6 -# TazPKG - Tiny autonomous zone packages manager. 2.7 +# TazPkg - Tiny autonomous zone packages manager. 2.8 # 2.9 # This is a lightweight packages manager for *.tazpkg files written in SHell 2.10 -# script. It works well with Busybox ash shell and bash. TazPKG lets you 2.11 +# script. It works well with Busybox ash shell and bash. TazPkg lets you 2.12 # list, install, remove, download or get information about a package. You 2.13 # can use 'tazpkg usage' to get a list of commands with short descriptions. 2.14 -# TazPKG also resolves dependencies and can upgrade packages from a mirror. 2.15 +# TazPkg also resolves dependencies and can upgrade packages from a mirror. 2.16 # 2.17 # (C) 2007-2015 SliTaz - GNU General Public License v3. 2.18 # 2.19 # Authors: See the AUTHORS files 2.20 # 2.21 2.22 + 2.23 #################### 2.24 # Script variables # 2.25 #################### 2.26 2.27 -# TazPKG version 2.28 +# TazPkg version 2.29 VERSION=5.3.4 2.30 2.31 . /etc/slitaz/slitaz.conf 2.32 @@ -85,12 +86,26 @@ 2.33 2.34 # Print localized title 2.35 2.36 -title() { newline; boldify "$(_ "$@")"; separator; } 2.37 +title() { 2.38 + case $output in 2.39 + html) 2.40 + echo "<section><header>$(_ "$@")</header><pre class=\"scroll\">";; 2.41 + *) 2.42 + newline; boldify "$(_ "$@")"; separator;; 2.43 + esac 2.44 +} 2.45 2.46 2.47 # Print footer 2.48 2.49 -footer() { separator; echo "$1"; [ -n "$1" ] && newline; } 2.50 +footer() { 2.51 + case $output in 2.52 + html) 2.53 + echo "</pre><footer>$1</header></section>";; 2.54 + *) 2.55 + separator; echo "$1"; [ -n "$1" ] && newline;; 2.56 + esac 2.57 +} 2.58 2.59 2.60 # Print current action in brown color (separate from any other msgs) 2.61 @@ -645,6 +660,20 @@ 2.62 } 2.63 2.64 2.65 +# Print short package description 2.66 +print_short_description() { 2.67 + local short_desc='' 2.68 + for LC in $LANG ${LANG%_*}; do 2.69 + if [ -e "$PKGS_DB/packages-desc.$LC" ]; then 2.70 + short_desc=$(grep -e "^$1 " $PKGS_DB/packages-desc.$LC | cut -d' ' -f2) 2.71 + fi 2.72 + done 2.73 + [ -z "$short_desc" ] && \ 2.74 + short_desc="$(awk -F$'\t' -vp="$PACKAGE" '{if($1==p){print $4;exit}}' $PKGS_DB/packages.info)" 2.75 + longline "$short_desc" 2.76 +} 2.77 + 2.78 + 2.79 # This function installs a package in the rootfs. 2.80 2.81 install_package() 2.82 @@ -691,8 +720,8 @@ 2.83 2.84 title 'Installation of package "%s"' $PACKAGE 2.85 2.86 - longline "$(awk -F$'\t' -vp="$PACKAGE" '{if($1==p){print $4;exit}}' $PKGS_DB/packages.info)" 2.87 - separator | tr -c $'\n' '-' 2.88 + print_short_description $PACKAGE 2.89 + separator '-' 2.90 2.91 action 'Copying package...' 2.92 cp $PACKAGE_FILE $TMP_DIR 2.93 @@ -815,7 +844,7 @@ 2.94 fi 2.95 2.96 action 'Installing package...' 2.97 - [ "$(busybox ls fs/* 2> /dev/null)" ] && cp -af fs/* $ROOT/ 2.98 + [ "$(busybox ls fs/* 2>/dev/null)" ] && cp -af fs/* $ROOT/ 2.99 status 2.100 2.101 if [ -s files2remove.list ]; then 2.102 @@ -834,7 +863,9 @@ 2.103 2.104 # Post install commands. 2.105 if grep -q ^post_install $ROOT$INSTALLED/$PACKAGE/receipt; then 2.106 + action "Execute post-install commands..." 2.107 post_install $ROOT 2.108 + status 2.109 fi 2.110 2.111 # Update-desktop-database if needed. 2.112 @@ -1793,120 +1824,132 @@ 2.113 check_for_installed_info 2.114 2.115 [ -n "$root" ] && ROOT="$root" 2.116 + 2.117 if [ ! -f "$ROOT$INSTALLED/$PACKAGE/receipt" ]; then 2.118 - newline 2.119 - _ 'Package "%s" is not installed.' $PACKAGE 2.120 + newline; _ 'Package "%s" is not installed.' $PACKAGE 2.121 exit 0 2.122 - else 2.123 - ALTERED="" 2.124 - THE_PACKAGE=$PACKAGE # altered by receipt 2.125 - for i in $(cd $ROOT$INSTALLED ; ls); do 2.126 - [ -f $ROOT$INSTALLED/$i/receipt ] || continue 2.127 - DEPENDS="" 2.128 - . $ROOT$INSTALLED/$i/receipt 2.129 - case " $(echo $DEPENDS) " in 2.130 - *\ $THE_PACKAGE\ *) ALTERED="$ALTERED $i";; 2.131 - esac 2.132 - done 2.133 - EXTRAVERSION="" 2.134 - . $ROOT$INSTALLED/$THE_PACKAGE/receipt 2.135 fi 2.136 - newline 2.137 + 2.138 + . $ROOT$INSTALLED/$PACKAGE/receipt 2.139 + 2.140 + # Info #1: dependent packages (to be processed later) 2.141 + ALTERED="$(awk -F$'\t' -vp=" $PACKAGE " ' 2.142 + index(" " $8 " ", p) { printf " %s\n", $1 } 2.143 + ' $ROOT/$PKGS_DB/installed.info)" 2.144 + 2.145 if [ -n "$ALTERED" ]; then 2.146 _ 'The following packages depend on package "%s":' $PACKAGE 2.147 - for i in $ALTERED; do 2.148 - echo " $i" 2.149 - done 2.150 + echo "$ALTERED" 2.151 fi 2.152 + 2.153 + # Info #2: changed packages (to be processed later) 2.154 REFRESH=$(cd $ROOT$INSTALLED ; grep -sl ^$PACKAGE$ */modifiers) 2.155 + 2.156 if [ -n "$REFRESH" ]; then 2.157 _ 'The following packages have been modified by package "%s":' $PACKAGE 2.158 for i in $REFRESH; do 2.159 echo " ${i%/modifiers}" 2.160 done 2.161 fi 2.162 - if [ "$auto" ]; then 2.163 - answer=0 2.164 + 2.165 + # Confirmation 2.166 + if im && [ -z "$auto" ]; then 2.167 + confirm "$(_ 'Remove package "%s" (%s)? (y/N)' $PACKAGE $VERSION$EXTRAVERSION)" 2.168 + if [ $? != 0 ]; then 2.169 + newline; _ 'Uninstallation of package "%s" cancelled.' $PACKAGE 2.170 + exit 0 2.171 + fi 2.172 + fi 2.173 + # We are here: non-interactive mode, or --auto, or answer 'y' 2.174 + 2.175 + # Removing package 2.176 + title 'Removing package "%s"' $PACKAGE 2.177 + 2.178 + # [1/4] Pre-remove commands 2.179 + if grep -q ^pre_remove $ROOT$INSTALLED/$PACKAGE/receipt; then 2.180 + action "Execution of pre-remove commands..." 2.181 + pre_remove $ROOT 2.182 + status 2.183 + fi 2.184 + 2.185 + # [2/4] Removing files 2.186 + action "Removing all files installed..." 2.187 + if [ -f $ROOT$INSTALLED/$PACKAGE/modifiers ]; then 2.188 + for file in $(cat $ROOT$INSTALLED/$PACKAGE/files.list); do 2.189 + for mod in $(cat $ROOT$INSTALLED/$PACKAGE/modifiers); do 2.190 + [ -f $ROOT$INSTALLED/$mod/files.list ] && \ 2.191 + [ $(grep "^$(echo $file | grepesc)$" $ROOT$INSTALLED/$mod/files.list | wc -l) -gt 1 ] && \ 2.192 + continue 2 2.193 + done 2.194 + remove_with_path $ROOT$file 2.195 + done 2.196 else 2.197 - confirm "$(_ 'Remove package "%s" (%s)? (y/N)' $PACKAGE $VERSION$EXTRAVERSION)" 2.198 - answer=$? 2.199 + for file in $(cat $ROOT$INSTALLED/$PACKAGE/files.list); do 2.200 + remove_with_path $ROOT$file 2.201 + done 2.202 fi 2.203 - if [ $answer = 0 ]; then 2.204 - title 'Removing package "%s"' $PACKAGE 2.205 - # Pre remove commands. 2.206 - if grep -q ^pre_remove $ROOT$INSTALLED/$PACKAGE/receipt; then 2.207 - pre_remove $ROOT 2.208 + status 2.209 + 2.210 + # [3/4] Post-remove commands 2.211 + if grep -q ^post_remove $ROOT$INSTALLED/$PACKAGE/receipt; then 2.212 + action "Execution of post-remove commands..." 2.213 + post_remove $ROOT 2.214 + status 2.215 + fi 2.216 + 2.217 + # [4/4] Remove package receipt and remove it from databases 2.218 + action "Removing package receipt..." 2.219 + rm -rf $ROOT$INSTALLED/$PACKAGE 2.220 + sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION.tazpkg$/d" $PKGS_DB/installed.$SUM 2.221 + sed -i "/^$PACKAGE /d" $PKGS_DB/installed.info 2.222 + status 2.223 + 2.224 + footer "$(_ 'Package "%s" (%s) removed.' $PACKAGE $VERSION$EXTRAVERSION)" 2.225 + 2.226 + # Log this activity 2.227 + log_pkg Removed 2.228 + 2.229 + # Stop if non-interactive mode and no --auto option 2.230 + if ! im && [ -z "$auto" ]; then exit 0; fi 2.231 + 2.232 + # Process dependent packages 2.233 + if [ -n "$ALTERED" ]; then 2.234 + if [ "$auto" ]; then 2.235 + answer=0 2.236 + else 2.237 + confirm "$(_ 'Remove packages depending on package "%s"? (y/N)' $PACKAGE)" 2.238 + answer=$? 2.239 fi 2.240 - action "Removing all files installed..." 2.241 - if [ -f $ROOT$INSTALLED/$PACKAGE/modifiers ]; then 2.242 - for file in $(cat $ROOT$INSTALLED/$PACKAGE/files.list); do 2.243 - for mod in $(cat $ROOT$INSTALLED/$PACKAGE/modifiers); do 2.244 - [ -f $ROOT$INSTALLED/$mod/files.list ] && [ $(grep "^$(echo $file | grepesc)$" $ROOT$INSTALLED/$mod/files.list | wc -l) -gt 1 ] && continue 2 2.245 - done 2.246 - remove_with_path $ROOT$file 2.247 - done 2.248 - else 2.249 - for file in $(cat $ROOT$INSTALLED/$PACKAGE/files.list); do 2.250 - remove_with_path $ROOT$file 2.251 + if [ $answer = 0 ]; then 2.252 + for i in $ALTERED; do 2.253 + if [ -d "$ROOT$INSTALLED/$i" ]; then 2.254 + echo "tazpkg remove $i $ROOTOPTS" 2.255 + fi 2.256 done 2.257 fi 2.258 - status 2.259 - if grep -q ^post_remove $ROOT$INSTALLED/$PACKAGE/receipt; then 2.260 - post_remove $ROOT 2.261 + fi 2.262 + 2.263 + # Process changed packages 2.264 + if [ -n "$REFRESH" ]; then 2.265 + if [ "$auto" ]; then 2.266 + answer=0 2.267 + else 2.268 + confirm "$(_ 'Reinstall packages modified by package "%s"? (y/N)' $PACKAGE)" 2.269 + answer=$? 2.270 fi 2.271 - 2.272 - # Remove package receipt. 2.273 - action "Removing package receipt..." 2.274 - rm -rf $ROOT$INSTALLED/$PACKAGE 2.275 - status 2.276 - 2.277 - sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION$/d" \ 2.278 - $PKGS_DB/installed.$SUM 2> /dev/null 2.279 - 2.280 - # Update installed.info 2.281 - sed -i "/^$PACKAGE /d" $PKGS_DB/installed.info 2.282 - 2.283 - # Log this activity 2.284 - log_pkg Removed 2.285 - 2.286 - if [ "$ALTERED" ]; then 2.287 - if [ "$auto" ]; then 2.288 - answer=0 2.289 - else 2.290 - confirm "$(_ 'Remove packages depending on package "%s"? (y/N)' $PACKAGE)" 2.291 - answer=$? 2.292 - fi 2.293 - if [ $answer = 0 ]; then 2.294 - for i in $ALTERED; do 2.295 - if [ -d "$ROOT$INSTALLED/$i" ]; then 2.296 - tazpkg remove $i $ROOTOPTS 2.297 - fi 2.298 - done 2.299 - fi 2.300 + if [ $answer = 0 ]; then 2.301 + for i in $REFRESH; do 2.302 + if [ $(wc -l < $ROOT$INSTALLED/$i) -gt 1 ]; then 2.303 + _ 'Check %s for reinstallation' "$INSTALLED/$i" 2.304 + continue 2.305 + fi 2.306 + echo "rm -r $ROOT$INSTALLED/$i" 2.307 + echo "tazpkg get-install ${i%/modifiers} $ROOTOPTS --forced" 2.308 + done 2.309 fi 2.310 - if [ "$REFRESH" ]; then 2.311 - if [ "$auto" ]; then 2.312 - answer=0 2.313 - else 2.314 - confirm "$(_ 'Reinstall packages modified by package "%s"? (y/N)' $PACKAGE)" 2.315 - answer=$? 2.316 - fi 2.317 - if [ $answer = 0 ]; then 2.318 - for i in $REFRESH; do 2.319 - if [ $(wc -l < $ROOT$INSTALLED/$i) -gt 1 ]; then 2.320 - _ 'Check %s for reinstallation' "$INSTALLED/$i" 2.321 - continue 2.322 - fi 2.323 - rm -r $ROOT$INSTALLED/$i 2.324 - tazpkg get-install ${i%/modifiers} $ROOTOPTS --forced 2.325 - done 2.326 - fi 2.327 - fi 2.328 - else 2.329 - newline 2.330 - _ 'Uninstallation of package "%s" cancelled.' $PACKAGE 2.331 fi 2.332 - newline ;; 2.333 + 2.334 + ;; 2.335 2.336 2.337 extract|-e)