Dragora - an independent GNU/Linux-Libre distribution based on concepts of simplicity
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
3.8 KiB

  1. #! /bin/sh -
  2. # Copyright (c) 2016-2018 Matias Fonzo, <selk@dragora.org>.
  3. # Copyright (c) 2020-2021 Matias Fonzo, <selk@dragora.org>.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. PROGRAM="${0##*/}"
  17. # Exit immediately on any error
  18. set -e
  19. # Override locale settings
  20. LC_ALL=C
  21. export LC_ALL
  22. # Get current working directory
  23. CWD="$(dirname -- "$0")"
  24. # Functions
  25. unmountSeries()
  26. {
  27. for node in "${rootdir}/usr/src/qi/archive" \
  28. "${rootdir}/usr/src/qi/patches" \
  29. "${rootdir}/usr/src/qi/recipes" \
  30. "${rootdir}/usr/src/qi/sources" \
  31. "${rootdir}/sys" \
  32. "${rootdir}/proc" \
  33. "${rootdir}/dev/pts" \
  34. "${rootdir}/dev" ; \
  35. do
  36. if mount | grep -q "$node"
  37. then
  38. echo "Unmounting ${node} ..."
  39. if ! umount "$node"
  40. then
  41. echo "Doing a lazy unmount for $node ..."
  42. umount -l "$node"
  43. fi
  44. fi
  45. done
  46. unset node
  47. }
  48. # Autodetermine the path of /tools
  49. if test ! -L /tools
  50. then
  51. echo "${PROGRAM}: cannot determine ${rootdir}: /tools does not exist as symlink" 1>&2
  52. exit 1
  53. fi
  54. if test -L /tools -a ! -e /tools
  55. then
  56. echo "${PROGRAM}: cannot access /tools: Dangling symlink" 1>&2
  57. exit 1
  58. fi
  59. # Set canonical name to compose the root directory, removing
  60. # the last component from the path name "/tools"
  61. rootdir="$(CDPATH='' cd -P -- /tools && pwd -P)"
  62. rootdir="${rootdir%/*}"
  63. # Unmount directories and file systems before the next mounting
  64. unmountSeries
  65. # Create required directory for destination
  66. mkdir -p -- "${rootdir}/dev" \
  67. "${rootdir}/dev/pts" \
  68. "${rootdir}/proc" \
  69. "${rootdir}/sys" \
  70. "${rootdir}/usr/src/qi/archive" \
  71. "${rootdir}/usr/src/qi/patches" \
  72. "${rootdir}/usr/src/qi/recipes" \
  73. "${rootdir}/usr/src/qi/sources"
  74. echo "Mounting virtual file systems ..."
  75. mount -o bind /dev "${rootdir}/dev"
  76. mount -t devpts devpts "${rootdir}/dev/pts"
  77. mount -t proc proc "${rootdir}/proc"
  78. mount -t sysfs sysfs "${rootdir}/sys"
  79. echo "Binding directories to mount: archive, patches, recipes, sources ..."
  80. mount -o bind "${CWD}/archive" "${rootdir}/usr/src/qi/archive"
  81. mount -o bind "${CWD}/patches" "${rootdir}/usr/src/qi/patches"
  82. mount -o bind "${CWD}/recipes" "${rootdir}/usr/src/qi/recipes"
  83. mount -o bind "${CWD}/sources" "${rootdir}/usr/src/qi/sources"
  84. # Change reported architecture for an appropriate environment
  85. _machine_type=""
  86. if file /tools/bin/busybox | grep -q "32-bit"
  87. then
  88. echo "Using the linux32 command for this machine type: $(uname -m) ..."
  89. if command -v linux32 > /dev/null
  90. then
  91. _machine_type="linux32"
  92. else
  93. echo " The linux32 command is not available on your system." 1>&2
  94. fi
  95. fi
  96. # Add trap for unmount the series, signalled or not
  97. trap 'echo ""; unmountSeries' EXIT HUP QUIT ABRT TERM
  98. echo "Entering via chroot $rootdir ..."
  99. $_machine_type chroot "$rootdir" /tools/bin/env -i \
  100. PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin:/opt/trinity/bin \
  101. SHELL=/bin/sh \
  102. HOME=/root \
  103. TERM=linux \
  104. HOSTNAME=dragora \
  105. LC_ALL=C \
  106. PKG_CONFIG=/usr/bin/pkgconf \
  107. PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig:/opt/trinity/lib/pkgconfig \
  108. /bin/sh -