/dep/build_ssh.sh

https://github.com/NERSC/shifter · Shell · 136 lines · 115 code · 13 blank · 8 comment · 23 complexity · 101b1a36270c57ce7cfa8287f0d31ebf MD5 · raw file

  1. #!/bin/bash
  2. set -e
  3. unset CFLAGS
  4. unset CPPFLAGS
  5. unset LDFLAGS
  6. INST_PREFIX=${INST_PREFIX:-/opt/udiImage}
  7. SPRT_PREFIX=$( mktemp -d )
  8. PREFIX=$( mktemp -d )
  9. MUSL_VERSION=1.1.8
  10. LIBRESSL_VERSION=2.1.6
  11. ZLIB_VERSION=1.2.8
  12. OPENSSH_VERSION=6.8p1
  13. origdir=$( pwd )
  14. mkdir -p build
  15. cd build
  16. builddir=$( pwd )
  17. if [[ -z "$INST_PREFIX" || "$INST_PREFIX" == "/" ]]; then
  18. echo "Invalid installation target: $INST_PREFIX" 1>&2
  19. exit 1
  20. fi
  21. if [[ ! -e "musl-${MUSL_VERSION}.tar.gz" && -n "$DEPTAR_DIR" && -e "$DEPTAR_DIR/musl-${MUSL_VERSION}.tar.gz" ]]; then
  22. cp "$DEPTAR_DIR/musl-${MUSL_VERSION}.tar.gz" .
  23. fi
  24. if [[ ! -e "musl-${MUSL_VERSION}.tar.gz" ]]; then
  25. curl -o "musl-${MUSL_VERSION}.tar.gz" "http://www.musl-libc.org/releases/musl-${MUSL_VERSION}.tar.gz"
  26. fi
  27. if [[ ! -e "libressl-${LIBRESSL_VERSION}.tar.gz" && -n "$DEPTAR_DIR" && -e "$DEPTAR_DIR/libressl-${LIBRESSL_VERSION}.tar.gz" ]]; then
  28. cp "$DEPTAR_DIR/libressl-${LIBRESSL_VERSION}.tar.gz" .
  29. fi
  30. if [[ ! -e "libressl-${LIBRESSL_VERSION}.tar.gz" ]]; then
  31. curl -o "libressl-${LIBRESSL_VERSION}.tar.gz" "http://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-${LIBRESSL_VERSION}.tar.gz"
  32. fi
  33. if [[ ! -e "zlib-${ZLIB_VERSION}.tar.gz" && -n "$DEPTAR_DIR" && -e "$DEPTAR_DIR/zlib-${ZLIB_VERSION}.tar.gz" ]]; then
  34. cp "$DEPTAR_DIR/zlib-${ZLIB_VERSION}.tar.gz" .
  35. fi
  36. if [[ ! -e "zlib-${ZLIB_VERSION}.tar.gz" ]]; then
  37. curl -o "zlib-${ZLIB_VERSION}.tar.gz" "http://zlib.net/fossils/zlib-${ZLIB_VERSION}.tar.gz"
  38. fi
  39. if [[ ! -e "openssh-${OPENSSH_VERSION}.tar.gz" && -n "$DEPTAR_DIR" && -e "$DEPTAR_DIR/openssh-${OPENSSH_VERSION}.tar.gz" ]]; then
  40. cp "$DEPTAR_DIR/openssh-${OPENSSH_VERSION}.tar.gz" .
  41. fi
  42. if [[ ! -e "openssh-${OPENSSH_VERSION}.tar.gz" ]]; then
  43. curl -o "openssh-${OPENSSH_VERSION}.tar.gz" "http://mirrors.sonic.net/pub/OpenBSD/OpenSSH/portable/openssh-${OPENSSH_VERSION}.tar.gz"
  44. fi
  45. mkdir -p musl
  46. tar xf "musl-${MUSL_VERSION}.tar.gz" -C musl --strip-components=1
  47. cd musl
  48. ./configure "--prefix=${SPRT_PREFIX}" --enable-static --disable-shared --enable-gcc-wrapper
  49. make
  50. make install
  51. cd "${builddir}"
  52. dirs="linux asm asm-generic x86_64-linux-gnu/asm"
  53. for dir in $dirs; do
  54. if [[ -e "/usr/include/$dir" ]]; then
  55. if [[ -L "/usr/include/$dir" ]]; then
  56. # SLES has symlinks for asm
  57. realpath=$(readlink -f "/usr/include/$dir")
  58. cp -rp "$realpath" "${SPRT_PREFIX}/include/"
  59. fi
  60. if [ ! -e "${SPRT_PREFIX}/include/$dir" ]; then
  61. cp -rp "/usr/include/$dir" "${SPRT_PREFIX}/include/"
  62. fi
  63. fi
  64. done
  65. cd "${builddir}"
  66. mkdir -p libressl
  67. tar xf "libressl-${LIBRESSL_VERSION}.tar.gz" -C libressl --strip-components=1
  68. cd libressl
  69. CC="${SPRT_PREFIX}/bin/musl-gcc" ./configure "--prefix=${SPRT_PREFIX}" --enable-static --disable-shared
  70. make
  71. make install
  72. cd "${builddir}"
  73. mkdir -p zlib
  74. tar xf "zlib-${ZLIB_VERSION}.tar.gz" -C zlib --strip-components=1
  75. cd zlib
  76. CC="${SPRT_PREFIX}/bin/musl-gcc" ./configure "--prefix=${SPRT_PREFIX}"
  77. make
  78. make install
  79. cd "${builddir}"
  80. mkdir -p openssh
  81. tar xf "openssh-${OPENSSH_VERSION}.tar.gz" -C openssh --strip-components=1
  82. cd openssh
  83. ## it is important to change PATH here so that the default PATH when ssh'd into
  84. ## the image is not infected with all kinds of silly paths (sshd sets PATH to
  85. ## very nearly the path it was built with)
  86. export PATH="/usr/bin:/bin"
  87. LDFLAGS="-L${SPRT_PREFIX}/lib -L${SPRT_PREFIX}/lib64" CC="${SPRT_PREFIX}/bin/musl-gcc" ./configure --without-pam "--with-ssl-dir=${SPRT_PREFIX}" --without-ssh1 --enable-static --disable-shared "--with-zlib=${SPRT_PREFIX}" "--prefix=${INST_PREFIX}"
  88. make
  89. make install "DESTDIR=${PREFIX}"
  90. cd "${builddir}"
  91. cat <<EOF > "${PREFIX}${INST_PREFIX}/etc/sshd_config"
  92. Port 1204
  93. StrictModes yes
  94. PermitRootLogin no
  95. AuthorizedKeysFile ${INST_PREFIX}/etc/user_auth_keys
  96. IgnoreUserKnownHosts yes
  97. PasswordAuthentication no
  98. ChallengeResponseAuthentication no
  99. X11Forwarding yes
  100. PermitUserEnvironment no
  101. UseDNS no
  102. Subsystem sftp ${INST_PREFIX}/libexec/sftp-server
  103. AcceptEnv PBS_HOSTFILE
  104. AcceptEnv SLURM_JOB_NODELIST
  105. AcceptEnv SLURM_NODELIST
  106. AcceptEnv BASIL_RESERVATION_ID
  107. ## The following is typically a bad practice -- but is ok here since all our security is
  108. ## to protect the system from the container not the other way around. Allowing all variables
  109. ## through should be safe within the clustered environment.
  110. AcceptEnv *
  111. AllowUsers ToBeReplaced
  112. EOF
  113. cat <<EOF > ${PREFIX}${INST_PREFIX}/etc/ssh_config
  114. Host *
  115. StrictHostKeyChecking no
  116. Port 1204
  117. IdentityFile ~/.udiRoot/id_rsa.key
  118. EOF
  119. cd "${PREFIX}"
  120. tar cf "${origdir}/udiRoot_dep.tar" .
  121. cd "${origdir}"
  122. rm -r "${PREFIX}"
  123. rm -r "${SPRT_PREFIX}"