conf.rc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/rc
  2. # the fossil configuration is stored at the 127kB offset in the disk
  3. # and extends for at most 1 kB.
  4. rfork e
  5. fn usage {
  6. echo 'usage: fossil/conf [-w] /dev/sdC0/fossil [config]' >[1=2]
  7. exit usage
  8. }
  9. wflag=no
  10. while(! ~ $#* 0 && ~ $1 -* && ! ~ $1 --){
  11. switch($1){
  12. case -w
  13. wflag=yes
  14. case *
  15. usage
  16. }
  17. shift
  18. }
  19. if(~ $1 --)
  20. shift
  21. if(~ $wflag no && ! ~ $#* 1)
  22. usage
  23. if(~ $wflag yes && ! ~ $#* 1 2)
  24. usage
  25. disk=$1
  26. if(! test -f $disk){
  27. echo 'unknown disk' $1 >[1=2]
  28. exit nodisk
  29. }
  30. fn sigexit {
  31. rm -f /tmp/fossilconf.$pid
  32. }
  33. if(~ $wflag yes){
  34. {echo fossil config; cat $2} >/tmp/fossilconf.$pid || exit oops
  35. if(! test -s /tmp/fossilconf.$pid){
  36. echo 'config is empty; will not install' >[1=2]
  37. exit emptyconfig
  38. }
  39. if(test `{ls -l /tmp/fossilconf.$pid | awk '{print $6}'} -gt 1024){
  40. echo 'config is too long; max is a little less than a kilobyte' >[1=2]
  41. exit toolong
  42. }
  43. dd -quiet 1 -bs 1024 -count 1 -if $disk -iseek 127 \
  44. >/tmp/_fossilconf.old || exit backup
  45. dd -quiet 1 -count 2 </dev/zero >>/tmp/fossilconf.$pid || exit dd
  46. dd -quiet 1 -bs 1024 -count 1 -if /tmp/fossilconf.$pid \
  47. -trunc 0 -of $disk -oseek 127 || exit dd2
  48. exit 0
  49. }
  50. dd -quiet 1 -bs 1024 -count 1 -if $disk -iseek 127 |
  51. aux/zerotrunc >/tmp/fossilconf.$pid
  52. if(! cmp -s <{sed 1q /tmp/fossilconf.$pid} <{echo fossil config}){
  53. echo 'config has bad header' >[1=2]
  54. exit badconfig
  55. }
  56. sed 1d /tmp/fossilconf.$pid
  57. exit 0