github.com/geofffranks/garden-linux@v0.0.0-20160715111146-26c893169cfa/linux_backend/bin/rootfs/ubuntu.sh (about) 1 #!/bin/bash 2 3 [ -n "$DEBUG" ] && set -o xtrace 4 set -o nounset 5 set -o errexit 6 shopt -s nullglob 7 shopt -s globstar 8 9 packages="openssh-server,rsync" 10 suite="lucid" 11 mirror=$(grep "^deb" /etc/apt/sources.list | head -n1 | cut -d" " -f2) 12 13 # Fallback to default Ubuntu mirror when mirror could not be determined 14 if [ -z "$mirror" ] 15 then 16 mirror="http://archive.ubuntu.com/ubuntu/" 17 fi 18 19 function debootstrap() { 20 # -v is too new, revert to old trick 21 # ${VAR+X} will be 22 # X when VAR is unset 23 # $VAR otherwise 24 # Only do this heuristic when http_proxy is unset 25 # You can opt out of this by setting http_proxy to nil 26 if [ -z ${http_proxy+X} ] 27 then 28 eval $(apt-config shell http_proxy Acquire::http::Proxy) 29 export http_proxy 30 fi 31 32 $(which debootstrap) --verbose --include $packages $suite $target $mirror 33 } 34 35 function write() { 36 [ -z "$1" ] && return 1 37 38 mkdir -p $target/$(dirname $1) 39 cat > $target/$1 40 } 41 42 function chroot() { 43 $(which chroot) $target env -i $(cat $target/etc/environment) /bin/bash 44 } 45 46 if [ $EUID -ne 0 ] 47 then 48 echo "Sorry, you need to be root." 49 exit 1 50 fi 51 52 if [ "$#" -ne 1 ] 53 then 54 echo "Usage: setup.sh [TARGET DIRECTORY]" 55 exit 1 56 fi 57 58 target=$1 59 60 if [ -d $target ] 61 then 62 read -p "Target directory already exists. Erase it? " 63 if [[ $REPLY =~ ^[Yy].*$ ]] 64 then 65 rm -rf $target 66 else 67 echo "Aborting..." 68 exit 1 69 fi 70 fi 71 72 mkdir -p $target 73 74 debootstrap 75 76 write "etc/apt/sources.list" <<-EOS 77 deb $mirror $suite main universe 78 deb $mirror $suite-updates main universe 79 EOS 80 81 # Disable interactive dpkg 82 chroot <<-EOS 83 echo debconf debconf/frontend select noninteractive | 84 debconf-set-selections 85 EOS 86 87 # Generate and setup default locale (en_US.UTF-8) 88 chroot <<-EOS 89 locale-gen en_US.UTF-8 90 update-locale LANG="en_US.UTF-8" 91 EOS 92 93 # Update packages 94 chroot <<-EOS 95 apt-get update 96 EOS 97 98 # Disable initctl so that apt cannot start any daemons 99 mv $target/sbin/initctl $target/sbin/initctl.real 100 ln -s /bin/true $target/sbin/initctl 101 trap "mv $target/sbin/initctl.real $target/sbin/initctl" EXIT 102 103 # Upgrade upstart 104 chroot <<-EOS 105 apt-get install -y upstart 106 EOS 107 108 # If upstart was upgraded, make sure to disable it again 109 if [ ! -h $target/sbin/initctl ] 110 then 111 mv $target/sbin/initctl $target/sbin/initctl.real 112 ln -s /bin/true $target/sbin/initctl 113 fi 114 115 # Upgrade everything 116 chroot <<-EOS 117 apt-get upgrade -y 118 EOS 119 120 # Install packages 121 chroot <<-EOS 122 apt-get install -y build-essential 123 EOS 124 125 # Remove files we don't need or want 126 chroot <<-EOS 127 rm -f /var/cache/apt/archives/*.deb 128 rm -f /var/cache/apt/*cache.bin 129 rm -f /var/lib/apt/lists/*_Packages 130 rm -f /etc/ssh/ssh_host_* 131 EOS