cookutils rev 890

Small edits. Move rare code from cook -> modules/cdeps.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Mar 17 00:44:10 2017 +0200 (2017-03-17)
parents cc30efdee934
children 080dd0a18d2e
files cook modules/cdeps modules/pkgdb modules/qa
line diff
     1.1 --- a/cook	Wed Mar 08 22:52:08 2017 +0100
     1.2 +++ b/cook	Fri Mar 17 00:44:10 2017 +0200
     1.3 @@ -80,19 +80,13 @@
     1.4  # Be sure package exists in wok.
     1.5  
     1.6  check_pkg_in_wok() {
     1.7 -	if [ ! -d "$WOK/$pkg" ]; then
     1.8 -		newline; _ 'Unable to find package "%s" in the wok' "$pkg"; newline
     1.9 -		exit 1
    1.10 -	fi
    1.11 +	[ -d "$WOK/$pkg" ] || die 'Unable to find package "%s" in the wok' "$pkg"
    1.12  }
    1.13  
    1.14  
    1.15  if_empty_value() {
    1.16 -	if [ -z "$value" ]; then
    1.17 -		# L10n: QA is quality assurance
    1.18 -		_ 'QA: empty variable: %s' "$var=\"\""; newline
    1.19 -		exit 1
    1.20 -	fi
    1.21 +	# L10n: QA is quality assurance
    1.22 +	[ -n "$value" ] || die 'QA: empty variable: %s' "$var=\"\""
    1.23  }
    1.24  
    1.25  
    1.26 @@ -102,9 +96,7 @@
    1.27  	_ 'Creating directories structure in "%s"' "$SLITAZ"
    1.28  	mkdir -p $WOK $PKGS $SRC $CACHE $LOGS $FEEDS
    1.29  	_ 'Creating DB files in "%s"' "$CACHE"
    1.30 -	for f in $activity $command $broken $blocked; do
    1.31 -		touch $f
    1.32 -	done
    1.33 +	touch $activity $command $broken $blocked
    1.34  }
    1.35  
    1.36  
    1.37 @@ -121,16 +113,16 @@
    1.38  		value="$(. $receipt; eval echo \$$var)"
    1.39  		case "$var" in
    1.40  			PACKAGE|VERSION|SHORT_DESC)
    1.41 -				if_empty_value ;;
    1.42 +				if_empty_value
    1.43 +				;;
    1.44  			CATEGORY)
    1.45  				value="${value:-empty}"
    1.46  				valid="$(echo $PKGS_CATEGORIES)" # avoid newlines
    1.47  				if ! echo " $valid " | grep -q " $value "; then
    1.48  					_ 'QA: unknown category "%s"' "$value"
    1.49 -					longline "$(_ 'Please, use one of: %s' "$valid")"
    1.50 -					newline
    1.51 -					exit 1
    1.52 -				fi ;;
    1.53 +					die 'Please, use one of: %s' "$valid"
    1.54 +				fi
    1.55 +				;;
    1.56  			WEB_SITE)
    1.57  				# We don't check WGET_URL since if dl is needed it will fail.
    1.58  				# Break also if we're not online. Here error is not fatal.
    1.59 @@ -138,7 +130,8 @@
    1.60  				[ -z "$online" ] && break
    1.61  				if ! busybox wget -T 12 -s $value 2>/dev/null; then
    1.62  					_ 'QA: unable to reach "%s"' "$value"
    1.63 -				fi ;;
    1.64 +				fi
    1.65 +				;;
    1.66  		esac
    1.67  	done
    1.68  }
    1.69 @@ -215,55 +208,46 @@
    1.70  
    1.71  get_source() {
    1.72  	local url
    1.73 -	url="$MIRROR_URL/sources/packages/${TARBALL:0:1}/$TARBALL"
    1.74 +	url=${WGET_URL#*|}
    1.75  	set_paths
    1.76  	pwd=$(pwd)
    1.77  	case "$WGET_URL" in
    1.78 -		http://*|ftp://*)
    1.79 -			# Busybox Wget is better!
    1.80 -			busybox wget -T 60 -c -O $SRC/$TARBALL $WGET_URL || \
    1.81 -			busybox wget -T 60 -c -O $SRC/$TARBALL $url || \
    1.82 -				(_ 'ERROR: %s' "wget $WGET_URL" && exit 1) ;;
    1.83 -
    1.84 -		https://*)
    1.85 -			wget -c --no-check-certificate -O $SRC/$TARBALL $WGET_URL || \
    1.86 -			busybox wget -T 60 -c -O $SRC/$TARBALL $url || \
    1.87 -				(_ 'ERROR: %s' "wget $WGET_URL" && exit 1) ;;
    1.88 +		http://*|ftp://*|https://*)
    1.89 +			url="$MIRROR_URL/sources/packages/${TARBALL:0:1}/$TARBALL"
    1.90 +			wget -T 60 -c -O $SRC/$TARBALL $WGET_URL ||
    1.91 +			wget -T 60 -c -O $SRC/$TARBALL $url ||
    1.92 +			die 'ERROR: %s' "wget $WGET_URL"
    1.93 +			;;
    1.94  
    1.95  		hg*|mercurial*)
    1.96 -			if $(echo "$WGET_URL" | fgrep -q 'hg|'); then
    1.97 -				url=${WGET_URL#hg|}
    1.98 -			else
    1.99 -				url=${WGET_URL#mercurial|}
   1.100 -			fi
   1.101  			_ 'Getting source from %s...' 'Hg'
   1.102  			_ 'URL: %s' "$url"
   1.103  			_ 'Cloning to "%s"' "$pwd/$pkgsrc"
   1.104  			if [ -n "$BRANCH" ]; then
   1.105  				_ 'Hg branch: %s' "$BRANCH"
   1.106 -				hg clone $url --rev $BRANCH $pkgsrc || \
   1.107 -					(_ 'ERROR: %s' "hg clone $url --rev $BRANCH" && exit 1)
   1.108 +				hg clone $url --rev $BRANCH $pkgsrc ||
   1.109 +				die 'ERROR: %s' "hg clone $url --rev $BRANCH"
   1.110  			else
   1.111 -				hg clone $url $pkgsrc || (_ 'ERROR: %s' "hg clone $url" && exit 1)
   1.112 +				hg clone $url $pkgsrc || die 'ERROR: %s' "hg clone $url"
   1.113  			fi
   1.114  			rm -rf $pkgsrc/.hg
   1.115 -			create_tarball ;;
   1.116 +			create_tarball
   1.117 +			;;
   1.118  
   1.119  		git*)
   1.120 -			url=${WGET_URL#git|}
   1.121  			_ 'Getting source from %s...' 'Git'
   1.122  			_ 'URL: %s' "$url"
   1.123  			cd $SRC
   1.124 -			git clone $url $pkgsrc || (_ 'ERROR: %s' "git clone $url" && exit 1)
   1.125 +			git clone $url $pkgsrc || die 'ERROR: %s' "git clone $url"
   1.126  			if [ -n "$BRANCH" ]; then
   1.127  				_ 'Git branch: %s' "$BRANCH"
   1.128  				cd $pkgsrc; git checkout $BRANCH; cd ..
   1.129  			fi
   1.130  			cd $SRC
   1.131 -			create_tarball ;;
   1.132 +			create_tarball
   1.133 +			;;
   1.134  
   1.135  		cvs*)
   1.136 -			url=${WGET_URL#cvs|}
   1.137  			mod=$PACKAGE
   1.138  			[ -n "$CVS_MODULE" ] && mod=$CVS_MODULE
   1.139  			_ 'Getting source from %s...' 'CVS'
   1.140 @@ -271,14 +255,10 @@
   1.141  			[ -n "$CVS_MODULE" ] && _ 'CVS module: %s' "$mod"
   1.142  			_ 'Cloning to "%s"' "$pwd/$mod"
   1.143  			cvs -d:$url co $mod && mv $mod $pkgsrc
   1.144 -			create_tarball ;;
   1.145 +			create_tarball
   1.146 +			;;
   1.147  
   1.148  		svn*|subversion*)
   1.149 -			if $(echo "$WGET_URL" | fgrep -q "svn|"); then
   1.150 -				url=${WGET_URL#svn|}
   1.151 -			else
   1.152 -				url=${WGET_URL#subversion|}
   1.153 -			fi
   1.154  			_ 'Getting source from %s...' 'SVN'
   1.155  			_ 'URL: %s' "$url"
   1.156  			if [ -n "$BRANCH" ]; then
   1.157 @@ -286,10 +266,10 @@
   1.158  			else
   1.159  				echo t | svn co $url $pkgsrc
   1.160  			fi
   1.161 -			create_tarball ;;
   1.162 +			create_tarball
   1.163 +			;;
   1.164  
   1.165  		bzr*)
   1.166 -			url=${WGET_URL#bzr|}
   1.167  			_ 'Getting source from %s...' 'bazaar'
   1.168  			cd $SRC
   1.169  			pkgsrc=${url#*:}
   1.170 @@ -371,7 +351,7 @@
   1.171  	[ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
   1.172  	fs=$(du -sh $WOK/$pkg/taz/* | awk '{print $1}')
   1.173  	size=$(ls -lh $PKGS/$pkg-${VERSION}*.tazpkg | awk '{print $5}')
   1.174 -	files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)
   1.175 +	files=$(cat $WOK/$pkg/taz/$pkg-*/files.list | wc -l)		# please keep cat here, otherwise it'll not work
   1.176  	[ -n "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
   1.177  
   1.178  	_ 'Summary for: %s' "$PACKAGE $VERSION"
   1.179 @@ -399,19 +379,22 @@
   1.180  	# L10n: specify your format of date and time (to help: man date)
   1.181  	# L10n: not bad one is '+%x %R'
   1.182  	_ 'Cook date: %s' "$(date "$(_ '+%%F %%R')")"
   1.183 -	[ "$time" ] && _ 'Cook time: %ds' "$(($(date +%s) - $time))"
   1.184 -	# L10n: Please, translate all messages beginning with ERROR in a same way
   1.185 -	lerror=$(_n 'ERROR')
   1.186 +	if [ -n "$time" ]; then
   1.187 +		times="$(($(date +%s) - $time))"
   1.188 +		_ 'Cook time   : %s' "$(disp_time "$times")"
   1.189 +	fi
   1.190  	for error in \
   1.191 -		ERROR $lerror 'No package' "cp: can't" "can't open" "can't cd" \
   1.192 +		ERROR 'No package' "cp: can't" "can't open" "can't cd" \
   1.193  		'error:' 'fatal error:' 'undefined reference to' \
   1.194  		'Unable to connect to' 'link: cannot find the library' \
   1.195  		'CMake Error' ': No such file or directory' \
   1.196  		'Could not read symbols: File in wrong format'
   1.197  	do
   1.198 -		fgrep "$error" $LOGS/$pkg.log
   1.199 +		# format "line number:line content"
   1.200 +		fgrep -n "$error" $LOGS/$pkg.log
   1.201  	done > $LOGS/$pkg.log.debug_info 2>&1
   1.202 -	cat $LOGS/$pkg.log.debug_info
   1.203 +	# sort by line number, remove duplicates
   1.204 +	sort -gk1,1 -t: -u $LOGS/$pkg.log.debug_info
   1.205  	rm -f $LOGS/$pkg.log.debug_info
   1.206  	footer
   1.207  }
   1.208 @@ -448,13 +431,10 @@
   1.209  	if [ "${COOKOPTS/!pixmaps/}" == "$COOKOPTS" -a "$GENERIC_PIXMAPS" != 'no' ]; then
   1.210  		if [ -d "$install/usr/share/pixmaps" ]; then
   1.211  			mkdir -p $fs/usr/share/pixmaps
   1.212 -			if [ -f "$install/usr/share/pixmaps/$PACKAGE.png" ]; then
   1.213 -				copy $install/usr/share/pixmaps/$PACKAGE.png \
   1.214 -					$fs/usr/share/pixmaps
   1.215 -			elif [ -f "$install/usr/share/pixmaps/$PACKAGE.xpm" ]; then
   1.216 -				copy   $install/usr/share/pixmaps/$PACKAGE.xpm \
   1.217 -					$fs/usr/share/pixmaps
   1.218 -			fi
   1.219 +			for i in png xpm; do
   1.220 +				[ -f "$install/usr/share/pixmaps/$PACKAGE.$i" ] &&
   1.221 +				copy $install/usr/share/pixmaps/$PACKAGE.$i $fs/usr/share/pixmaps
   1.222 +			done
   1.223  		fi
   1.224  
   1.225  		# Custom or homemade PNG pixmap can be in stuff.
   1.226 @@ -1096,70 +1076,6 @@
   1.227  }
   1.228  
   1.229  
   1.230 -# Search file in mirrored packages
   1.231 -
   1.232 -search_file_mirror() {
   1.233 -	busybox unlzma -c $DB/files.list.lzma | grep $1\$ | cut -d: -f1 | sort -u
   1.234 -}
   1.235 -
   1.236 -
   1.237 -# Search file in local wok packages
   1.238 -
   1.239 -search_file_local() {
   1.240 -	# existing packages have precedence over the package/taz folder
   1.241 -	srch=$1
   1.242 -	{ for package in $(find $PKGS -name '*.tazpkg'); do
   1.243 -		if [ -n "$(busybox cpio --to-stdout --quiet -i files.list < $package | \
   1.244 -			grep /$srch\$)" ]; then
   1.245 -			busybox cpio -i receipt < $package | fgrep PACKAGE | cut -d\" -f2
   1.246 -		fi
   1.247 -	done } | sort -u
   1.248 -}
   1.249 -
   1.250 -
   1.251 -# Ask in multiple choice
   1.252 -
   1.253 -ask_multiple() {
   1.254 -	local multiples first my_choice
   1.255 -	multiples="$1"
   1.256 -	first=$(echo "$multiples" | head -n1)
   1.257 -	newline; _ 'Multiple choice:'; echo "$multiples"; newline
   1.258 -	_ 'Select one [%s]: ' "$first"; read my_choice
   1.259 -	found="${my_choice:-$first}"
   1.260 -}
   1.261 -
   1.262 -
   1.263 -# Search file in local cache (fast), local wok packages, mirrored packages
   1.264 -
   1.265 -search_file() {
   1.266 -	local srch cache missing
   1.267 -	srch="$1"
   1.268 -	cache='/var/cache/ldsearch.cache'
   1.269 -	missing='/var/cache/missing.file'
   1.270 -	touch $cache $missing
   1.271 -	found=$(grep $srch $cache | cut -d$'\t' -f2)
   1.272 -	if [ -z "$found" ]; then
   1.273 -		found=$(search_file_local $srch)
   1.274 -		if [ -n "$found" ]; then
   1.275 -			if [ $(echo "$found" | wc -l) -gt 1 ]; then
   1.276 -				ask_multiple "$found"
   1.277 -			fi
   1.278 -			echo -e "$srch\t$found" >> $cache
   1.279 -		else
   1.280 -			found=$(search_file_mirror $srch)
   1.281 -			if [ -n "$found" ]; then
   1.282 -				if [ $(echo "$found" | wc -l) -gt 1 ]; then
   1.283 -					ask_multiple "$found"
   1.284 -				fi
   1.285 -				echo -e "$srch\t$found" >> $cache
   1.286 -			else
   1.287 -				echo "$srch" >> $missing
   1.288 -			fi
   1.289 -		fi
   1.290 -	fi
   1.291 -}
   1.292 -
   1.293 -
   1.294  #
   1.295  # Receipt functions to ease packaging
   1.296  #
   1.297 @@ -1662,37 +1578,7 @@
   1.298  				exit 0 ;;
   1.299  
   1.300  			--cdeps)
   1.301 -				if [ ! -d $WOK/$pkg/taz ]; then
   1.302 -					_ 'Need to build "%s"' "$pkg"
   1.303 -					exit 0
   1.304 -				fi
   1.305 -
   1.306 -				title 'Checking depends'
   1.307 -				lddlist='/tmp/lddlist'; touch $lddlist
   1.308 -				missing='/var/cache/missing.file'
   1.309 -
   1.310 -				# find all deps using ldd
   1.311 -				for exe in $(find $WOK/$pkg/taz -type f -perm +111); do
   1.312 -					[ "x$(dd if=$exe bs=4 count=1 2>/dev/null)" == "xELF" ] &&
   1.313 -						ldd $exe | sed 's|	||' | cut -d' ' -f1 >> $lddlist
   1.314 -				done #"
   1.315 -
   1.316 -				# remove exe/so duplicates
   1.317 -				sort -u $lddlist > $lddlist.sorted
   1.318 -
   1.319 -				# search packages
   1.320 -				for exefile in $(cat $lddlist.sorted); do
   1.321 -					search_file $exefile
   1.322 -					echo "$found" >> $lddlist.pkgs
   1.323 -					echo -n '.'
   1.324 -				done
   1.325 -				echo
   1.326 -
   1.327 -				# remove packages duplicates
   1.328 -				sort -u $lddlist.pkgs > $lddlist.final
   1.329 -				sort -u $missing > $missing.final
   1.330 -				rm -f $lddlist $lddlist.sorted $lddlist.pkgs $missing
   1.331 -				exit 0 ;;
   1.332 +				@@PREFIX@@/libexec/cookutils/cdeps $pkg
   1.333  		esac
   1.334  
   1.335  		# Rotate log
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/modules/cdeps	Fri Mar 17 00:44:10 2017 +0200
     2.3 @@ -0,0 +1,108 @@
     2.4 +#!/bin/sh
     2.5 +#
     2.6 +# cdeps - module of the SliTaz Cook
     2.7 +# Copyright (C) SliTaz GNU/Linux - GNU GPL v3
     2.8 +#
     2.9 +
    2.10 +. /usr/lib/slitaz/libcook.sh
    2.11 +
    2.12 +
    2.13 +# Search file in mirrored packages
    2.14 +
    2.15 +search_file_mirror() {
    2.16 +	busybox unlzma -c $DB/files.list.lzma | grep $1\$ | cut -d: -f1 | sort -u
    2.17 +}
    2.18 +
    2.19 +
    2.20 +# Search file in local wok packages
    2.21 +
    2.22 +search_file_local() {
    2.23 +	# existing packages have precedence over the package/taz folder
    2.24 +	srch=$1
    2.25 +	{ for package in $(find $PKGS -name '*.tazpkg'); do
    2.26 +		if [ -n "$(busybox cpio --to-stdout --quiet -i files.list < $package | \
    2.27 +			grep /$srch\$)" ]; then
    2.28 +			busybox cpio -i receipt < $package | fgrep PACKAGE | cut -d\" -f2
    2.29 +		fi
    2.30 +	done } | sort -u
    2.31 +}
    2.32 +
    2.33 +
    2.34 +# Ask in multiple choice
    2.35 +
    2.36 +ask_multiple() {
    2.37 +	local multiples first my_choice
    2.38 +	multiples="$1"
    2.39 +	first=$(echo "$multiples" | head -n1)
    2.40 +	newline; _ 'Multiple choice:'; echo "$multiples"; newline
    2.41 +	_ 'Select one [%s]: ' "$first"; read my_choice
    2.42 +	found="${my_choice:-$first}"
    2.43 +}
    2.44 +
    2.45 +
    2.46 +# Search file in local cache (fast), local wok packages, mirrored packages
    2.47 +
    2.48 +search_file() {
    2.49 +	local srch cache missing
    2.50 +	srch="$1"
    2.51 +	cache='/var/cache/ldsearch.cache'
    2.52 +	missing='/var/cache/missing.file'
    2.53 +	touch $cache $missing
    2.54 +	found=$(grep $srch $cache | cut -d$'\t' -f2)
    2.55 +	if [ -z "$found" ]; then
    2.56 +		found=$(search_file_local $srch)
    2.57 +		if [ -n "$found" ]; then
    2.58 +			if [ $(echo "$found" | wc -l) -gt 1 ]; then
    2.59 +				ask_multiple "$found"
    2.60 +			fi
    2.61 +			echo -e "$srch\t$found" >> $cache
    2.62 +		else
    2.63 +			found=$(search_file_mirror $srch)
    2.64 +			if [ -n "$found" ]; then
    2.65 +				if [ $(echo "$found" | wc -l) -gt 1 ]; then
    2.66 +					ask_multiple "$found"
    2.67 +				fi
    2.68 +				echo -e "$srch\t$found" >> $cache
    2.69 +			else
    2.70 +				echo "$srch" >> $missing
    2.71 +			fi
    2.72 +		fi
    2.73 +	fi
    2.74 +}
    2.75 +
    2.76 +
    2.77 +
    2.78 +
    2.79 +
    2.80 +
    2.81 +if [ ! -d $WOK/$pkg/taz ]; then
    2.82 +	_ 'Need to build "%s"' "$pkg"
    2.83 +	exit 0
    2.84 +fi
    2.85 +
    2.86 +title 'Checking depends'
    2.87 +lddlist='/tmp/lddlist'; touch $lddlist
    2.88 +missing='/var/cache/missing.file'
    2.89 +
    2.90 +# find all deps using ldd
    2.91 +for exe in $(find $WOK/$pkg/taz -type f -perm +111); do
    2.92 +	[ "x$(dd if=$exe bs=4 count=1 2>/dev/null)" == "xELF" ] &&			#"
    2.93 +		ldd $exe | sed 's|	||' | cut -d' ' -f1 >> $lddlist
    2.94 +done
    2.95 +
    2.96 +# remove exe/so duplicates
    2.97 +sort -u $lddlist > $lddlist.sorted
    2.98 +
    2.99 +# search packages
   2.100 +for exefile in $(cat $lddlist.sorted); do
   2.101 +	search_file $exefile
   2.102 +	echo "$found" >> $lddlist.pkgs
   2.103 +	echo -n '.'
   2.104 +done
   2.105 +echo
   2.106 +
   2.107 +# remove packages duplicates
   2.108 +sort -u $lddlist.pkgs > $lddlist.final
   2.109 +sort -u $missing > $missing.final
   2.110 +rm -f $lddlist $lddlist.sorted $lddlist.pkgs $missing
   2.111 +exit 0
     3.1 --- a/modules/pkgdb	Wed Mar 08 22:52:08 2017 +0100
     3.2 +++ b/modules/pkgdb	Fri Mar 17 00:44:10 2017 +0200
     3.3 @@ -109,7 +109,7 @@
     3.4  		DEPENDS=$(echo $DEPENDS) # remove newlines from some receipts
     3.5  		MD5="$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" $PKGS/packages.md5 | awk '{print $1}')"
     3.6  		cat >> $PKGS/packages.info <<EOT
     3.7 -$PACKAGE	$VERSION$EXTRAVERSION	$CATEGORY	$SHORT_DESC	$WEB_SITE	$TAGS	$SIZES	$DEPENDS	$MD5
     3.8 +$PACKAGE	$VERSION$EXTRAVERSION	$CATEGORY	$SHORT_DESC	$WEB_SITE	$TAGS	$SIZES	$DEPENDS	$MD5	$PROVIDE
     3.9  EOT
    3.10  
    3.11  		# packages.equiv is used by tazpkg install to check depends.
    3.12 @@ -125,8 +125,7 @@
    3.13  		done
    3.14  
    3.15  		# files.list provides a list of all packages files.
    3.16 -		cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> \
    3.17 -			$PKGS/files.list
    3.18 +		[ -d $pkg/taz ] && cat $pkg/taz/*/files.list | sed s/^/"$pkg: \0"/ >> $PKGS/files.list
    3.19  
    3.20  		# list of unnecessary packages
    3.21  		sed -i "/ $PACKAGE-$VERSION$EXTRAVERSION.tazpkg/d" $PKGS/packages.toremove
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/modules/qa	Fri Mar 17 00:44:10 2017 +0200
     4.3 @@ -0,0 +1,71 @@
     4.4 +#!/bin/sh
     4.5 +#
     4.6 +# qa - module of the SliTaz Cook
     4.7 +# Copyright (C) SliTaz GNU/Linux - GNU GPL v3
     4.8 +#
     4.9 +
    4.10 +. /usr/lib/slitaz/libcook.sh
    4.11 +
    4.12 +
    4.13 +result() {
    4.14 +	# using external $rule, $check
    4.15 +	[ -n "$check" ] || return
    4.16 +	echo "$rule:"
    4.17 +	echo "$check" | awk '{printf("  %s\n", $0)}'
    4.18 +	echo
    4.19 +}
    4.20 +
    4.21 +# FHS: http://refspecs.linuxfoundation.org/FHS_3.0/fhs-3.0.html
    4.22 +
    4.23 +# FHS 3.16.2
    4.24 +rule='Subdirectories in /sbin'
    4.25 +check="$(find $root/sbin -mindepth 1 -type d 2>/dev/null | sed "s|^$root||")"
    4.26 +result
    4.27 +
    4.28 +# FHS 4.2, 4.3
    4.29 +rule='Non-standard directories in /usr'
    4.30 +check="$(ls $root/usr 2>/dev/null | sed '/^bin$/d; /^lib$/d; /^local$/d; /^sbin$/d; /^share$/d; /^games$/d; /^include$/d; /^libexec$/d; /^lib[0-9][0-9]*$/d; /^src$/d' | sed 's|^|/usr/|')"
    4.31 +result
    4.32 +
    4.33 +# FHS 4.4.2
    4.34 +rule='Subdirectories in /usr/bin'
    4.35 +check="$(find $root/usr/bin -mindepth 1 -type d 2>/dev/null | sed "s|^$root||")"
    4.36 +result
    4.37 +
    4.38 +# FHS 4.9.1
    4.39 +rule='Using /usr/local for system packages'
    4.40 +check="$(ls -d $root/usr/local 2>/dev/null | sed "s|^$root||")"
    4.41 +result
    4.42 +
    4.43 +# FHS 4.10.2
    4.44 +rule='Subdirectories in /usr/sbin'
    4.45 +check="$(find $root/usr/sbin -mindepth 1 -type d 2>/dev/null | sed "s|^$root||")"
    4.46 +result
    4.47 +
    4.48 +
    4.49 +
    4.50 +exit 0
    4.51 +
    4.52 +echo 'Check extra folders'
    4.53 +
    4.54 +for i in /bin /sbin /usr/bin /usr/sbin; do
    4.55 +	find $i -mindepth 1 -type d
    4.56 +done
    4.57 +
    4.58 +
    4.59 +echo 'Check bad folders'
    4.60 +
    4.61 +for i in /usr/etc /usr/man; do
    4.62 +	find $i -type d -maxdepth 0
    4.63 +done
    4.64 +
    4.65 +
    4.66 +echo ''
    4.67 +
    4.68 +
    4.69 +case dir in
    4.70 +	bin)		user='root'; maskf='+022'; maskd='+777';;
    4.71 +	etc/init.d)	user='root'; maskf='!755'
    4.72 +	etc)		user='root'; maskf='+133'; permd='';;
    4.73 +	/usr/share/applications) find /usr/share/applications -maxdepth 1 \( -type d -o ! -user root -o ! -perm 644 \) -exec ls -land {} \;
    4.74 +esac