spk rev 23
spk-add: we want usage() and come empty line clean-up
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Tue May 15 16:59:57 2012 +0200 (2012-05-15) |
parents | c067cf3860e1 |
children | 2eefb6700d4b |
files | spk-add |
line diff
1.1 --- a/spk-add Tue May 15 16:54:28 2012 +0200 1.2 +++ b/spk-add Tue May 15 16:59:57 2012 +0200 1.3 @@ -1,26 +1,52 @@ 1.4 #!/bin/sh 1.5 # 1.6 -# Authors : See the AUTHORS files 1.7 +# Spk-add - Install SliTaz packages. Read the README before adding or 1.8 +# modifing any code in spk! 1.9 +# 1.10 +# Copyright (C) SliTaz GNU/Linux - BSD License 1.11 +# Author: See AUTHORS files 1.12 +# 1.13 +. /usr/lib/slitaz/libspk.sh 1.14 1.15 # Set to / for now until we add installing to chroot support 1.16 # Could we update tools so they do not need this? 1.17 ROOT="" 1.18 TMP_DIR="/tmp/$RANDOM" 1.19 1.20 -source /usr/lib/slitaz/libspk.sh 1.21 +# 1.22 +# Functions 1.23 +# 1.24 + 1.25 +# Help and usage 1.26 +usage() { 1.27 + name=$(basename $0) 1.28 + cat << EOT 1.29 + 1.30 +$(boldify $(gettext "Usage:")) $name [packages|--options] 1.31 + 1.32 +$(gettext "Install SliTaz Packages") 1.33 + 1.34 +$(boldify $(gettext "Options:")) 1.35 + 1.36 +$(boldify $(gettext "Examples:")) 1.37 + $name package1 package2 packageN 1.38 + 1.39 +EOT 1.40 + exit 0 1.41 +} 1.42 1.43 # This function installs a package in the rootfs. 1.44 # Parameters: package_name package_file 1.45 -install_package() { 1.46 +install_package() { 1.47 local package_file=$1 1.48 - 1.49 + 1.50 # Set by receipt: pre_depends() DEPENDS SELF_INSTALL CONFIG_FILES post_install() 1.51 - 1.52 + 1.53 # Create package path early to avoid dependencies loop 1.54 mkdir -p $TMP_DIR 1.55 extract_receipt $TMP_DIR $package_file 1.56 source $TMP_DIR/receipt 1.57 - 1.58 + 1.59 local package_name=$PACKAGE 1.60 local package_dir="$installed/$package_name" 1.61 mkdir -p $package_dir 1.62 @@ -39,25 +65,25 @@ 1.63 pushd $(dirname $package_file) > /dev/null 1.64 $CHECKSUM $(basename $package_file) >> $pkgsmd5 1.65 popd > /dev/null 1.66 - 1.67 + 1.68 # Resolve package deps. 1.69 if missing_deps $package_name $DEPENDS; then 1.70 install_deps $package_name $DEPENDS 1.71 fi 1.72 - 1.73 - newline 1.74 + 1.75 + newline 1.76 boldify $(gettext "Installation of :") $package_name 1.77 separator 1.78 eval_gettext "Copying \$package_name... " 1.79 cp $package_file $TMP_DIR 1.80 status 1.81 - 1.82 + 1.83 # Extract Package 1.84 pushd $TMP_DIR > /dev/null 1.85 rm receipt 1.86 spk-archive extract $package_file 1.87 popd > /dev/null 1.88 - 1.89 + 1.90 # Get files to remove if upgrading 1.91 local files_to_remove 1.92 if [ -f $package_dir/files.list ]; then 1.93 @@ -71,7 +97,7 @@ 1.94 files_to_remove="$files_to_remove $file" 1.95 done 1.96 fi 1.97 - 1.98 + 1.99 local check=false 1.100 local file_list 1.101 # Create list of all possibly modified files 1.102 @@ -81,13 +107,13 @@ 1.103 file_list="$file_list $i" 1.104 check=true 1.105 done 1.106 - 1.107 + 1.108 # Check possibly modified files against other packages file.list 1.109 if $check; then 1.110 - for pkg in $INSTALLED/*; do 1.111 + for pkg in $INSTALLED/*; do 1.112 [ "$pkg" == "$package_name" ] && continue 1.113 [ -s $pkg/files.list ] || continue 1.114 - 1.115 + 1.116 for file in $file_list; do 1.117 # $package_name wants to install $file which is already 1.118 # Installed from $pkg 1.119 @@ -103,30 +129,30 @@ 1.120 done 1.121 done 1.122 fi 1.123 - 1.124 + 1.125 pushd $TMP_DIR > /dev/null 1.126 cp receipt files.list $package_dir 1.127 # Copy the description if found. 1.128 [ -f "description.txt" ] && cp description.txt $package_dir 1.129 - 1.130 + 1.131 # Pre install commands. 1.132 if grep -q ^pre_install $package_dir/receipt; then 1.133 pre_install $ROOT 1.134 fi 1.135 - 1.136 + 1.137 # Handle Config Files from receipt 1.138 if [ -n "$CONFIG_FILES" ]; then 1.139 pushd $fs > /dev/null 1.140 # save 'official' configuration files 1.141 eval_gettext "Saving configuration files for \$package_name... " 1.142 - 1.143 + 1.144 local confs 1.145 for i in $CONFIG_FILES; do 1.146 confs="$confs $(find ${i#/} -type f 2> /dev/null)" 1.147 done 1.148 - 1.149 + 1.150 echo $confs | cpio -o -H newc --quiet | gzip -9 > $package_dir/volatile.cpio.gz 1.151 - 1.152 + 1.153 # keep user configuration files 1.154 for conf_file in $confs; do 1.155 [ -e $conf_file ] || continue 1.156 @@ -135,12 +161,12 @@ 1.157 status 1.158 popd > /dev/null 1.159 fi 1.160 - 1.161 + 1.162 # Merge ROOT_FS with Package FS 1.163 eval_gettext "Installing \$package_name... " 1.164 cp -a fs/* $ROOT/ 1.165 status 1.166 - 1.167 + 1.168 # Remove old config files 1.169 if [ -n $files_to_remove ]; then 1.170 eval_gettext "Removing old \$package_name... " 1.171 @@ -150,17 +176,17 @@ 1.172 status 1.173 fi 1.174 popd > /dev/null 1.175 - 1.176 + 1.177 # Remove the temporary directory. 1.178 gettext "Removing all tmp files... " 1.179 rm -rf $TMP_DIR 1.180 status 1.181 - 1.182 + 1.183 # Post install commands. 1.184 if grep -q ^post_install $package_dir/receipt; then 1.185 post_install $ROOT 1.186 fi 1.187 - 1.188 + 1.189 # Update-desktop-database if needed. 1.190 if [ "$(fgrep .desktop $package_dir/files.list | fgrep /usr/share/applications/)" ]; then 1.191 updatedesktopdb=yes 1.192 @@ -181,7 +207,7 @@ 1.193 if [ "$(fgrep /lib/modules $package_dir/files.list)" ]; then 1.194 updatedepmod=yes 1.195 fi 1.196 - 1.197 + 1.198 separator 1.199 eval_gettext "\$package_name (\$VERSION\$EXTRAVERSION) is installed."; newline 1.200 newline 1.201 @@ -192,20 +218,20 @@ 1.202 # Parameters: package_file 1.203 install_pkg() { 1.204 package_file="$1" 1.205 - 1.206 + 1.207 check_root 1.208 check_valid_tazpkg $package_file 1.209 - 1.210 + 1.211 # Check if forced install. 1.212 if ! [ "$forced" ]; then 1.213 check_for_installed_package $(package_name $package_file) 1.214 fi 1.215 - 1.216 + 1.217 install_package $package_file 1.218 - 1.219 + 1.220 update_desktop_database 1.221 update_mime_database 1.222 - update_icon_database 1.223 + update_icon_database 1.224 compile_glib_schemas 1.225 } 1.226 1.227 @@ -215,7 +241,7 @@ 1.228 local package_name="$1" 1.229 1.230 check_root 1.231 - 1.232 + 1.233 # Check if get-Package 1.234 if ! is_package_mirrored $package_name; then 1.235 package_name="get-$package_name" 1.236 @@ -230,12 +256,12 @@ 1.237 1.238 # package_full=Package-Version 1.239 local package_full=$(full_package $package_name) 1.240 - 1.241 + 1.242 # Check if forced install. 1.243 if ! [ "$forced" ]; then 1.244 check_for_installed_package $package_name 1.245 fi 1.246 - 1.247 + 1.248 pushd $CACHE_DIR > /dev/null 1.249 if [ -f "$package_full.tazpkg" ]; then 1.250 eval_gettext "\$package_full is already in the cache : \$CACHE_DIR"; newline 1.251 @@ -244,26 +270,26 @@ 1.252 eval_gettext "Continuing \$package_name download"; newline 1.253 download "$package_full.tazpkg" 1.254 fi 1.255 - 1.256 + 1.257 # Check that the package has the correct checksum 1.258 # if [ "$($CHECKSUM $package_full.tazpkg)" != "$(fgrep \" $package_full.tazpkg\" $pkgsmd5)" ]; then 1.259 # rm -f $package.tazpkg 1.260 # download "$package_full.tazpkg" 1.261 # fi 1.262 else 1.263 - newline 1.264 + newline 1.265 download "$package_full.tazpkg" 1.266 fi 1.267 popd > /dev/null 1.268 - 1.269 + 1.270 install_package "$CACHE_DIR/$package_full.tazpkg" 1.271 - 1.272 - [ -n "$AUTOEXEC" ] && $package_name $ROOT 1.273 + 1.274 + [ -n "$AUTOEXEC" ] && $package_name $ROOT 1.275 update_desktop_database 1.276 update_mime_database 1.277 } 1.278 1.279 -# Install all missing deps. Auto install or ask user then install all missing 1.280 +# Install all missing deps. Auto install or ask user then install all missing 1.281 # deps from local dir, cdrom, media or from the mirror. In case we want to 1.282 # install packages from local, we need a packages.list to find the version. 1.283 # Parameters: package List of deps to install 1.284 @@ -271,9 +297,9 @@ 1.285 local package=$1 1.286 shift 1.287 local deps="$@" 1.288 - 1.289 + 1.290 gettext "Install all missing dependencies? " 1.291 - 1.292 + 1.293 # Print Yes/No and get result 1.294 if $AUTO_INSTALL_DEPS || confirm; then 1.295 for pkgorg in $deps; do