pthbs

Packaging Through Hashed Build Scripts
git clone https://ccx.te2000.cz/git/pthbs
Log | Files | Refs | Submodules | README

applyuidgid-caps (2733B)


      1 #!/usr/bin/env pthbs-build
      2 #+musl-cross-make.65f98305f5666435bf0c6b9ccedffae2179ff1b3286752756886f760cf7771d2
      3 #+gnu-make.782c9e6625fd7420e2cd38b847afed19db3b3844cae8a0426a0dbf73e10d78e5
      4 #+busybox.e60885fe93ee85c01831673bb29f0e62a64903f4ce3094e3dc35bc8ec8887ad9
      5 #+skalibs.a98901a2d19b3799a9c481e2be46a14642d670d9724480b81988486c71eba15a
      6 #+libcap.3528f93ae9873fceae62855cb7c0fa521ac2c3cfabe71bf58ba01483136bf5fd
      7 #@sha256:818a5ad7061ab1a740a5c2e7d7d8cdcc7be7e84e3f04b479731cf94ff1f1d093:applyuidgid-caps.c
      8 
      9 name=applyuidgid-caps
     10 check_static() {
     11 	local exe || true
     12 	exe=$pthbs_destdir/'/versions'/$pthbs_package/$1
     13 	if ! test -f $exe; then
     14 		printf '%s\n' "Error: file '$1' doesn't exist!"
     15 		exit 1
     16 	fi
     17 	interp_info=$(readelf --string-dump=.interp "$exe") || exit $?
     18 	if test x '!=' "x$interp_info"; then
     19 		printf '%s\n' "Error: '$1' is a dynamic binary!"
     20 		exit 1
     21 	fi
     22 }
     23 build_env_static() {
     24 	export LD_LIBRARY_PATH="$pthbs_build_environment/library"
     25 	export CPATH="$pthbs_build_environment/include"
     26 	export LDFLAGS="-static -L$pthbs_build_environment/library $LDFLAGS"
     27 }
     28 def_prefix() {
     29 	prefix=/versions/$pthbs_package
     30 }
     31 def_dest() {
     32 	dest=${pthbs_destdir%/}//versions/$pthbs_package
     33 }
     34 build_env_static
     35 def_prefix
     36 
     37 gcc -D_GNU_SOURCE -static -o $name $name.c $LDFLAGS -lskarnet -lcap
     38 
     39 install -d "$pthbs_destdir/$prefix/command"
     40 install -m 755 $name "$pthbs_destdir/$prefix/command"
     41 check_static command/$name
     42 
     43 cd "$pthbs_destdir/versions/$pthbs_package"
     44 find -type d -o -print | awk -F/ '
     45 BEGIN {
     46 	x["./command/applyuidgid-caps"]=1}
     47 
     48 function r1(s) {
     49 	sub("^[.]/[^/]*", ".", s)
     50 	return s
     51 }
     52 function s1(repl, s) {
     53 	sub("^[.]/[^/]*", "./"repl, s)
     54 	return s
     55 }
     56 function link(src) {
     57 	x[$0]=0
     58 	printf "%s\t%s\n", $0, src
     59 	printf "genlinks >>%s\t%s<<\n", $0, src >>"/dev/stderr"
     60 }
     61 $1!="."{exit 1}
     62 
     63 
     64 $2 == "command" { link($0); next }
     65 $2 == "bin" { link(s1("command", $0)); next }
     66 
     67 $2 == "library.so" { link($0); next }
     68 $2 == "library" { link($0); next }
     69 $2 == "lib" && $NF ~ /\.l?a$/ { link(s1("library", $0)); next }
     70 $2 == "lib" && $NF ~ /\.so(|\..*)$/ { link(s1("library.so", $0)); next }
     71 
     72 $2 == "share" && $3 ~ /^(info|man|doc|icons|terminfo)$/ { link(r1($0)); next }
     73 
     74 $2 == "man" { link($0); next }
     75 $2 == "info" { link($0); next }
     76 $2 == "doc" { link($0); next }
     77 $2 == "icons" { link($0); next }
     78 $2 == "terminfo" { link($0); next }
     79 $2 == "data" { link($0); next }
     80 $2 == "include" { link($0); next }
     81 
     82 { printf "genlinks ##%s## skipped\n", $0 >>"/dev/stderr" }
     83 
     84 END {
     85 	for(fname in x) { printf "DEBUG: x[\"%s\"]=\"%s\"\n", fname, x[fname] >"/dev/stderr" }
     86 	for(fname in x) {
     87 		if(x[fname]) {
     88 			printf "ERROR: missing expected file \"%s\"\n", fname >"/dev/stderr"
     89 			exit 3
     90 		}
     91 	}
     92 }' >.install-links.new
     93 mv .install-links.new .install-links