cookutils rev 931

cook, cooker: save all the cats ;) and make seds not so 'sed.'
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Jun 16 16:40:34 2017 +0300 (2017-06-16)
parents 5f0da70605b6
children 9a70c8fdc40c
files cook cooker
line diff
     1.1 --- a/cook	Fri Jun 16 01:10:16 2017 +0300
     1.2 +++ b/cook	Fri Jun 16 16:40:34 2017 +0300
     1.3 @@ -72,8 +72,8 @@
     1.4  # We don't want these escapes in web interface.
     1.5  
     1.6  clean_log() {
     1.7 -	sed -i -e s'|\[70G\[ \[1;32m| |' \
     1.8 -		-e s'|\[0;39m \]||' $LOGS/${1:-$pkg}.log
     1.9 +	sed -i -e 's|\[70G\[ \[1;32m| |' \
    1.10 +		-e 's|\[0;39m \]||' $LOGS/${1:-$pkg}.log
    1.11  }
    1.12  
    1.13  
    1.14 @@ -507,7 +507,7 @@
    1.15  	cd $CACHE
    1.16  	[ "$1" == 'force' -o ! -s '/tmp/installed.cook.diff' ] && \
    1.17  		busybox diff installed.list installed.cook > /tmp/installed.cook.diff
    1.18 -	deps=$(cat /tmp/installed.cook.diff | grep ^+[a-zA-Z0-9] | wc -l)
    1.19 +	deps=$(grep ^+[a-zA-Z0-9] /tmp/installed.cook.diff | wc -l)
    1.20  }
    1.21  
    1.22  
    1.23 @@ -518,8 +518,8 @@
    1.24  	diff='/tmp/installed.cook.diff'
    1.25  	[ -s "$diff" ] || return
    1.26  
    1.27 -	deps=$(cat $diff | grep ^+[a-zA-Z0-9] | sed s/^+//)
    1.28 -	nb=$(cat $diff | grep ^+[a-zA-Z0-9] | wc -l)
    1.29 +	deps=$(grep ^+[a-zA-Z0-9] $diff | sed 's|^+||')
    1.30 +	nb=$(grep ^+[a-zA-Z0-9] $diff | wc -l)
    1.31  	newline
    1.32  	_n 'Build dependencies to remove:'; echo " $nb"
    1.33  	[ -n "$root" ] && echo "root=\"$root\""
    1.34 @@ -977,7 +977,7 @@
    1.35  	cd $fs
    1.36  	find . -type f -print > ../files.list
    1.37  	find . -type l -print >> ../files.list
    1.38 -	cd ..; sed -i s/'^.'/''/ files.list
    1.39 +	cd ..; sed -i 's|^.||' files.list
    1.40  	status
    1.41  
    1.42  	# Md5sum of files.
    1.43 @@ -988,7 +988,7 @@
    1.44  		case "$file" in
    1.45  			/lib/modules/*/modules.*|*.pyc) continue ;;
    1.46  		esac
    1.47 -		md5sum "fs$file" | sed 's/  fs/  /'
    1.48 +		md5sum "fs$file" | sed 's|  fs|  |'
    1.49  	done < files.list > md5sum
    1.50  	status
    1.51  
    1.52 @@ -1006,16 +1006,15 @@
    1.53  		2>/dev/null | awk 'END{ print $1 }')
    1.54  
    1.55  	action 'Updating receipt sizes...'
    1.56 -	sed -i s/^PACKED_SIZE.*$// receipt
    1.57 -	sed -i s/^UNPACKED_SIZE.*$// receipt
    1.58 -	sed -i "s/^PACKAGE=/PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=/" receipt
    1.59 +	sed -i '/^PACKED_SIZE=/d; /^UNPACKED_SIZE=/d' receipt
    1.60 +	sed -i "s|^PACKAGE=|PACKED_SIZE=\"$PACKED_SIZE\"\nUNPACKED_SIZE=\"$UNPACKED_SIZE\"\nPACKAGE=|" receipt
    1.61  	status
    1.62  
    1.63  	# Set extra version.
    1.64  	if [ -n "$EXTRAVERSION" ]; then
    1.65  		action 'Updating receipt EXTRAVERSION: %s' "$EXTRAVERSION"
    1.66 -		sed -i s/^EXTRAVERSION.*$// receipt
    1.67 -		sed -i "s/^VERSION=/EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=/" receipt
    1.68 +		sed -i '/^EXTRAVERSION=/d' receipt
    1.69 +		sed -i "s|^VERSION=|EXTRAVERSION=\"$EXTRAVERSION\"\nVERSION=|" receipt
    1.70  		status
    1.71  	fi
    1.72  
    1.73 @@ -1078,7 +1077,7 @@
    1.74  	done
    1.75  	rm -r "$tempd"
    1.76  	mv -f $pkgdir/taz/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg $PKGS
    1.77 -	sed -i /^${pkg}$/d $broken
    1.78 +	sed -i "/^${pkg}$/d" $broken
    1.79  	#action 'Removing source tree...'
    1.80  	#rm -f $WOK/$pkg/source; status
    1.81  }
    1.82 @@ -1453,7 +1452,7 @@
    1.83  		cat $activity ;;
    1.84  
    1.85  	search)
    1.86 -		# Just a simple search function, we dont need more actually.
    1.87 +		# Just a simple search function, we don't need more actually.
    1.88  		query="$2"
    1.89  		title 'Search results for "%s"' "$query"
    1.90  		cd $WOK; ls -1 | grep "$query"
    1.91 @@ -1519,9 +1518,9 @@
    1.92  		title 'Setting up your %s cross environment' "$arch"
    1.93  		init_db_files
    1.94  		sed -i \
    1.95 -			-e s"/ARCH=.*/ARCH=\"$arch\"/" \
    1.96 -			-e s"/CROSS_TREE=.*/CROSS_TREE=\"\/cross\/$arch\"/" \
    1.97 -			-e s'/BUILD_SYSTEM=.*/BUILD_SYSTEM=i486-slitaz-linux/' \
    1.98 +			-e "s|ARCH=.*|ARCH=\"$arch\"|" \
    1.99 +			-e "s|CROSS_TREE=.*|CROSS_TREE=\"/cross/$arch\"|" \
   1.100 +			-e 's|BUILD_SYSTEM=.*|BUILD_SYSTEM=i486-slitaz-linux|' \
   1.101  			/etc/slitaz/cook.conf
   1.102  		case "$arch" in
   1.103  			arm)
   1.104 @@ -1538,8 +1537,8 @@
   1.105  				host="$ARCH-slitaz-linux" ;;
   1.106  		esac
   1.107  		sed -i \
   1.108 -			-e s"/CFLAGS=.*/CFLAGS=\"$flags\"/" \
   1.109 -			-e s"/HOST_SYSTEM=.*/HOST_SYSTEM=$host/" /etc/slitaz/cook.conf
   1.110 +			-e "s|CFLAGS=.*|CFLAGS=\"$flags\"|" \
   1.111 +			-e "s|HOST_SYSTEM=.*|HOST_SYSTEM=$host|" /etc/slitaz/cook.conf
   1.112  		. /etc/slitaz/cook.conf
   1.113  		sysroot="$CROSS_TREE/sysroot"
   1.114  		tools="/cross/$arch/tools"
   1.115 @@ -1592,7 +1591,7 @@
   1.116  
   1.117  		action 'Preparing the package receipt...'
   1.118  		cp $DATA/receipt .
   1.119 -		sed -i s"/^PACKAGE=.*/PACKAGE=\"$pkg\"/" receipt
   1.120 +		sed -i "s|^PACKAGE=.*|PACKAGE=\"$pkg\"|" receipt
   1.121  		status; newline
   1.122  
   1.123  		# Interactive mode, asking and seding.
   1.124 @@ -1603,30 +1602,30 @@
   1.125  				_  'Package       : %s' "$pkg"
   1.126  
   1.127  				_n 'Version       : ' ; read answer
   1.128 -				sed -i s/'VERSION=\"\"'/"VERSION=\"$answer\""/ receipt
   1.129 +				sed -i "s|^VERSION=.*|VERSION=\"$answer\"|" receipt
   1.130  
   1.131  				_n 'Category      : ' ; read answer
   1.132 -				sed -i s/'CATEGORY=\"\"'/"CATEGORY=\"$answer\""/ receipt
   1.133 +				sed -i "s|^CATEGORY=.*|CATEGORY=\"$answer\"|" receipt
   1.134  
   1.135  				# L10n: Short description
   1.136  				_n 'Short desc    : ' ; read answer
   1.137 -				sed -i s/'SHORT_DESC=\"\"'/"SHORT_DESC=\"$answer\""/ receipt
   1.138 +				sed -i "s|^SHORT_DESC=.*|SHORT_DESC=\"$answer\"|" receipt
   1.139  
   1.140  				_n 'Maintainer    : ' ; read answer
   1.141 -				sed -i s/'MAINTAINER=\"\"'/"MAINTAINER=\"$answer\""/ receipt
   1.142 +				sed -i "s|^MAINTAINER=.*|MAINTAINER=\"$answer\"|" receipt
   1.143  
   1.144  				_n 'License       : ' ; read answer
   1.145 -				sed -i s/'LICENSE=\"\"'/"LICENSE=\"$answer\""/ receipt
   1.146 +				sed -i "s|^LICENSE=.*|LICENSE=\"$answer\"|" receipt
   1.147  
   1.148  				_n 'Web site      : ' ; read answer
   1.149 -				sed -i s#'WEB_SITE=\"\"'#"WEB_SITE=\"$answer\""# receipt
   1.150 +				sed -i "s|^WEB_SITE=.*|WEB_SITE=\"$answer\"|" receipt
   1.151  				newline
   1.152  
   1.153  				# Wget URL.
   1.154  				_ 'Wget URL to download source tarball.'
   1.155  				_n 'Example  : ' ; echo '$GNU_MIRROR/$PACKAGE/$TARBALL'
   1.156  				_n 'Wget url : ' ; read answer
   1.157 -				sed -i "s|WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
   1.158 +				sed -i "s|^WGET_URL=.*|WGET_URL=\"$answer\"|" receipt
   1.159  
   1.160  				# Ask for a stuff dir.
   1.161  				confirm "$(_n 'Do you need a stuff directory? (y/N)')"
   1.162 @@ -1654,9 +1653,10 @@
   1.163  
   1.164  		_ 'Starting cooking the list "%s"' "$2" | log
   1.165  
   1.166 -		for pkg in $(cat $2); do
   1.167 +		while read pkg; do
   1.168  			cook $pkg || broken
   1.169 -		done ;;
   1.170 +		done < $2
   1.171 +		;;
   1.172  
   1.173  	clean-wok)
   1.174  		check_root
   1.175 @@ -1765,7 +1765,7 @@
   1.176  			_ 'cook: %s' "error"
   1.177  			[ -n "$CROSS_BUGS" ] && _ 'bugs: %s' "$CROSS_BUGS"
   1.178  			_ 'Cook skip: %s' "$error" | log
   1.179 -			sed -i /^${pkg}$/d $broken
   1.180 +			sed -i "/^${pkg}$/d" $broken
   1.181  			newline
   1.182  			exit 0
   1.183  		fi
   1.184 @@ -1817,7 +1817,7 @@
   1.185  
   1.186  			--unblock|-ub)
   1.187  				action 'Unblocking package "%s"' "$pkg"
   1.188 -				sed -i "/^${pkg}$/"d $blocked
   1.189 +				sed -i "/^${pkg}$/d" $blocked
   1.190  				status; newline
   1.191  				exit 0 ;;
   1.192  
     2.1 --- a/cooker	Fri Jun 16 01:10:16 2017 +0300
     2.2 +++ b/cooker	Fri Jun 16 16:40:34 2017 +0300
     2.3 @@ -50,7 +50,7 @@
     2.4  # into a log file.
     2.5  
     2.6  log_commits() {
     2.7 -	sed '/^.\//'d | sed '/^.hg/'d | tee -a $LOGS/commits.log
     2.8 +	sed '/^.\//d' | sed '/^.hg/d' | tee -a $LOGS/commits.log
     2.9  }
    2.10  
    2.11  
    2.12 @@ -84,7 +84,7 @@
    2.13  cook_order_scan() {
    2.14  	rm -f $cookorder
    2.15  	touch $cookorder
    2.16 -	for pkg in $(cat $cooklist); do
    2.17 +	while read pkg; do
    2.18  		unset WANTED BUILD_DEPENDS
    2.19  		. $wok/$pkg/receipt
    2.20  		# The :: is for web interface color.
    2.21 @@ -96,14 +96,14 @@
    2.22  				fi
    2.23  			fi
    2.24  		done
    2.25 -	done
    2.26 +	done < $cooklist
    2.27  
    2.28  	# Append unordered packages to cookorder.
    2.29 -	for pkg in $(cat $cooklist); do
    2.30 +	while read pkg; do
    2.31  		if ! grep -q "^$pkg$" $cookorder; then
    2.32  			echo "$pkg" >> $cookorder
    2.33  		fi
    2.34 -	done
    2.35 +	done < $cooklist
    2.36  }
    2.37  
    2.38  
    2.39 @@ -143,17 +143,17 @@
    2.40  	# TODO: grep the line number to get pkg position and keep it higher.
    2.41  	echo -e '\nHandle WANTED package'
    2.42  	separator
    2.43 -	for pkg in $(cat $cooklist); do
    2.44 +	while read pkg; do
    2.45  		unset WANTED
    2.46  		. $wok/$pkg/receipt
    2.47  		for wanted in $WANTED; do
    2.48  			echo "$pkg :: $wanted"
    2.49  			if grep -q ^${wanted}$ $cooklist; then
    2.50 -				sed -i -e "/^$pkg$/"d  \
    2.51 +				sed -i -e "/^$pkg$/d" \
    2.52  					-e "/^$wanted$/ a $pkg" $cooklist
    2.53  			fi
    2.54  		done
    2.55 -	done
    2.56 +	done < $cooklist
    2.57  
    2.58  	# Show ordered cooklist
    2.59  	echo -e '\nCooklist order'
    2.60 @@ -162,7 +162,7 @@
    2.61  	separator
    2.62  
    2.63  	time=$(($(date +%s) - $time))
    2.64 -	pkgs=$(cat $cooklist | wc -l)
    2.65 +	pkgs=$(wc -l < $cooklist)
    2.66  	echo -e '\nSummary for cookorder'
    2.67  	separator
    2.68  	cat <<EOT
    2.69 @@ -179,10 +179,10 @@
    2.70  # Remove blocked (faster this way than grepping before).
    2.71  
    2.72  strip_blocked() {
    2.73 -	for pkg in $(cat $blocked); do
    2.74 -		sed -i /^${pkg}$/d $cooklist
    2.75 -	done
    2.76 -	sed -i /^$/d $cooklist
    2.77 +	while read pkg; do
    2.78 +		sed -i "/^${pkg}$/d" $cooklist
    2.79 +	done < $blocked
    2.80 +	sed -i '/^$/d' $cooklist
    2.81  }
    2.82  
    2.83  
    2.84 @@ -190,12 +190,12 @@
    2.85  
    2.86  cook_commits() {
    2.87  	if [ -s "$commits" ]; then
    2.88 -		for pkg in $(cat $commits); do
    2.89 +		while read pkg; do
    2.90  			ps | grep -q "cook $pkg$" && continue
    2.91  			echo "cook:$pkg" > $command
    2.92  			cook $pkg || broken
    2.93 -			sed -i /^${pkg}$/d $commits
    2.94 -		done
    2.95 +			sed -i "/^${pkg}$/d" $commits
    2.96 +		done < $commits
    2.97  	fi
    2.98  }
    2.99  
   2.100 @@ -203,19 +203,19 @@
   2.101  # Cook all packages in a cooklist.
   2.102  
   2.103  cook_list() {
   2.104 -	for pkg in $(cat $cooklist); do
   2.105 +	while read pkg; do
   2.106  		ps | grep -q "cook $pkg$" && continue
   2.107  		cook $pkg || broken
   2.108 -		sed -i /^${pkg}$/d $cooklist
   2.109 -	done
   2.110 +		sed -i "/^${pkg}$/d" $cooklist
   2.111 +	done < $cooklist
   2.112  }
   2.113  
   2.114  
   2.115  # Create a arch.$ARCH file for each package cooked for the target host
   2.116  # architecture
   2.117  #
   2.118 -# The deal: we dont want all packages handled by cooker commands and stats,
   2.119 -# since we dont cross compile all packages for each arch but only a set of
   2.120 +# The deal: we don't want all packages handled by cooker commands and stats,
   2.121 +# since we don't cross compile all packages for each arch but only a set of
   2.122  # packages to provide one full featured desktop, servers and goodies useful
   2.123  # for the host system.
   2.124  #
   2.125 @@ -299,7 +299,7 @@
   2.126  			mkdir -p /var/spool/cron/crontabs
   2.127  		fi
   2.128  		if ! fgrep -q /usr/bin/cooker $crontabs; then
   2.129 -			cat > $crontabs << EOT
   2.130 +			cat > $crontabs <<EOT
   2.131  # Run SliTaz Cooker every $hours hours
   2.132  59 */$hours * * *  touch $CACHE/cooker-request
   2.133  */5 * * * *  [ $CACHE/cooker-request -nt $CACHE/activity ] && /usr/bin/cooker --output=html
   2.134 @@ -359,7 +359,7 @@
   2.135  			fi
   2.136  		done
   2.137  		separator
   2.138 -		echo -e "Reverse dependencies found: $(cat $cooklist | wc -l)\n"
   2.139 +		echo -e "Reverse dependencies found: $(wc -l < $cooklist)\n"
   2.140  		strip_blocked
   2.141  		cook_order | tee $LOGS/cookorder.log
   2.142  		cook_list ;;
   2.143 @@ -453,7 +453,7 @@
   2.144  		done
   2.145  		strip_blocked
   2.146  		cook_order | tee $LOGS/cookorder.log
   2.147 -		echo "Packages to cook: $(cat $cooklist | wc -l)" | log
   2.148 +		echo "Packages to cook: $(wc -l < $cooklist)" | log
   2.149  		cook_list ;;
   2.150  
   2.151  	*)
   2.152 @@ -502,7 +502,7 @@
   2.153  			echo "Changes found from: $cur to $new" | log
   2.154  			echo 'Syncing build wok with Hg wok...' | log_commits
   2.155  			rsync -r -t -c -l -u -v -D -E $wok-hg/ $wok/ | \
   2.156 -				sed '/^$/'d | log_commits
   2.157 +				sed '/^$/d' | log_commits
   2.158  		else
   2.159  			echo "No revision changes: $cur vs $new" | log
   2.160  			separator | log_commits
   2.161 @@ -535,7 +535,7 @@
   2.162  					rm -f $PKGS/$PACKAGE-$VERSION*
   2.163  				fi
   2.164  				rm -rf $wok/$pkg $LOGS/$pkg.log
   2.165 -				sed -i "/^${pkg}$/"d $blocked $broken $commits.tmp
   2.166 +				sed -i "/^${pkg}$/d" $blocked $broken $commits.tmp
   2.167  			fi
   2.168  			if [ -d "$wok/$pkg/stuff" ]; then
   2.169  				if [ ! -d "$wok-hg/$pkg/stuff" ]; then
   2.170 @@ -555,24 +555,24 @@
   2.171  		done
   2.172  
   2.173  		# Keep previous commit and discard duplicate lines
   2.174 -		cat $commits $commits.tmp | sed /"^$"/d > $commits.new
   2.175 +		cat $commits $commits.tmp | sed '/^$/d' > $commits.new
   2.176  		uniq $commits.new > $commits; rm $commits.*
   2.177  
   2.178  		# Handle cross compilation. Create arch packages DB and remove pkgs
   2.179  		# not cooked for this arch from the commits list.
   2.180  		arch_db
   2.181 -		for pkg in $(cat $commits); do
   2.182 +		while read pkg; do
   2.183  			if [ ! -f "$wok/$pkg/arch.$ARCH" ]; then
   2.184  				echo "Cooker arch : skip $pkg (not included in: $ARCH)" | \
   2.185  					log_commits
   2.186 -				sed -i "/^${pkg}$/"d $commits
   2.187 +				sed -i "/^${pkg}$/d" $commits
   2.188  			else
   2.189  				echo "Cooker arch : $ARCH" | log_commits
   2.190  			fi
   2.191 -		done
   2.192 +		done < $commits
   2.193  
   2.194  		# Stats
   2.195 -		pkgs=$(cat $commits | wc -l)
   2.196 +		pkgs=$(wc -l < $commits)
   2.197  		echo "Packages to cook: $pkgs" | log
   2.198  		echo "Packages to cook : $pkgs" | log_commits
   2.199  		separator | log_commits