02-enter-chroot-tools 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #!/bin/bash
  2. # temel sistemin bash i yapılmadan önce kullanılacak.
  3. # http://www.linuxfromscratch.org/lfs/view/development/chapter06/chroot.html
  4. # http://www.linuxfromscratch.org/lfs/view/development/chapter06/kernfs.html#ch-system-kernfsmount
  5. # https://notabug.org/dragora/dragora/src/master/enter-chroot
  6. hata_olustu(){
  7. echo $1
  8. exit 1
  9. }
  10. [ -z $ONSISTEM_CHROOT ] && hata_olustu "ONSISTEM_CHROOT tanmlı değil!"
  11. [ ! -d $ONSISTEM_CHROOT/tools ] && hata_olustu "$ONSISTEM_CHROOT/tools dizini mevcut değil!"
  12. # Herhangi bir hatada çıkış için
  13. set -e
  14. LC_ALL=C
  15. export LC_ALL
  16. unmount_ortam()
  17. {
  18. for node in "${ONSISTEM_CHROOT}/sources" \
  19. "${ONSISTEM_CHROOT}/sys" \
  20. "${ONSISTEM_CHROOT}/proc" \
  21. "${ONSISTEM_CHROOT}/dev/pts" \
  22. "${ONSISTEM_CHROOT}/dev" \
  23. "${ONSISTEM_CHROOT}/run" ; \
  24. do
  25. if mount | grep -q "$node"
  26. then
  27. echo "Çözülüyor ${node} ..."
  28. if ! umount "$node"
  29. then
  30. echo "Sorunlu $node çözülüyor ..."
  31. umount -l "$node"
  32. fi
  33. fi
  34. done
  35. }
  36. # chroot girerken eski bağlar temizlenir.
  37. unmount_ortam
  38. # chroot için gerekli dizinlerin oluşturulması
  39. # Create required directory for destination
  40. mkdir -p -- "${ONSISTEM_CHROOT}/dev" \
  41. "${ONSISTEM_CHROOT}/dev/pts" \
  42. "${ONSISTEM_CHROOT}/proc" \
  43. "${ONSISTEM_CHROOT}/sys" \
  44. "${ONSISTEM_CHROOT}/run" \
  45. "${ONSISTEM_CHROOT}/sources"
  46. if [ -h $ONSISTEM_CHROOT/dev/shm ]; then
  47. mkdir -pv $ONSISTEM_CHROOT/$(readlink $ONSISTEM_CHROOT/dev/shm)
  48. fi
  49. rm -f ${ONSISTEM_CHROOT}/dev/console
  50. rm -f ${ONSISTEM_CHROOT}/dev/null
  51. mknod -m 600 ${ONSISTEM_CHROOT}/dev/console c 5 1
  52. mknod -m 666 ${ONSISTEM_CHROOT}/dev/null c 1 3
  53. echo "Chroot ortamı bağlanıyor..."
  54. mount -v --bind /dev $ONSISTEM_CHROOT/dev
  55. mount -vt devpts devpts $ONSISTEM_CHROOT/dev/pts -o gid=5,mode=620
  56. mount -vt proc proc $ONSISTEM_CHROOT/proc
  57. mount -vt sysfs sysfs $ONSISTEM_CHROOT/sys
  58. mount -vt tmpfs tmpfs $ONSISTEM_CHROOT/run
  59. mount -o bind "/sources" "$ONSISTEM_CHROOT/sources"
  60. _MPS_PATH="/tools/share/mps"
  61. # mps nin tools içine kopyalanması
  62. if [ ! -d $ONSISTEM_CHROOT/${_MPS_PATH} ];then
  63. mkdir -p $ONSISTEM_CHROOT/${_MPS_PATH}
  64. cp -rf $MPS_PATH/* $ONSISTEM_CHROOT/${_MPS_PATH}/
  65. fi
  66. # temel dosya sistemi için betik ataması
  67. if [ -d $ONSISTEM_CHROOT/tools/bin ];then
  68. cp -f $PWD/03-* $ONSISTEM_CHROOT/tools/bin/
  69. cp -f $PWD/04-* $ONSISTEM_CHROOT/tools/bin/
  70. cp -f $PWD/05-* $ONSISTEM_CHROOT/tools/bin/
  71. fi
  72. _TALIMATNAME="/tools/share/talimatname"
  73. # temel sistem talimatlarının yüklenmesi
  74. if [ ! -d $ONSISTEM_CHROOT/${_TALIMATNAME}/1 ];then
  75. mkdir -p $ONSISTEM_CHROOT/${_TALIMATNAME}
  76. if [ -d ${MILIS_REPO}/talimatname/1 ];then
  77. cp -rf ${MILIS_REPO}/talimatname/1 $ONSISTEM_CHROOT/${_TALIMATNAME}/
  78. echo "temel sistem talimatları kopyalandı."
  79. else
  80. echo "$TALIMATNAME/1 bulunamadı"
  81. fi
  82. fi
  83. # önsisteme wget kurulduysa sertifika ve resolv.conf ayarlarının kopyalanması
  84. [ -d $ONSISTEM_CHROOT/tools/etc/ssl/certs/ ] && \
  85. [ -f /etc/ssl/certs/ca-certificates.crt ] && \
  86. cp -fv /etc/ssl/certs/ca-certificates.crt $ONSISTEM_CHROOT/tools/etc/ssl/certs/
  87. cp -fv /etc/resolv.conf $ONSISTEM_CHROOT/tools/etc/
  88. # bin dir
  89. mkdir -p $ONSISTEM_CHROOT/tools/share/bin
  90. [ -d ${MILIS_REPO}/bin ] && cp -rvf ${MILIS_REPO}/bin/* $ONSISTEM_CHROOT/tools/share/bin/
  91. # ayarlar dir
  92. mkdir -p $ONSISTEM_CHROOT/tools/share/ayarlar
  93. [ -d ${MILIS_REPO}/ayarlar ] && cp -rvf ${MILIS_REPO}/ayarlar/* $ONSISTEM_CHROOT/tools/share/ayarlar/
  94. # rsync.static
  95. if [ -f ${MILIS_REPO}/ayarlar/onsistem/rsync.static ];then
  96. cp -f ${MILIS_REPO}/ayarlar/onsistem/rsync.static $ONSISTEM_CHROOT/tools/bin/rsync
  97. chmod +x $ONSISTEM_CHROOT/tools/bin/rsync
  98. fi
  99. # Çıkışları yakalamak için bash tuzak(trap) eklenir.
  100. trap 'echo ; unmount_ortam' EXIT HUP QUIT ABRT TERM
  101. chroot "$ONSISTEM_CHROOT" /tools/bin/env -i \
  102. HOME=/root \
  103. TERM="$TERM" \
  104. PS1='(temel) \u:\w\$ ' \
  105. MPS_PATH=${_MPS_PATH} \
  106. TALIMATNAME="/usr/milis/talimatname" \
  107. PATH=${_MPS_PATH}/bin:/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin:/tools/sbin \
  108. USER=root \
  109. /tools/bin/bash --login +h