FIXME unfinished stuff.

opkg-list-user-installed-packages-sorted-by-size-20180114
#!/usr/bin/awk -f
BEGIN {
	D="cd /overlay/upper/usr/lib/opkg/info&&"
	C=D"ls *.list"
	S="sort -n"
	while(C|getline>0) {
		P=substr(F=$1,1,length($1)-5)
		J=D"du -sk $(cat "F")"
		s=0
		while(J|getline>0) {
			s+=$1
			t+=$1
		}
		close(J)
		print s"\t"P|S
	}
	close(S)
	print t"\t---TOTAL---"
}

:!: This originally was created as 1-liner and now just has been unfolded.

opkg-list-user-installed-packages-sorted-by-size-20180115
#!/usr/bin/awk -f
BEGIN {
	D="cd /overlay/upper/usr/lib/opkg/info&&"
	C=D"ls *.list"
	S="sort -n"
	while(C|getline>0) {
		P=substr(F=$1,1,length($1)-5)
		J=D"du -sk $(cat "F")"
		s=0
		while(J|getline>0) s+=$1
		close(J)
		t+=s
		print s"\t"P|S
	}
	close(S)
	print t"\t---TOTAL---"
}

:!: Moved summing t (total) to outside the loop.

:?: Should the size of the files in /overlay/upper/usr/lib/opkg/info/packagename.* which describe the package be counted too? Can-o-worms?

:?: Why du -k? What was the mysterious reason why it makes sense despite being du's default?

:?: Why du -s?

:!: Have a look: (the example was run on Debian)

$ du logs
8       logs/refs/heads
8       logs/refs/remotes/origin
12      logs/refs/remotes
24      logs/refs
32      logs

The script only needs the summary of directories:

$ du -s logs
32      logs

If called with files and directories, files are shown like without -s and directories are totalled:

$ ls -ld description logs
-rw-r--r-- 1 yeti yeti   73 Mai 15  2017 description
drwxr-xr-x 3 yeti yeti 4096 Mai 15  2017 logs
$ du -s description logs
4       description
32      logs

As long as this script shall show no intermediate results, letting du sum the directories' sizes fits.

FIXME add error free reaction for “no user installed packages yet” state.

root@zsun0:~# ./opkg-list-user-installed-sorted-by-size 
sh: cd: line 1: can't cd to /overlay/upper/usr/lib/opkg/info: No such file or directory
        ---TOTAL---
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
  • Last modified: 2019/09/07 19:18
  • by yeti