summaryrefslogtreecommitdiff
path: root/rc/bin/pc
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 17:14:36 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 17:14:36 +0300
commit2959e1ede0ebc6fdffd7b8660f43c2ce14c9696f (patch)
treef6343b1ce11a8c87251dd27cf3d3e26b50693fa7 /rc/bin/pc
parente463eb40363ff4c68b1d903f4e0cdd0ac1c5977f (diff)
downloadplan9front-2959e1ede0ebc6fdffd7b8660f43c2ce14c9696f.tar.xz
Import sources from 2011-03-30 iso image - rc
Diffstat (limited to 'rc/bin/pc')
-rwxr-xr-xrc/bin/pc/bootfloppy22
-rwxr-xr-xrc/bin/pc/bootplan972
-rwxr-xr-xrc/bin/pc/bootwin9x115
-rwxr-xr-xrc/bin/pc/bootwinnt53
-rwxr-xr-xrc/bin/pc/defs72
-rwxr-xr-xrc/bin/pc/isfat22
-rwxr-xr-xrc/bin/pc/personalize7
-rwxr-xr-xrc/bin/pc/setup.9fat33
-rwxr-xr-xrc/bin/pc/setup.disk37
-rwxr-xr-xrc/bin/pc/update20
10 files changed, 453 insertions, 0 deletions
diff --git a/rc/bin/pc/bootfloppy b/rc/bin/pc/bootfloppy
new file mode 100755
index 000000000..ce63456c7
--- /dev/null
+++ b/rc/bin/pc/bootfloppy
@@ -0,0 +1,22 @@
+#!/bin/rc
+
+if(~ $#* 0 1) {
+ echo 'usage: bootfloppy /dev/fd0disk plan9.ini [files...]'>[1=2]
+ exit usage
+}
+
+if(! test -f $2) {
+ echo $2 does not exist >[1=2]
+ exit noplan9.ini
+}
+
+disk=$1
+ini=$2
+shift
+shift
+
+mkdir /tmp/bootfloppy.$pid
+cp $ini /tmp/bootfloppy.$pid/plan9.ini
+dd -bs 512 -count 1 < /dev/zero >/tmp/bootfloppy.$pid/plan9.nvr
+disk/format -b /386/pbs -f -d $disk /386/9load /tmp/bootfloppy.$pid/* $*
+rm -rf /tmp/bootfloppy.$pid
diff --git a/rc/bin/pc/bootplan9 b/rc/bin/pc/bootplan9
new file mode 100755
index 000000000..559fe0c5e
--- /dev/null
+++ b/rc/bin/pc/bootplan9
@@ -0,0 +1,72 @@
+#!/bin/rc
+
+rfork e
+
+. /rc/bin/pc/defs
+
+if(! ~ $#* 1) {
+ echo 'usage: bootplan9 /dev/sdC0' >[1=2]
+ echo 'sets active the plan 9 partition on the named disk.' >[1=2]
+ exit usage
+}
+
+disk=$1
+
+fn x {
+ if(! test -f $disk/$1) {
+ echo 'could not find '$disk/$1
+ exit disk
+ }
+}
+
+x plan9
+x data
+x ctl
+
+diskbase=`{basename `{cleanname $disk}}
+
+first=`{ls -p '#S' | sed 1q}
+if(! ~ $first $diskbase) {
+ echo 'warning: The plan 9 partition is not on the boot disk,' >[1=2]
+ echo 'so making it the active partition will have no effect.' >[1=2]
+}
+
+p9offset=`{disk/fdisk -p $disk/data |grep '^part plan9 ' | awk '{print $4}'}
+if(! ~ $#p9offset 1) {
+ echo 'could not find plan 9 partition.' >[1=2]
+ echo 'cannot happen' >[1=2]
+ exit bad
+}
+
+if(test $p9offset -gt 4128705) { # 65536 * 63
+ echo >[1=2]
+ echo 'Your Plan 9 partition is more than 2GB into your disk,' >[1=2]
+ echo 'and the master boot records used by most operating systems' >[1=2]
+ echo 'cannot access it (and thus cannot boot it).' >[1=2]
+ echo >[1=2]
+ echo 'Would you like to install a master boot record' >[1=2]
+ echo 'that will be able to access partitions more than 2GB into the disk?' >[1=2]
+ echo >[1=2]
+ prompt 'Install a new mbr' y n
+ switch($rd) {
+ case n
+ echo >[1=2]
+ echo 'Not setting Plan 9 partition active, then.' >[1=2]
+ echo >[1=2]
+ exit bad
+ case y
+ disk/mbr -m /386/mbr $disk/data
+ }
+}
+
+p9part=`{disk/fdisk $disk/data >[2]/dev/null </dev/null |
+ grep PLAN9 | sed 1q | sed 's/ *(p.) .*/\1/'}
+if(~ $#p9part 1) {
+ { echo 'A '^$p9part; echo w } | disk/fdisk $disk/data >[2]/dev/null >/dev/null
+}
+if not {
+ echo 'Could not find Plan 9 partition.'
+ exit notdone
+}
+
+exit
diff --git a/rc/bin/pc/bootwin9x b/rc/bin/pc/bootwin9x
new file mode 100755
index 000000000..f3f33c613
--- /dev/null
+++ b/rc/bin/pc/bootwin9x
@@ -0,0 +1,115 @@
+#!/bin/rc
+
+dosdisk=`{ls /dev/sd??/dos >[2]/dev/null | sed 1q | sed 's!.*/(.*)/dos!\1!'}
+if(~ $#dosdisk 0 || ! c: || ! test -f /n/c:/autoexec.bat || ! test -f /n/c:/config.sys) {
+ echo 'Could not find autoexec.bat or config.sys on the first FAT disk.' >[1=2]
+ exit
+}
+
+for (i in autoexec config msdos)
+ if(test -f /n/c:/$i.p9) {
+ echo 'A Plan 9 backup already exists; will not edit system files again.' >[1=2]
+ exit
+ }
+
+for (i in autoexec.bat config.sys msdos.sys)
+ if(! cp /n/c:/$i /n/c:/^`{echo $i | sed 's/\.(bat|sys)$/.p9/'}) {
+ echo 'Could not back up '^$i^'; will not continue.' >[1=2]
+ exit
+ }
+
+if(! test -d /n/c:/plan9 && ! mkdir /n/c:/plan9) {
+ echo 'Could not create directory /n/c:/plan9.' >[1=2]
+ exit
+}
+
+if(! cp /386/^(9load ld.com) /386/9pcdisk /n/c:/plan9) {
+ echo 'Could not copy Plan 9 boot files into /n/c:/plan9.' >[1=2]
+ exit
+}
+
+chmod +w /n/c:/autoexec.bat /n/c:/config.sys /n/c:/msdos.sys
+
+if(grep -si 'Plan ?9' /n/c:/config.sys || grep -si 'Plan ?9' /n/c:/autoexec.bat) {
+ echo 'Plan 9 entries already in config.sys or autoexec.bat.' >[1=2]
+ echo 'Not changing them; refer to Plan 9 install documentation' >[1=2]
+ echo 'to configure manually.' >[1=2]
+ exit
+}
+
+if(! grep -si '\[menu\]' /n/c:/config.sys) {
+ {
+ echo 1
+ echo i
+ echo '[menu] '
+ echo 'menuitem=windows, Windows '
+ echo 'menudefault=windows '
+ echo ' '
+ echo '[common] '
+ echo ' '
+ echo '[windows] '
+ echo .
+ echo w
+ echo q
+ } | ed /n/c:/config.sys >/dev/null >[2]/dev/null
+}
+
+{
+ echo 1
+ echo '/\[[Mm][Ee][Nn][Uu]\]'
+ echo '?^[Mm][Ee][Nn][Uu][Ii][Tt][Ee][Mm]='
+ echo a
+ echo 'menuitem=plan9, Plan 9 from Bell Labs '
+ echo .
+ echo '$'
+ echo a
+ echo ' '
+ echo '[plan9] '
+ echo ' '
+ echo .
+ echo w
+ echo q
+} | ed /n/c:/config.sys >/dev/null >[2]/dev/null
+
+{
+ echo 1
+ echo i
+ echo '@echo off '
+ echo 'if %config%==plan9 goto plan9 '
+ echo 'goto notplan9 '
+ echo ':plan9 '
+ echo 'plan9\ld '^$dosdisk^'!dos!plan9/9load '
+ echo ':notplan9 '
+ echo .
+ echo w
+ echo q
+} | ed /n/c:/autoexec.bat >/dev/null >[2]/dev/null
+
+fn zeroopt {
+ if(grep -s '^'^$1^'=1' /n/c:/msdos.sys) {
+ {
+ echo '/^'^$1^'=1/s/=1/=0/'
+ echo w
+ echo q
+ } | ed /n/c:/msdos.sys >/dev/null >[2]/dev/null
+ }
+ if not if (grep -s '^'^$1^'=0' /n/c:/msdos.sys)
+ ;
+ if not {
+ {
+ echo 1
+ echo i
+ echo '[Options] '
+ echo 'Logo=0 '
+ echo .
+ echo w
+ echo q
+ } | ed /n/c:/msdos.sys >/dev/null >[2]/dev/null
+ }
+}
+
+if(grep -si '^\[paths\]' /n/c:/msdos.sys){ # Windows 9x rather than DOS
+ zeroopt Logo
+}
+
+exit
diff --git a/rc/bin/pc/bootwinnt b/rc/bin/pc/bootwinnt
new file mode 100755
index 000000000..cab89deda
--- /dev/null
+++ b/rc/bin/pc/bootwinnt
@@ -0,0 +1,53 @@
+#!/bin/rc
+
+disk=`{ls /dev/sd??/plan9 >[2]/dev/null | sed 1q | sed 's!.*/(.*)/plan9!\1!'}
+if(! ~ $#disk 1) {
+ echo 'No plan 9 disk found' >[1=2]
+ exit
+}
+
+if(! c: || ! test -f /n/c:/boot.ini) {
+ echo 'Could not find NT''s boot.ini on the first FAT disk.' >[1=2]
+ exit
+}
+
+if(test -f /n/c:/boot.p9) {
+ echo 'A Plan 9 backup already exists; will not edit boot.ini again.' >[1=2]
+ exit
+}
+
+if(! cp /n/c:/boot.ini /n/c:/boot.p9) {
+ echo 'Could not back up boot.ini; will not continue.' >[1=2]
+ exit
+}
+
+chmod +w /n/c:/boot.ini
+
+if(! grep -si '\[operating systems\]' /n/c:/boot.ini) {
+ echo 'Could not parse boot.ini.' >[1=2]
+ exit
+}
+
+if(grep -si 'Plan 9' /n/c:/boot.ini) {
+ p9file=`{grep 'Plan 9' /n/c:/boot.ini | sed 1q | sed 's/=.*//'}
+ if(! ~ $p9file [Cc]:'\'*) {
+ echo 'Unexpected Plan 9 entry in boot.ini already; not continuing.' >[1=2]
+ exit
+ }
+}
+
+if not {
+ p9file='c:\bootsect.p9'
+ echo 'c:\bootsect.p9 = "Plan 9 from Bell Labs" ' >>/n/c:/boot.ini
+}
+
+p9file=/n/^`{echo $p9file | sed 's!\\!/!g'}
+
+
+if(dd -if /dev/$disk/plan9 -bs 512 -count 1 -of $p9file >/dev/null >[2]/dev/null) {
+ echo 'Plan 9 added to Windows NT boot menu.' >[1=2]
+ exit
+}
+
+echo 'Error copying Plan 9 boot sector to file.'
+exit
diff --git a/rc/bin/pc/defs b/rc/bin/pc/defs
new file mode 100755
index 000000000..c5c2e6950
--- /dev/null
+++ b/rc/bin/pc/defs
@@ -0,0 +1,72 @@
+nl='
+'
+tab=' '
+
+fn prompt {
+ def=()
+ what=()
+ if(~ $1 -d && ! ~ $#* 1){
+ def=$2
+ shift
+ shift
+ }
+
+ optstr=()
+ if(~ $1 -w && ! ~ $#* 1){
+ optstr=$2
+ shift
+ shift
+ }
+
+ pr=$1
+ shift
+
+ opts=($*)
+ if(~ $#opts 0) {
+ suf=' '
+ }
+ if not if(! ~ $#optstr 0) {
+ if(~ $optstr '')
+ suf=' '
+ if not {
+ pr=$pr^' ('^$"optstr^')'
+ suf=''
+ }
+ }
+ if not {
+ pr=$pr^' ('^$1
+ shift
+ for(i)
+ pr=$pr^', '^$i
+ pr=$pr^')'
+ suf=''
+ }
+
+ if(~ $#def 1)
+ pr=$pr^$suf^'['^$def^']'
+ pr=$pr^': '
+
+
+ okay=no
+ while(~ $okay no) {
+# whatis opts
+ echo -n $pr >[1=2]
+ ifs='' {rd=`{read}}
+ if(~ $#rd 0)
+ exit notdone
+ rd=`{echo $rd}
+ if(~ $#rd 0 || ~ $rd '')
+ rd=$def
+
+ switch($#opts){
+ case 0
+ if(! ~ $rd '')
+ okay=yes
+ case *
+ if(~ $rd $opts)
+ okay=yes
+ }
+ }
+ echo -n $rd >/env/rd # just in case
+}
+
diff --git a/rc/bin/pc/isfat b/rc/bin/pc/isfat
new file mode 100755
index 000000000..860278571
--- /dev/null
+++ b/rc/bin/pc/isfat
@@ -0,0 +1,22 @@
+#!/bin/rc
+
+rfork e
+
+# 0000000 eb 3c 90 P l a n 9 . 0 0 00 02 04 02 00
+# 0000010 02 00 02 02 P f8 14 00 ? 00 ff 00 ~ 04 } 00
+# 0000020 02 P 00 00 80 00 ) a8 04 } 00 C Y L I N
+# 0000030 D R I C A L F A T 1 6 fa 8c
+
+if(! ~ $#* 1) {
+ echo 'usage: isfat /dev/sdC0/part' >[1=2]
+ exit usage
+}
+
+arg=$1
+fn fat {
+ cmp -s <{dd -if $arg -bs 1 -count 3 -skip $1 >[2]/dev/null} <{echo -n FAT}
+}
+
+fat 54 || fat 82
+exit $status
+
diff --git a/rc/bin/pc/personalize b/rc/bin/pc/personalize
new file mode 100755
index 000000000..d5112de34
--- /dev/null
+++ b/rc/bin/pc/personalize
@@ -0,0 +1,7 @@
+#!/bin/rc
+
+switch($#*){
+case 1
+ user=$1
+}
+disk/mkfs -s /n/emelie /sys/lib/sysconfig/proto/usrproto
diff --git a/rc/bin/pc/setup.9fat b/rc/bin/pc/setup.9fat
new file mode 100755
index 000000000..a6f470316
--- /dev/null
+++ b/rc/bin/pc/setup.9fat
@@ -0,0 +1,33 @@
+#!/bin/rc
+
+rfork e
+if(! ~ $#* 2) {
+ echo 'usage: setup.9fat /dev/sdC0/9fat plan9.ini' >[1=2]
+ exit usage
+}
+
+. /rc/bin/pc/defs
+fat=$1
+ini=$2
+if(! test -f $fat) {
+ echo fat partition not found >[1=2]
+ exit fat
+}
+if(! test -f $ini) {
+ echo plan9.ini not found >[1=2]
+ exit ini
+}
+
+if(pc/isfat $fat) {
+ echo 'Already a FAT partition in '^$fat^'; ream it?'
+ prompt 'ream 9fat' y n
+ switch($rd) {
+ case n
+ exit
+ }
+}
+
+disk/format -r 2 -d -b /386/pbs $fat /386/9load /386/9pcdisk
+mount -c /srv/dos /n/9fat $fat
+cp $ini /n/9fat/plan9.ini
+unmount /n/9fat
diff --git a/rc/bin/pc/setup.disk b/rc/bin/pc/setup.disk
new file mode 100755
index 000000000..87330895f
--- /dev/null
+++ b/rc/bin/pc/setup.disk
@@ -0,0 +1,37 @@
+#!/bin/rc
+
+rfork e
+
+if(! ~ $#* 2) {
+ echo 'usage: setup.disk /dev/sdC0 plan9.ini' >[1=2]
+ exit usage
+}
+
+disk=$1
+ini=$2
+if(! test -d $disk) {
+ echo disk directory not found >[1=2]
+ exit fat
+}
+if(! test -f $ini) {
+ echo plan9.ini not found >[1=2]
+ exit ini
+}
+
+
+disk/fdisk -wa $disk/data
+if(! test -f $disk/plan9) {
+ echo could not create plan 9 partition >[1=2]
+ exit noplan9
+}
+
+disk/prep -cwa $disk/plan9
+if(! test -f $disk/fs) {
+ echo did not create fs partition '(weird)' >[1=2]
+ exit nofs
+}
+
+disk/kfs -rb4096 -f $disk/fs
+pc/setup.9fat $disk/9fat $ini
+pc/update
+pc/personalize
diff --git a/rc/bin/pc/update b/rc/bin/pc/update
new file mode 100755
index 000000000..5b1cd9853
--- /dev/null
+++ b/rc/bin/pc/update
@@ -0,0 +1,20 @@
+#!/bin/rc
+
+if(~ $#fileserver 0) {
+ echo set '$fileserver' >[1=2]
+ exit no
+}
+if(~ $fileserver kfs) {
+ echo pc/update shouldn''''t be run from kfs >[1=2]
+ echo 'run:' >[1=2]
+ echo ' fileserver=network-server pc/update' >[1=2]
+ exit no
+}
+flag e +
+echo updating files
+9fs $fileserver
+disk/mkfs -s /n/$fileserver /n/$fileserver/sys/lib/sysconfig/proto/portproto
+9fat:
+cp /n/$fileserver/386/9pcdisk /n/9fat/9pcdisk
+cp /n/$fileserver/386/9load /n/9fat/9load
+unmount /n/9fat