slweb

Једноставни генератор статичких веб страна
git clone https://git.sr.ht/~strahinja/slweb
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

makedate (1771B)


      1 #!/bin/sh -x
      2 # vim: set ft=bash:
      3 FALLBACKDATE=${FALLBACKDATE:-unknown}
      4 LC_ALL=C
      5 export LC_ALL
      6 
      7 getent()
      8 {
      9 	if command -v getent >/dev/null 2>&1; then
     10 		command getent "$@"
     11 		return
     12 	fi
     13 	case "$1" in
     14 	passwd|group)
     15 		if [ -z "$2" ]; then
     16 			cat /etc/"$1"
     17 		else
     18 			awk -F: -vu="$2" '{ if ($3 == u) print }' /etc/"$1"
     19 		fi
     20 		;;
     21 	*)	;;
     22 	esac
     23 }
     24 
     25 if [ -d .got ] && command -v got >/dev/null 2>&1; then
     26 	got log |
     27 	awk '
     28 	/^date: / {
     29 		sub(/^date: /,"",$0)
     30 		# Convert to proper form for `mandoc -Tlint`
     31 		month_names["Jan"] = "January"
     32 		month_names["Feb"] = "February"
     33 		month_names["Mar"] = "March"
     34 		month_names["Apr"] = "April"
     35 		month_names["May"] = "May"
     36 		month_names["Jun"] = "June"
     37 		month_names["Jul"] = "July"
     38 		month_names["Aug"] = "August"
     39 		month_names["Sep"] = "September"
     40 		month_names["Oct"] = "October"
     41 		month_names["Nov"] = "November"
     42 		month_names["Dec"] = "December"
     43 		print month_names[$2] " " $3 ", " $5
     44 		exit
     45 	}' >date.new
     46 elif [ -d .git ] && command -v git >/dev/null 2>&1; then
     47 	user=$(getent passwd "$(unalias ls >/dev/null 2>&1 || true; \
     48 		command ls -nd . | awk '{print $3}')" | awk -F: '{print $1}')
     49 	if [ -z "$user" ]; then
     50 		printf "$0: error: Cannot determine owner of %s" "$(pwd)" >&2
     51 		exit 1
     52 	fi
     53 	e_user=$(id -un)
     54 	if [ "$e_user" = "$user" ]; then
     55 		git log --format=format:%cd \
     56 			--date=format:"%B %d, %Y" -1 @ >date.new
     57 	else
     58 		su "${user}" -c 'env LC_ALL=C git log --format=format:%cd \
     59 			--date=format:"%B %d, %Y" -1 @' >date.new
     60 	fi
     61 	echo >>date.new
     62 else
     63 	printf "%s\n" "$FALLBACKDATE" >date.new
     64 fi
     65 
     66 if [ -f date ]; then
     67 	if diff date date.new >/dev/null; then
     68 		rm date.new
     69 	else
     70 		mv date.new date
     71 		touch .rebuild
     72 	fi
     73 else
     74 	mv date.new date
     75 	touch .rebuild
     76 fi
     77 if [ "$1" = "-l" ]; then
     78 	printf "DATE=\"%s\"\n" "$(cat date)"
     79 fi