cookutils rev 474 slitaz-tank

cook: Update summary and extract_source function. Add getsrc, repack_source, download_base and download function.
author Christopher Rogers <slaxemulator@gmail.com>
date Sat Jun 09 08:46:33 2012 +0000 (2012-06-09)
parents 3d5d729aa6c5
children deff72d6ad0d
files cook
line diff
     1.1 --- a/cook	Fri Jun 08 18:06:35 2012 +0000
     1.2 +++ b/cook	Sat Jun 09 08:46:33 2012 +0000
     1.3 @@ -105,9 +105,7 @@
     1.4  				if_empty_value ;;
     1.5  			CATEGORY)
     1.6  				[ -z "$value" ] && value="empty"
     1.7 -				valid="base-system x-window utilities network graphics \
     1.8 -					multimedia office development system-tools security games \
     1.9 -					misc meta non-free"
    1.10 +				valid="$PKGS_CATEGORIES"
    1.11  				if ! echo "$valid" | grep -q -w "$value"; then
    1.12  					gettext "QA: unknown category:"; echo -e " $value\n"
    1.13  					exit 1
    1.14 @@ -267,15 +265,114 @@
    1.15  	done
    1.16  }
    1.17  
    1.18 +getsrc() {
    1.19 +	gettext "Getting source for:"; echo " $pkg"
    1.20 +	set_paths
    1.21 +	[ -f "$SRC/$lzma_tarball" ] && \
    1.22 +		TARBALL="$lzma_tarball"
    1.23 +	
    1.24 +	# Get source tarball and make sure we have source dir named:
    1.25 +	# $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
    1.26 +	# tarball if it exists.
    1.27 +	if [ ! "$WANTED" ] && [ "$TARBALL" ]; then
    1.28 +		[ -d $tmpsrc ] && rm -rf $tmpsrc
    1.29 +		mkdir -p $tmpsrc && cd $tmpsrc
    1.30 +	fi
    1.31 +	
    1.32 +	if [ "$WGET_URL" ] && [ -f "$SRC/$TARBALL" ]; then
    1.33 +		if [ "$1" = "--extract" ]; then
    1.34 +			[ -d $basesrc ] && rm -rf $basesrc
    1.35 +			mkdir -p $tmpsrc && cd $tmpsrc
    1.36 +			extract_source
    1.37 +			extract_path
    1.38 +		fi
    1.39 +		[ "$TARBALL" = "$lzma_tarball" ] && LZMA_SRC=""
    1.40 +	else
    1.41 +		separator && download
    1.42 +	fi
    1.43 +	
    1.44 +	# This is to make sure if PATCH equals something it will be downloaded
    1.45 +	# checks are done in download functions
    1.46 +	if [ "$PATCH" ]; then
    1.47 +		if [ ! -f "$SRC/$PTARBALL" ]; then
    1.48 +			separator && download
    1.49 +		fi
    1.50 +	fi
    1.51 +	
    1.52 +	look_for_cookopt !repack_src && LZMA_SRC=""
    1.53 +	if [ "$LZMA_SRC" ]; then
    1.54 +		echo -e "Repacking source."
    1.55 +		set_paths
    1.56 +		mkdir -p $tmpsrc && cd $tmpsrc
    1.57 +		extract_source || exit 1
    1.58 +		repack_source || exit 1
    1.59 +		if [ "$1" = "--extract" ]; then
    1.60 +			extract_path
    1.61 +		fi
    1.62 +		if [ -f $SRC/$TARBALL ]; then
    1.63 +			[ -d $tmpsrc ] && rm -rf $tmpsrc
    1.64 +		fi
    1.65 +	fi
    1.66 +	
    1.67 +	echo -e "Tarball: $SRC/$TARBALL"
    1.68 +	[ "$PATCH" ] && echo -e "Patch: $SRC/$PTARBALL"
    1.69 +}
    1.70 +
    1.71 +download_base() {
    1.72 +	local URLS url alt_url orig_url orig_url_patch
    1.73 +	url="$ONLINE_SRC_REPOSITORY"
    1.74 +	if [ "$SOURCE" ]; then
    1.75 +		alt_url="${url}${SOURCE:0:1}/$SOURCE-${KBASEVER:-$VERSION}.tar.lzma"
    1.76 +	else
    1.77 +		alt_url="${url}${PACKAGE:0:1}/$PACKAGE-${KBASEVER:-$VERSION}.tar.lzma"
    1.78 +	fi
    1.79 +	orig_url="${url}${TARBALL:0:1}/$TARBALL"
    1.80 +	[ "$PATCH" ] && orig_url_patch="${url}${PTARBALL:0:1}/$PTARBALL"
    1.81 +	URLS="$@ $alt_url $orig_url $orig_url_patch"
    1.82 +	[ "$LAN_MIRROR" ] && URLS="$alt_url $orig_url $orig_url_patch $@"
    1.83 +	if [ "$WGET_URL" = "$orig_url" ]; then
    1.84 +		[ "$TARBALL" = "$lzma_tarball" ] && LZMA_SRC=""
    1.85 +		get_source $@
    1.86 +	elif [ "$WGET_URL" = "$alt_url" ]; then
    1.87 +		LZMA_SRC=""
    1.88 +		get_source $@
    1.89 +	else
    1.90 +		for i in $URLS; do
    1.91 +			if [ "$1" = "$PATCH" ]; then
    1.92 +				[ ! -f "$SRC/$PTARBALL" ] || continue
    1.93 +			else
    1.94 +				[ ! -f "$SRC/$TARBALL" ] || continue
    1.95 +			fi
    1.96 +			case $i in 
    1.97 +				${url}*)
    1.98 +					[ "$i" = "$alt_url" ] && TARBALL="$(basename $alt_url)"
    1.99 +					[ "$i" = "$alt_url" ] && LZMA_SRC=""
   1.100 +					get_source $i 
   1.101 +					;;
   1.102 +				*)
   1.103 +					get_source $i ;;
   1.104 +			esac
   1.105 +		done
   1.106 +	fi
   1.107 +}
   1.108 +
   1.109 +# Get source from multible urls
   1.110 +download() {
   1.111 +	if [ ! -s "$SRC/$TARBALL" ]; then
   1.112 +		download_base $WGET_URL
   1.113 +		[ -f "$SRC/$TARBALL" ] || broken
   1.114 +	fi
   1.115 +	
   1.116 +	if [ "$PATCH" ]; then
   1.117 +		if [ ! -s "$SRC/$PTARBALL" ]; then
   1.118 +			download_base $PATCH
   1.119 +			[ -f "$SRC/$PTARBALL" ] || broken
   1.120 +		fi
   1.121 +	fi
   1.122 +}
   1.123 +
   1.124  # Extract source package.
   1.125  extract_source() {
   1.126 -	if [ ! -s "$SRC/$TARBALL" ]; then
   1.127 -		local url
   1.128 -		url="$MIRROR_URL/sources/packages"
   1.129 -		url=$url/${TARBALL:0:1}/$TARBALL
   1.130 -		gettext "Getting source from mirror:"; echo " $url"
   1.131 -		busybox wget -c -P $SRC $url || echo -e "ERROR: wget $url"
   1.132 -	fi
   1.133  	gettext "Extracting:"; echo " $TARBALL"
   1.134  	case "$TARBALL" in
   1.135  		*.tar.gz|*.tgz) tar xzf $SRC/$TARBALL 2>/dev/null ;;
   1.136 @@ -286,33 +383,74 @@
   1.137  		*.xz) unxz -c $SRC/$TARBALL | tar xf - ;;
   1.138  		*.Z) uncompress -c $SRC/$TARBALL | tar xf - ;;
   1.139  		*.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
   1.140 +		*.deb) ar vx $SRC/$TARBALL
   1.141 +				[ ! -d $tmpsrc/$PACKAGE-$VERSION ] && mkdir -p $tmpsrc/$PACKAGE-$VERSION
   1.142 +				cd $tmpsrc/$PACKAGE-$VERSION
   1.143 +				tar -xvzf $tmpsrc/data.tar.gz 
   1.144 +				[ -f $tmpsrc/data.tar.gz ] && rm -f $tmpsrc/data.tar.gz 
   1.145 +				[ -f $tmpsrc/control.tar.gz ] && rm -f $tmpsrc/control.tar.gz
   1.146 +				[ -f $tmpsrc/debian-binary ] && rm -f $tmpsrc/debian-binary ;;
   1.147  		*.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
   1.148 +		*.7z) 7zr x $SRC/$TARBALL ;;
   1.149  		*) cp $SRC/$TARBALL $(pwd) ;;
   1.150  	esac
   1.151  	chown -R 0.0 $(pwd)
   1.152  }
   1.153  
   1.154 +repack_source() {
   1.155 +	
   1.156 +	# Some archives are not well done and don't extract to one dir (ex lzma).
   1.157 +	files=$(ls | wc -l)
   1.158 +	[ "$files" == 1 ] && [ -d "$(ls)" ] && [ ! -d "$pkgsrc" ] && mv * $tmpsrc/$pkgsrc
   1.159 +	if [ ! -d "$tmpsrc/$pkgsrc" ]; then
   1.160 +		cd $basesrc
   1.161 +		if [ "$(ls -A tmp | wc -l)" -gt 1 ] || [ -f "$(echo tmp/*)" ]; then
   1.162 +			mv tmp tmp-1 && mkdir tmp
   1.163 +			mv tmp-1 tmp/$pkgsrc
   1.164 +		fi
   1.165 +	fi
   1.166 +	ORIG_TARBALL=$TARBALL
   1.167 +	if [ -d "$tmpsrc/$pkgsrc" ]; then
   1.168 +		gettext "Repacking source is enabled:"; echo " LZMA_SRC"
   1.169 +		TARBALL=$lzma_tarball
   1.170 +		cd $tmpsrc
   1.171 +		if [ -x /usr/bin/optipng ]; then
   1.172 +			[ "$SHRINKPNG" ] && find -name "*.png" -type f | xargs -i optipng "{}"
   1.173 +		fi
   1.174 +		tar -c * | lzma e $SRC/$TARBALL -si $LZMA_SET_DIR
   1.175 +		if [ $REMOVE_ORIG_TARBALL ]; then
   1.176 +			if [ -f $SRC/$TARBALL ]; then
   1.177 +				[ -f $SRC/$ORIG_TARBALL ] && rm -f $SRC/$ORIG_TARBALL
   1.178 +			fi
   1.179 +		fi
   1.180 +	fi
   1.181 +}
   1.182 +
   1.183  # Display cooked package summary.
   1.184  summary() {
   1.185  	cd $WOK/$pkg
   1.186 -	[ -d install ] && prod=$(du -sh install | awk '{print $1}' 2>/dev/null)
   1.187 -	fs=$(du -sh taz/* | awk '{print $1}')
   1.188 -	size=$(du -sh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $1}')
   1.189 -	files=$(cat taz/$pkg-*/files.list | wc -l)
   1.190 +	[ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
   1.191 +	fs=$(du -sh $WOK/$pkg/taz/* | awk '{print $1}')
   1.192 +	size=$(du -sh $INCOMING/$pkg-${VERSION}*.tazpkg | awk '{print $1}')
   1.193 +	files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
   1.194 +	[ "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
   1.195  	cookdate=$(date "+%Y-%m-%d %H:%M")
   1.196  	sec=$time
   1.197  	div=$(( ($time + 30) / 60))
   1.198  	[ "$div" != 0 ] && min="~ ${div}m"
   1.199  	gettext "Summary for:"; echo " $PACKAGE $VERSION"
   1.200  	separator
   1.201 +	[ "$srcdir" ] && echo "Source dir  : $srcdir"
   1.202 +	[ "$TARBALL" ] && echo "Src file    : $TARBALL"
   1.203 +	[ "$srcsize" ] && echo "Src size    : $srcsize"
   1.204  	[ "$prod" ] && echo "Produced   : $prod"
   1.205  	cat << EOT
   1.206 -Packed     : $fs
   1.207 -Compressed : $size
   1.208 -Files      : $files
   1.209 -Cook time  : ${sec}s $min
   1.210 -Cook date  : $cookdate
   1.211 -Host arch  : $ARCH
   1.212 +Packed      : $fs
   1.213 +Compressed  : $size
   1.214 +Files       : $files
   1.215 +Cook time   : ${sec}s $min
   1.216 +Cook date   : $cookdate
   1.217 +Host arch   : $ARCH
   1.218  $(separator)
   1.219  EOT
   1.220  }
   1.221 @@ -1046,7 +1184,7 @@
   1.222  			echo -e "\n" && exit 1
   1.223  		fi
   1.224  		gettext "Creating"; echo -n " $WOK/$pkg"
   1.225 -		mkdir $WOK/$pkg && cd $WOK/$pkg && status
   1.226 +		mkdir -p $WOK/$pkg && cd $WOK/$pkg && status
   1.227  		gettext "Preparing the package receipt..."
   1.228  		cp $DATA/receipt .
   1.229  		sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
   1.230 @@ -1086,7 +1224,7 @@
   1.231  				echo -n "Do you need a stuff directory ? (y/N) : " ; read anser
   1.232  				if [ "$anser" = "y" ]; then
   1.233  					echo -n "Creating the stuff directory..."
   1.234 -					mkdir $WOK/$pkg/stuff && status
   1.235 +					mkdir -p $WOK/$pkg/stuff && status
   1.236  				fi
   1.237  				# Ask for a description file.
   1.238  				echo -n "Are you going to write a description ? (y/N) : " ; read anser