#!/bin/rc

src=/usr/djc/plan9

kill 9660srv | rc

rm -rf /tmp/plan9-1e /tmp/plan9-2e /tmp/plan9-3e /tmp/plan9-4e /tmp/plan9-4e-latest

now=1616457600 # 2020-03-23
nowt=1761609600 # 2025-10-28

cp $src/license/trademarks.4e.ps $src/license/trademarks.4e-latest.ps
touch -t $now $src/license/*
touch -t $nowt $src/license/trademarks.*
chmod 444 $src/license/*
chmod 664 $src/license/trademarks.*.ps
chgrp sys $src/license/*

9660srv -f $src/geoff/dist/1e/1e.iso 1e
9660srv -f $src/geoff/rls/plan9/2e.iso 2e
9660srv -f $src/geoff/rls/plan9/3e.iso 3e
9660srv -f $src/djc/plan9-4th-2002-04-27.iso 4e
9660srv -f $src/djc/plan9.iso 4e-latest

mount -c /srv/1e /n/1e
mount -c /srv/2e /n/2e
mount -c /srv/3e /n/3e
mount -c /srv/4e /n/4e
mount -c /srv/4e-latest /n/4e-latest

fn trademarks {
	if (! ~ $#* 2) {
		echo usage: trademarks mnt version
		exit usage
	}

	if (test -f $1/sys/lib/man/trademarks) {
		sed 's/Plan 9 is a trademark of .*/Plan 9 is a registered trademark of SouthSuite Inc./' <$1/sys/lib/man/trademarks >/tmp/trademarks
		# touch -t `{mtime $1/sys/lib/man/trademarks | awk '{print $2}'} /tmp/trademarks
		touch -t $nowt /tmp/trademarks
		chgrp sys /tmp/trademarks
		bind /tmp/trademarks /tmp/plan9-$2/sys/lib/man/trademarks
	}

	if (test -f $1/sys/doc/trademarks.ps) {
		# touch -t `{mtime $1/sys/doc/trademarks.ps | awk '{print $2}'} $src/license/trademarks.$2.ps
		touch -t $nowt $src/license/trademarks.$2.ps
		bind $src/license/trademarks.$2.ps /tmp/plan9-$2/sys/doc/trademarks.ps
	}

	#for(i in /sys/lib/man/title /sys/doc/title) {
	#	sed s/™/�/ $i
	#}
}

# 1e and 2e

lst=( \
	1e \
	2e \
)

for(i in $lst){
	mkdir /tmp/plan9-$i
	chgrp sys /tmp/plan9-$i
	touch -t $now /tmp/plan9-$i/readme
	touch -t $now /tmp/plan9-$i/license
	touch -t $now /tmp/plan9-$i/license.lucida
	touch -t `{mtime /n/$i/notice | awk '{print $1}'} /tmp/plan9-$i/notice.old
	touch -t `{mtime /n/$i | awk '{print $1}'} /tmp/plan9-$i
	bind -a /n/$i /tmp/plan9-$i
	bind /tmp/plan9-$i/notice /tmp/plan9-$i/notice.old
	bind $src/license/README.$i /tmp/plan9-$i/readme
	bind $src/license/NOTICE.$i /tmp/plan9-$i/notice
	bind $src/license/LICENSE /tmp/plan9-$i/license
	bind $src/license/LICENSE.lucida.txt /tmp/plan9-$i/license.lucida

	trademarks /n/$i $i

	cd /tmp
	tar cf plan9-$i.tar plan9-$i
	bzip2 plan9-$i.tar && mv plan9-$i.tbz plan9-$i.tar.bz2
}

disk/mk9660 -9cj -n `{mtime /n/1e | awk '{print $1}'} -v 'Plan 9 1st Ed.' -s /tmp/plan9-1e /tmp/plan9-1e.iso
bzip2 plan9-1e.iso

disk/mk9660 -9cj -n `{mtime /n/2e | awk '{print $1}'} -v 'Plan 9 2nd Ed.' -s /tmp/plan9-2e /tmp/plan9-2e.iso
bzip2 plan9-2e.iso

# 3e

# note: we use mtime of /n/3e/2001/0327/386/9load because mtime of /n/3e/2001/0327 is not correct

mkdir /tmp/plan9-3e
chgrp sys /tmp/plan9-3e
touch -t $now /tmp/plan9-3e/README
touch -t $now /tmp/plan9-3e/LICENSE.lucida
touch -t `{mtime /n/3e/2001/0327/LICENSE | awk '{print $1}'} /tmp/plan9-3e/LICENSE.old
touch -t `{mtime /n/3e/2001/0327/NOTICE | awk '{print $1}'} /tmp/plan9-3e/NOTICE.old
touch -t `{mtime /n/3e/2001/0327/386/9load | awk '{print $1}'} /tmp/plan9-3e
bind -a /n/3e/2001/0327 /tmp/plan9-3e
bind /tmp/plan9-3e/NOTICE /tmp/plan9-3e/NOTICE.old
bind /tmp/plan9-3e/LICENSE /tmp/plan9-3e/LICENSE.old
bind $src/license/README.3e /tmp/plan9-3e/README
bind $src/license/NOTICE.3e /tmp/plan9-3e/NOTICE
bind $src/license/NOTICE.3e /tmp/plan9-3e/sys/src/NOTICE
bind $src/license/LICENSE /tmp/plan9-3e/LICENSE
bind $src/license/LICENSE.lucida.txt /tmp/plan9-3e/LICENSE.lucida

trademarks /n/3e/2001/0327 3e

cd /tmp
tar cf plan9-3e.tar plan9-3e
bzip2 plan9-3e.tar && mv plan9-3e.tbz plan9-3e.tar.bz2

disk/mk9660 -9cj -n `{mtime /n/3e/2001/0327/386/9load | awk '{print $1}'} -v 'Plan 9 3rd Ed.' -s /tmp/plan9-3e /tmp/plan9-3e.iso
bzip2 plan9-3e.iso

