init.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. ##
  2. ## Copyright (c) 2014 Minoca Corp. All Rights Reserved.
  3. ##
  4. ## Script Name:
  5. ##
  6. ## init.sh
  7. ##
  8. ## Abstract:
  9. ##
  10. ## This script performs user mode initialization.
  11. ##
  12. ## Author:
  13. ##
  14. ## Evan Green 20-Dec-2014
  15. ##
  16. ## Environment:
  17. ##
  18. ## Minoca OS
  19. ##
  20. ##
  21. ## Define the location to set up and ultimately chroot into. If such a world
  22. ## does not exist, then try to fire up a shell directly.
  23. ##
  24. if test -z "$WORLD"; then
  25. WORLD="apps"
  26. fi
  27. if ! test -d "$WORLD"; then
  28. if test -z "$CONSOLE"; then
  29. CONSOLE=/Terminal/Slave0
  30. fi
  31. 0<>$CONSOLE
  32. 1>$CONSOLE
  33. 2>$CONSOLE
  34. export LD_LIBRARY_PATH=$PWD
  35. exec $PWD/swiss sh -i
  36. fi
  37. ##
  38. ## Set up some working environment variables.
  39. ##
  40. export LD_LIBRARY_PATH="$PWD/$WORLD/lib"
  41. export PATH="$PWD/$WORLD/bin"
  42. ##
  43. ## Mount the special devices if needed.
  44. ##
  45. if ! test -c "$WORLD/dev/null"; then
  46. mkdir -p "$WORLD/dev"
  47. touch "$WORLD/dev/null"
  48. touch "$WORLD/dev/full"
  49. touch "$WORLD/dev/zero"
  50. touch "$WORLD/dev/urandom"
  51. touch "$WORLD/dev/console"
  52. touch "$WORLD/dev/tty"
  53. mkdir -p "$WORLD/dev/Volume"
  54. mkdir -p "$WORLD/dev/Terminal"
  55. mount --bind "/Device/null" "$WORLD/dev/null"
  56. mount --bind "/Device/full" "$WORLD/dev/full"
  57. mount --bind "/Device/zero" "$WORLD/dev/zero"
  58. mount --bind "/Device/urandom" "$WORLD/dev/urandom"
  59. mount --bind "/Device/tty" "$WORLD/dev/tty"
  60. mount --bind "/Terminal/Slave0" "$WORLD/dev/console"
  61. mount --bind "/Volume" "$WORLD/dev/Volume"
  62. mount --bind "/Terminal" "$WORLD/dev/Terminal"
  63. fi
  64. ##
  65. ## Set up the home environment.
  66. ##
  67. mkdir -p "$WORLD/root" \
  68. "$WORLD/var/run" \
  69. "$WORLD/var/log" \
  70. "$WORLD/home"
  71. export HOME="/root"
  72. export TERM=xterm
  73. ##
  74. ## Clean out the tmp directory.
  75. ##
  76. rm -rf "$WORLD/tmp"
  77. mkdir -p -m777 "$WORLD/tmp"
  78. ##
  79. ## Symlink swiss binaries.
  80. ##
  81. if ! test -x $WORLD/bin/chroot; then
  82. ##
  83. ## If there is no swiss, link sh to swiss (hopefully that works). Pipes
  84. ## don't really work at this point.
  85. ##
  86. if ! test -r $WORLD/bin/swiss ; then
  87. ln -s sh $WORLD/bin/swiss
  88. fi
  89. for app in `swiss --list`; do
  90. if ! test -x $WORLD/bin/$app; then
  91. ln -s swiss $WORLD/bin/$app
  92. fi
  93. done
  94. fi
  95. ##
  96. ## Run the final user shell.
  97. ##
  98. exec $WORLD/bin/chroot "$WORLD" -- /bin/init