1
0

loadfossil 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/bin/rc
  2. # loadfossil - populate a fossil partition or file
  3. #
  4. # due to name clashes in /srv, will only work on a machine
  5. # without a fossil named `fossil' already running.
  6. rfork en
  7. fn killfossil {
  8. sleep 1
  9. unmount /n/f &
  10. sleep 1
  11. rm -f /srv/^(fossil fossil.open fscons fscons.open)
  12. kill fossil | rc
  13. sleep 1
  14. }
  15. fn sendexpect { # send expect timeout
  16. echo $1
  17. if(! dial/expect -qt $3 $2)
  18. echo -n 'no '^$"1^'...' > /dev/cons
  19. }
  20. fn usage {
  21. echo usage: $argv0 partition root proto fossil.conf >[1=2]
  22. exit usage
  23. }
  24. fn sigexit {
  25. rm -f /tmp/fossil-no-list.conf
  26. exit
  27. }
  28. fn sigint sighup sigterm {
  29. rm -f /tmp/fossil-no-list.conf
  30. killfossil
  31. exit note
  32. }
  33. # process arguments
  34. if (! ~ $#* 4)
  35. usage
  36. argv0=$0
  37. fosspart=$1
  38. srcroot=$2
  39. proto=$3
  40. fossconf=$4
  41. if (test -e /srv/fossil -o -e /srv/fossil.open) {
  42. echo $0: /srv/fossil* exists, not safe to start a new fossil >[1=2]
  43. exit fossil-already-running
  44. }
  45. # initialise fossil
  46. fossil/flfmt -y $fosspart
  47. # install listen-less config for fossil creation
  48. {
  49. grep -v '^listen ' $fossconf
  50. echo create /active/adm adm sys d775
  51. echo create /active/adm/users adm sys 664
  52. } >/tmp/fossil-no-list.conf
  53. fossil/conf -w $fosspart /tmp/fossil-no-list.conf
  54. # start fossil
  55. fossil/fossil -f $fosspart
  56. mount -cC /srv/fossil.open /n/f
  57. # set up /adm/users
  58. cp /adm/users /n/f/adm
  59. {
  60. echo
  61. dial/drain &
  62. sleep 2
  63. sendexpect 'users -r /active/adm/users' ': ' 5
  64. } </srv/fscons.open >>/srv/fscons.open
  65. # remount with new users
  66. unmount /n/f
  67. mount -cC /srv/fossil.open /n/f
  68. # populate fossil
  69. @ {
  70. # logs are boring, make them all appear empty
  71. chmod +arw /tmp/empty-log >/tmp/empty-log
  72. cd $srcroot/sys/log && {
  73. for (f in [0-9a-z]* */*)
  74. if (! ~ $f httpd mkfile smtpdb timesync.d vac year)
  75. bind /tmp/empty-log $f
  76. }
  77. cd /tmp
  78. disk/mkfs -u $srcroot/adm/users -U -d /n/f -s $srcroot $proto
  79. }
  80. # stop fossil gracefully
  81. {
  82. echo
  83. dial/drain &
  84. sleep 2
  85. sendexpect 'fsys all sync' ': ' 120
  86. sendexpect 'fsys all halt' ': ' 5
  87. } </srv/fscons.open >>/srv/fscons.open
  88. killfossil
  89. # install permanent fossil configuration
  90. fossil/conf -w $fosspart $fossconf