# 4e

mkdir /tmp/plan9-4e
chgrp sys /tmp/plan9-4e
touch -t $now /tmp/plan9-4e/README
touch -t $now /tmp/plan9-4e/LICENSE.lucida
touch -t `{mtime /n/4e/LICENSE | awk '{print $1}'} /tmp/plan9-4e/LICENSE.old
touch -t `{mtime /n/4e/NOTICE | awk '{print $1}'} /tmp/plan9-4e/NOTICE.old
touch -t `{mtime /n/4e | awk '{print $1}'} /tmp/plan9-4e
bind -a /n/4e /tmp/plan9-4e
bind /tmp/plan9-4e/NOTICE /tmp/plan9-4e/NOTICE.old
bind /tmp/plan9-4e/LICENSE /tmp/plan9-4e/LICENSE.old
bind $src/license/README.4e /tmp/plan9-4e/README
bind $src/license/NOTICE.4e /tmp/plan9-4e/NOTICE
bind $src/license/NOTICE.4e /tmp/plan9-4e/sys/src/NOTICE
bind $src/license/LICENSE /tmp/plan9-4e/LICENSE
bind $src/license/LICENSE.lucida.txt /tmp/plan9-4e/LICENSE.lucida

trademarks /n/4e 4e

cd /tmp
tar cf plan9-4e.tar plan9-4e
bzip2 plan9-4e.tar && mv plan9-4e.tbz plan9-4e.tar.bz2

cd /tmp
disk/mk9660 -9cj -n `{mtime /n/4e | awk '{print $1}'} -v 'Plan 9 4th Ed.' -s /tmp/plan9-4e -b bootdisk.img /tmp/plan9-4e.iso
bzip2 plan9-4e.iso

# 4e-latest

mkdir /tmp/plan9-4e-latest
chgrp sys /tmp/plan9-4e-latest
touch -t $now /tmp/plan9-4e-latest/README
touch -t $now /tmp/plan9-4e-latest/LICENSE.lucida
touch -t `{mtime /n/4e-latest/LICENSE | awk '{print $1}'} /tmp/plan9-4e-latest/LICENSE.old
touch -t `{mtime /n/4e-latest/NOTICE | awk '{print $1}'} /tmp/plan9-4e-latest/NOTICE.old
touch -t `{mtime /n/4e-latest | awk '{print $1}'} /tmp/plan9-4e-latest
bind -a /n/4e-latest /tmp/plan9-4e-latest
bind /tmp/plan9-4e-latest/NOTICE /tmp/plan9-4e-latest/NOTICE.old
bind /tmp/plan9-4e-latest/LICENSE /tmp/plan9-4e-latest/LICENSE.old
bind $src/license/README.4e-latest /tmp/plan9-4e-latest/README
bind $src/license/NOTICE.4e-latest /tmp/plan9-4e-latest/NOTICE
bind $src/license/NOTICE.4e-latest /tmp/plan9-4e-latest/sys/src/NOTICE
bind $src/license/LICENSE /tmp/plan9-4e-latest/LICENSE
bind $src/license/LICENSE.lucida.txt /tmp/plan9-4e-latest/LICENSE.lucida

trademarks /n/4e-latest 4e-latest

cd /tmp
tar cf plan9-4e-latest.tar plan9-4e-latest
bzip2 plan9-4e-latest.tar && mv plan9-4e-latest.tbz plan9-4e-latest.tar.bz2

cd /tmp
disk/mk9660 -9cj -n `{mtime /n/4e-latest | awk '{print $1}'} -v 'PLAN 9 - JAN 10 2015 04:00' -s /tmp/plan9-4e-latest -B pbsraw -x 9load /tmp/plan9-4e-latest.iso
bzip2 plan9-4e-latest.iso

# checksum

cd /tmp
sha1sum -2 256 *.bz2 >sha256sum.txt

# upload

cp /tmp/plan9-*.bz2 /tmp/sha256sum.txt /mnt/term/home/djc/tmp
#cp /tmp/plan9-*.bz2 /tmp/sha256sum.txt /n/web/www.9legacy.org/download/history
exit
import -pc -k user'='web 9p.io /usr/web /n/9p.io
mkdir -p /n/9p.io/plan9/download/history2
cp /tmp/plan9-*.bz2 /tmp/sha256sum.txt /n/9p.io/plan9/download/history2
touch -t $nowt /n/9p.io/plan9/download/history2/*
touch -t $nowt /n/9p.io/plan9/download/history2
