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.

125 lines
3.2 KiB

  1. #!/bin/sh
  2. # Copyright 2018 Roger Shimizu <rosh@debian.org>
  3. #
  4. # This is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 3 of the License, or
  7. # (at your option) any later version.
  8. set -e
  9. help_usage() {
  10. cat << EOT
  11. Call build_deb.sh script in a chrooted environment
  12. Usage:
  13. sudo $(basename $0) [--help|-h] [codename]
  14. --help|-h Show this usage.
  15. [code name] Debian/Ubuntu release codename
  16. e.g. jessie/stretch/trusty/xenial
  17. EOT
  18. exit
  19. }
  20. # POSIX-compliant maint function recommend by devref
  21. # to check for the existence of a command
  22. # https://www.debian.org/doc/manuals/developers-reference/ch06.html#bpp-debian-maint-scripts
  23. pathfind() {
  24. OLDIFS="$IFS"
  25. IFS=:
  26. for p in $PATH; do
  27. if [ -x "$p/$*" ]; then
  28. IFS="$OLDIFS"
  29. return 0
  30. fi
  31. done
  32. IFS="$OLDIFS"
  33. return 1
  34. }
  35. case "$1" in
  36. wheezy|precise)
  37. echo Sorry, the system $1 is not supported.
  38. ;;
  39. jessie|stretch|buster|testing|unstable|sid)
  40. OSID=debian
  41. REPO=http://deb.debian.org/debian
  42. ;;
  43. trusty|yakkety|zesty|xenial|artful|bionic)
  44. OSID=ubuntu
  45. REPO=http://archive.ubuntu.com/ubuntu
  46. ;;
  47. --help|-h|*)
  48. help_usage
  49. esac
  50. if ! pathfind debootstrap; then
  51. echo Please install debootstrap package.
  52. exit 1
  53. fi
  54. OSVER=$1
  55. CHROOT=/tmp/${OSVER}-build-$(date +%Y%m%d%H%M)
  56. TIMESTAMP0=$(date)
  57. mkdir -p ${CHROOT}/etc
  58. echo en_US.UTF-8 UTF-8 > ${CHROOT}/etc/locale.gen
  59. if ! debootstrap --variant=minbase --include=ca-certificates,git,sudo,wget,whiptail --exclude=upstart,systemd $OSVER $CHROOT $REPO; then
  60. echo debootstrap failed. Please kindly check whether proper sudo or not.
  61. exit 1
  62. fi
  63. case "$OSID" in
  64. debian)
  65. echo deb $REPO ${OSVER} main > ${CHROOT}/etc/apt/sources.list
  66. echo deb $REPO ${OSVER}-updates main >> ${CHROOT}/etc/apt/sources.list
  67. echo deb $REPO-security ${OSVER}/updates main >> ${CHROOT}/etc/apt/sources.list
  68. ;;
  69. ubuntu)
  70. echo deb $REPO $OSVER main universe > ${CHROOT}/etc/apt/sources.list
  71. echo deb $REPO ${OSVER}-updates main universe >> ${CHROOT}/etc/apt/sources.list
  72. echo deb $REPO ${OSVER}-security main universe >> ${CHROOT}/etc/apt/sources.list
  73. ;;
  74. esac
  75. cat << EOL | chroot $CHROOT
  76. apt-get purge -y udev
  77. apt-get update
  78. apt-get -fy install
  79. apt-get -y upgrade
  80. apt-get -y install --no-install-recommends lsb-release
  81. # dh_auto_test of mbedtls (faketime) depends on /dev/shm. https://bugs.debian.org/778462
  82. mkdir -p ~ /dev/shm
  83. mount tmpfs /dev/shm -t tmpfs
  84. date > /TIMESTAMP1
  85. git config --global user.email "script@example.com"
  86. git config --global user.name "build script"
  87. if [ -n "$http_proxy" ]; then
  88. git config --global proxy.http $http_proxy
  89. echo Acquire::http::Proxy \"$http_proxy\"\; > /etc/apt/apt.conf
  90. export http_proxy=$http_proxy
  91. export https_proxy=$https_proxy
  92. export no_proxy=$no_proxy
  93. fi
  94. cd /tmp
  95. wget https://raw.githubusercontent.com/shadowsocks/shadowsocks-libev/master/scripts/build_deb.sh
  96. chmod 755 build_deb.sh
  97. ./build_deb.sh
  98. date > /TIMESTAMP2
  99. ./build_deb.sh kcp
  100. umount /dev/shm
  101. EOL
  102. TIMESTAMP1=$(cat ${CHROOT}/TIMESTAMP1)
  103. TIMESTAMP2=$(cat ${CHROOT}/TIMESTAMP2)
  104. TIMESTAMP3=$(date)
  105. printf \\n"All built deb packages:"\\n
  106. ls -l ${CHROOT}/tmp/*.deb
  107. echo
  108. echo Start-Time: $TIMESTAMP0
  109. echo ChrootDone: $TIMESTAMP1
  110. echo SsDeb-Done: $TIMESTAMP2
  111. echo \ Kcp-Done : $TIMESTAMP3