linije

Клон игре Color lines
git clone https://git.sr.ht/~strahinja/linije
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

makedate (1912B)


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