mkroot 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #!/bin/sh -e
  2. sinfo() {
  3. echo ${BASH:+-e} "\033[1;33;41m$@\033[0m"
  4. }
  5. # Must have root directory as an argument
  6. if [ -z "$1" -o \( -n "$2" -a "$2" != fresh \) ]; then
  7. echo "$0 <livecd root> [fresh]"
  8. exit 1
  9. fi
  10. # Variables
  11. FROM=`dirname $0`
  12. LIVECD=$1
  13. # MIRROR=http://mirrors.kernel.org/gentoo
  14. MIRROR=http://distfiles.gentoo.org
  15. stage3base=${MIRROR}/releases/x86/autobuilds
  16. portage=${MIRROR}/snapshots/portage-latest.tar.bz2
  17. # GPG keys used at bulid-time
  18. gpg_keys=`sed '/^#/d; /^$/d; s/ //g' ${FROM}/conf/pubkeys`
  19. if [ "$2" != fresh -a -d ${LIVECD}/src ]; then
  20. sinfo "Skipping overwrite of ${LIVECD}/src (use \"fresh\")"
  21. exit
  22. fi
  23. # Extract stage3 + portage snapshot to fresh directory
  24. # Download stage3 + portage snapshot
  25. mkdir -p ${LIVECD}/mirror/stage3 ${LIVECD}/mirror/portage
  26. mkdir -p -m 700 ${LIVECD}/mirror/gnupg
  27. sinfo "Testing for required utilities"
  28. if ! type gpg 1>/dev/null 2>&1; then
  29. echo "Please install GnuPG"
  30. exit 1
  31. fi
  32. sinfo "Testing security labels and user xattrs support"
  33. touch ${LIVECD}/mirror/fs-test
  34. if ! setcap cap_net_raw+i ${LIVECD}/mirror/fs-test || \
  35. ! setfattr -n user.test ${LIVECD}/mirror/fs-test; then
  36. echo "Filesystem does not support extended attributes."
  37. echo "Try ext4 with EXT4_FS_SECURITY and -o user_xattr"
  38. echo "(make sure attr / libpcap are installed)"
  39. exit 1
  40. fi
  41. rm ${LIVECD}/mirror/fs-test
  42. # latest-stage3-i686.txt contains YYYYMMDD/stage3-i686-YYYYMMDD.tar.bz2
  43. sinfo "Fetching latest-stage3.txt"
  44. wget -N -nv -P ${LIVECD}/mirror/stage3 ${stage3base}/latest-stage3-i686.txt
  45. stage3=`grep stage3-i686 ${LIVECD}/mirror/stage3/latest-stage3-i686.txt`
  46. stage3file=`basename ${stage3}`
  47. # If a new stage3 is available, remove old mirrors
  48. if [ ! -e ${LIVECD}/mirror/stage3/${stage3file} ]; then
  49. rm -f ${LIVECD}/mirror/stage3/stage3-i686-*.tar.bz2*
  50. fi
  51. sinfo "Downloading ${stage3file}"
  52. wget -c -nv -P ${LIVECD}/mirror/stage3 \
  53. ${stage3base}/${stage3}.DIGESTS.asc \
  54. ${stage3base}/${stage3}.CONTENTS \
  55. ${stage3base}/${stage3}
  56. sinfo "Downloading portage-latest.tar.bz2"
  57. wget -N -nv -P ${LIVECD}/mirror/portage ${portage}.gpgsig ${portage}
  58. sinfo "Verifying PGP keys fingerprints"
  59. for key in ${gpg_keys}; do
  60. org=`echo ${key} | cut -d: -f1`
  61. fpr=`echo ${key} | cut -d: -f2`
  62. keyid=`echo -n ${fpr} | tail -c -8`
  63. gpg -q --homedir ${LIVECD}/mirror/gnupg --no-default-keyring \
  64. --keyring ${org}.gpg --import ${FROM}/conf/certs/${org}-${keyid}.asc
  65. fpr2=`gpg -q --homedir ${LIVECD}/mirror/gnupg --keyring ${org}.gpg \
  66. --fingerprint --with-colons 0x${fpr} | sed -n '/^fpr:/p' | cut -d: -f10`
  67. if [ ${fpr} != "${fpr2}" ]; then
  68. echo "Fingerprint mismatch: [${fpr}] != [${fpr2}]"
  69. exit 1
  70. fi
  71. done
  72. for keyring in `echo "${gpg_keys}" | cut -d: -f1 | sort -u`; do
  73. keyids=`gpg -q -k --homedir ${LIVECD}/mirror/gnupg --keyring ${keyring}.gpg \
  74. --fingerprint --with-colons | sed -n '/^fpr:/p' | cut -d: -f10 | sort`
  75. expids=`echo "${gpg_keys}" | sed -n "/^${keyring}:/p" | cut -d: -f2 | sort`
  76. if [ "${keyids}" != "${expids}" ]; then
  77. echo "Unexpected public keys in keyring ${keyring}.gpg"
  78. exit 1
  79. fi
  80. done
  81. sinfo "Verifying stage3 and portage snapshot PGP signatures"
  82. gpg -q --homedir ${LIVECD}/mirror/gnupg --trust-model always --keyring gentoo.gpg \
  83. --verify ${LIVECD}/mirror/stage3/${stage3file}.DIGESTS.asc
  84. gpg -q --homedir ${LIVECD}/mirror/gnupg --trust-model always --keyring gentoo.gpg \
  85. --verify ${LIVECD}/mirror/portage/portage-latest.tar.bz2.gpgsig \
  86. ${LIVECD}/mirror/portage/portage-latest.tar.bz2
  87. sinfo "Verifying stage3 SHA512 digests"
  88. sed '/^# WHIRLPOOL HASH$/{N; s/.*/\n/}' ${LIVECD}/mirror/stage3/${stage3file}.DIGESTS.asc \
  89. | (cd ${LIVECD}/mirror/stage3; sha512sum -c)
  90. sinfo "Removing ${LIVECD}/src"
  91. chattr -f -a ${LIVECD}/src/tmp/.private || :
  92. rm -rf --one-file-system ${LIVECD}/src
  93. mkdir -m 755 ${LIVECD}/src
  94. sinfo "Extracting stage3 to ${LIVECD}/src"
  95. tar -xpSjf ${LIVECD}/mirror/stage3/${stage3file} -C ${LIVECD}/src --exclude './dev/*'
  96. sinfo "Extracting portage to ${LIVECD}/src/usr"
  97. tar -xpSjf ${LIVECD}/mirror/portage/portage-latest.tar.bz2 -C ${LIVECD}/src/usr
  98. sinfo "Done."