fileset

git mirror of https://ccx.te2000.cz/bzr/fileset
git clone https://ccx.te2000.cz/git/fileset
Log | Files | Refs | README

test.sh (1045B)


      1 #!/bin/sh
      2 export fname dirname
      3 die() {
      4 	printf '%s\n' "$*"
      5 	exit 1
      6 }
      7 
      8 fname=./etc/autofs/auto.smb
      9 dirname=./etc/autofs
     10 if ! test -f "$fname"; then
     11 	if test -e "$fname"; then
     12 		die "already present but not a file:" "$fname"
     13 	fi
     14 fi
     15 content='#!/bin/bash
     16 
     17 # This file must be executable to work! chmod 755!
     18 
     19 key="$1"
     20 opts="-fstype=cifs"
     21 
     22 for P in /bin /sbin /usr/bin /usr/sbin
     23 do
     24 	if [ -x $P/smbclient ]
     25 	then
     26 		SMBCLIENT=$P/smbclient
     27 		break
     28 	fi
     29 done
     30 
     31 [ -x $SMBCLIENT ] || exit 1
     32 
     33 $SMBCLIENT -gNL $key 2>/dev/null| awk -v key="$key" -v opts="$opts" -F'\''|'\'' -- '\''
     34 	BEGIN	{ ORS=""; first=1 }
     35 	/Disk/	{
     36 		  if (first)
     37 			print opts; first=0
     38 		  dir = $2
     39 		  loc = $2
     40 		  # Enclose mount dir and location in quotes
     41 		  # Double quote "$" in location as it is special
     42 		  gsub(/\$$/, "\\$", loc);
     43 		  gsub(/\&/,"\\\\&",loc)
     44 		  print " \\\n\t \"/" dir "\"", "\"://" key "/" loc "\""
     45 		}
     46 	END 	{ if (!first) print "\n"; else exit 1 }
     47 	'\''
     48 '
     49 printf >"$fname" '%s\n' "$content" || exit $?
     50 chown 0:0 "$fname" || exit $?
     51 chmod 755 "$fname" || exit $?