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.

242 lines
4.3 KiB

  1. #!/bin/bash
  2. set -eux # -x for verbose logging to juju debug-log
  3. apt-get update
  4. apt-get -y install bash-completion wget bzip2 git-core less language-pack-en python-software-properties tmux mosh sudo git
  5. ## 0k git remote path
  6. GIT_0K_BASE=${GIT_0K_BASE:-"git.0k.io:/var/git"}
  7. ## 0k git remote options
  8. GIT_0K_CLONE_OPTIONS=${GIT_0K_CLONE_OPTIONS:-""}
  9. ##
  10. ## etckeeper
  11. ##
  12. apt-get install etckeeper
  13. sed -i 's/#VCS="git"/VCS="git"/g' /etc/etckeeper/etckeeper.conf
  14. sed -i 's/VCS="bzr"/#VCS="bzr"/g' /etc/etckeeper/etckeeper.conf
  15. etckeeper init
  16. ##
  17. ## Git utilities
  18. ##
  19. echo "[alias]
  20. co = checkout
  21. com = commit
  22. st = status
  23. ci = commit
  24. [color]
  25. branch = auto
  26. diff = auto
  27. interactive = auto
  28. status = auto
  29. " >> /etc/gitconfig
  30. ##
  31. ## kal-scripts
  32. ##
  33. cat <<EOF >> /etc/apt/sources.list
  34. ## vlab's shell libraries
  35. deb http://deb.kalysto.org no-dist kal-alpha kal-beta kal-main
  36. EOF
  37. ##
  38. ## More shell configurations (prompt, functions)
  39. ##
  40. mkdir -p /etc/prompt
  41. cat <<EOF > /etc/prompt/prompt.1.rc
  42. PROMPT_COMMAND=""
  43. parse_git_branch() {
  44. ref=\$(git symbolic-ref HEAD 2> /dev/null) || return
  45. echo -en ' (\033[0;32m'\${ref#refs/heads/}'\033[0m)'
  46. }
  47. export PS1="\[\033[0;37m\][\[\033[1;30m\]\u\[\033[0;37m\]@\[\033[1;30m\]\h\[\033[0;37m\]]-[\[\033[1;34m\]\w\[\033[0;37m\]]\\\$(parse_git_branch)\n\[\033[1;37m\]\\$ \[\033[0;37m\]"
  48. EOF
  49. cat <<EOF >> /root/.bashrc
  50. ## History management
  51. export HISTCONTROL=ignoredups
  52. export HISTSIZE=50000
  53. shopt -s histappend
  54. PROMPT_COMMAND='history -a'
  55. ## Prompt easy management
  56. prompt() {
  57. prompt_name="prompt.\$1.rc"
  58. for i in /etc/prompt ~/.prompt; do
  59. [ -f "\$i/\$prompt_name" ] &&
  60. . "\$i/\$prompt_name"
  61. done
  62. }
  63. ## Git log command
  64. function glog() {
  65. git log --graph --pretty=tformat:%C\(yellow\ normal\)%h%Creset\ %C\(blue\ normal\)%an%Creset\ %s\ %Cgreen%d%Creset -n 20 "\$@"
  66. }
  67. prompt 1
  68. EOF
  69. apt-get install -y kal-scripts python-pip
  70. pip install shyaml
  71. ##
  72. ## btrfs install
  73. ##
  74. apt-get install btrfs-tools
  75. root=/mnt/btrfs-root
  76. #mkdir /mnt/btrfs-root -p
  77. #mount /mnt/btrfs-root
  78. btrfs subvolume create $root/var
  79. mkdir $root/var/{lib,cache,backups} -p
  80. for d in $root/var/{lib,cache,backups}; do
  81. btrfs subvolume create $d/lxc
  82. done
  83. for d in $root/srv/{,lxc-datastore{,/config,/data}}; do
  84. btrfs subvolume create $d
  85. done
  86. mkdir srv/lxc
  87. cat <<EOF >> /etc/fstab
  88. ## binds
  89. /mnt/btrfs-root/var/lib/lxc /var/lib/lxc none bind,defaults,auto 0 0
  90. /mnt/btrfs-root/var/cache/lxc /var/cache/lxc none bind,defaults,auto 0 0
  91. /mnt/btrfs-root/var/backups/lxc /var/backups/lxc none bind,defaults,auto 0 0
  92. /mnt/btrfs-root/srv/lxc-datastore /srv/lxc-datastore none bind,defaults,auto 0 0
  93. EOF
  94. mkdir -p /var/backups/lxc /srv/lxc-datastore
  95. ##
  96. ## lxc tools
  97. ##
  98. apt-get install lxc
  99. ## mount all
  100. mkdir -p /opt/apps
  101. ##
  102. ## Install 0k-manage for the handy oe command
  103. ##
  104. (
  105. if ! [ -d "/opt/apps/0k-manage" ]; then
  106. cd /opt/apps &&
  107. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-manage.git" &&
  108. cd /opt/apps/0k-manage &&
  109. git checkout 0k/dev/master
  110. fi
  111. )
  112. ##
  113. ## Install 0k-charms
  114. ##
  115. (
  116. if ! [ -d "/opt/apps/0k-charms" ]; then
  117. cd /opt/apps &&
  118. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-charms.git" &&
  119. cd /opt/apps/0k-manage &&
  120. git checkout 0k/dev/master
  121. fi
  122. )
  123. ##
  124. ## Install lxc-scripts
  125. ##
  126. (
  127. if ! [ -d "/opt/apps/lxc-scripts" ]; then
  128. cd /opt/apps &&
  129. git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/lxc-scripts.git" &&
  130. cd /opt/apps/0k-manage &&
  131. git checkout master &&
  132. ln -sf /opt/apps/lxc-scripts/bin/lxc-* /usr/local/sbin/ &&
  133. ln -sf /opt/apps/lxc-scripts/usr/lib/lxc/templates/lxc-0k-ubuntu-cloud /usr/lib/lxc/templates/
  134. fi
  135. )
  136. ##
  137. ## Patch some files
  138. ##
  139. (
  140. cd /etc &&
  141. cat /opt/apps/lxc-scripts/precise-12.04.patch | patch -p1
  142. )
  143. ##
  144. ## Install dns waterfall
  145. ##
  146. apt-get install -y bind9 dnsmasq
  147. # edit /etc/dnsmaq.conf
  148. echo "
  149. server=$(. /etc/default/lxc && echo "$LXC_ADDR")
  150. interface=lo
  151. no-negcache
  152. log-queries
  153. log-facility=/var/log/dnsmasq.log
  154. " >> /etc/dnsmasq.conf
  155. (
  156. cd /etc &&
  157. cat src/bind9.patch | patch -p1 &&
  158. sed -ri s/%%EXTERNAL_IP%%/$(. /etc/default/lxc && ifip "$HOST_EXTERNAL_DEVICE")
  159. )
  160. mkdir /var/log/named -p &&
  161. chown bind:bind /var/log/named