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.
 
 
 

315 lines
9.0 KiB

  1. #!/bin/bash
  2. if [ "$IN_CHROOT" != "1" ] ; then
  3. echo This is supposed to run inside the chroot, oops
  4. exit 1
  5. fi
  6. set -e
  7. set -x
  8. try_install() {
  9. # try to install packages, but ignore failure
  10. for pkg in "$@"; do
  11. if ! apt-get -y install "$pkg" ; then
  12. echo ---- WARNING: Failed to install package: $pkg
  13. fi
  14. done
  15. }
  16. # Set up live username and hostname
  17. cat >/etc/casper.conf <<"EOF"
  18. export USERNAME="ubuntu"
  19. export USERFULLNAME="Live session user"
  20. export HOST="nilmbuntu"
  21. export BUILD_SYSTEM="Ubuntu"
  22. export FLAVOUR="NILMbuntu"
  23. EOF
  24. # Upgrade packages and remove old kernels
  25. apt-get update
  26. apt-get -y dist-upgrade
  27. apt-get -y --purge autoremove
  28. for VER in $(ls --sort=version /lib/modules/ | head -n -1) ; do
  29. apt-get -y --purge remove "linux-.*$VER"
  30. done
  31. # Disable upgrade popups
  32. sed -i -s -e 's/Prompt=.*/Prompt=never/g' \
  33. /etc/update-manager/release-upgrades || true
  34. # Set up & install postfix for local mail delivery
  35. debconf-set-selections <<"EOF"
  36. postfix postfix/mailname string localdomain
  37. postfix postfix/main_mailer_type select Local only
  38. EOF
  39. apt-get -y install postfix
  40. # Required packages
  41. apt-get -y install \
  42. python3 \
  43. python2.7 \
  44. python2.7-dev \
  45. python-setuptools \
  46. python-pip \
  47. cython \
  48. git \
  49. build-essential \
  50. python-cherrypy3 \
  51. python-decorator \
  52. python-simplejson \
  53. python-requests \
  54. python-dateutil \
  55. python-tz \
  56. python-progressbar \
  57. python-psutil \
  58. python-numpy \
  59. python-nose \
  60. python-coverage \
  61. apache2 \
  62. libapache2-mod-wsgi \
  63. python-scipy \
  64. python-daemon
  65. # Install other useful but optional stuff
  66. try_install \
  67. curl \
  68. devscripts \
  69. dlocate \
  70. emacs \
  71. emacs-goodies-el \
  72. gcc-arm-none-eabi \
  73. gdb-arm-none-eabi \
  74. gddrescue \
  75. gnuplot \
  76. help2man \
  77. ipython \
  78. libnewlib-arm-none-eabi \
  79. libstdc++-arm-none-eabi-newlib \
  80. texlive \
  81. mailutils \
  82. moreutils \
  83. mutt \
  84. network-manager-openvpn-gnome \
  85. octave \
  86. octave-missing-functions \
  87. octave-signal \
  88. openocd \
  89. openssl \
  90. openvpn \
  91. python-matplotlib \
  92. screen \
  93. silversearcher-ag \
  94. subversion \
  95. tcpdump \
  96. zip
  97. # Install the packages required for en_US language support
  98. # This avoids a prompt and package download at first install
  99. try_install $(/usr/bin/check-language-support -l en_US)
  100. # Set up timezone to America/New_York for the live CD
  101. ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime
  102. dpkg-reconfigure -f noninteractive tzdata
  103. # Put some default desktop shortcuts in place
  104. DESKTOP=/etc/skel/Desktop
  105. mkdir -p $DESKTOP
  106. cp /usr/share/applications/exo-terminal-emulator.desktop $DESKTOP || true
  107. cp /usr/share/applications/exo-web-browser.desktop $DESKTOP || true
  108. chmod +x $DESKTOP/*
  109. # Custom background image (which was already copied in by customize.sh)
  110. XML=/etc/xdg/xdg-xubuntu/xfce4/xfconf/xfce-perchannel-xml/xfce4-desktop.xml
  111. BG=/usr/share/xfce4/backdrops/nilmbuntu.png
  112. apt-get -y install xmlstarlet
  113. xmlstarlet ed -L -u "//property[@name='image-path']/@value" -v "$BG" $XML
  114. xmlstarlet ed -L -u "//property[@name='image-style']/@value" -v "3" $XML
  115. # Configure Firefox with our default homepage
  116. HOMEPAGE="http://www.wattsworth.net/"
  117. cat >/etc/firefox/syspref.js <<EOF
  118. pref("browser.startup.homepage", "${HOMEPAGE}");
  119. pref("extensions.ubufox@ubuntu.com.custom_homepage", "${HOMEPAGE}");
  120. pref("browser.startup.homepage_override.mstone", "ignore");
  121. EOF
  122. # NilmDB setup below...
  123. # # Create nilmdb user to run the database
  124. # adduser --system --group --shell /bin/bash --disabled-password nilmdb
  125. # cp -rv /etc/skel/.??* /home/nilmdb
  126. # chown -R nilmdb:nilmdb /home/nilmdb
  127. # # Create WSGI scripts
  128. # cat > /home/nilmdb/nilmdb.wsgi <<"EOF"
  129. # import nilmdb.server
  130. # application = nilmdb.server.wsgi_application("/home/nilmdb/db","/nilmdb")
  131. # EOF
  132. # cat > /home/nilmdb/nilmrun.wsgi <<"EOF"
  133. # import nilmrun.server
  134. # application = nilmrun.server.wsgi_application("/nilmrun")
  135. # EOF
  136. # #### Edit apache config
  137. # # Create apache config by hacking up the default one. Might be a better way
  138. # # to do this, and it'll probably break on new versions, but...
  139. # APACHE_VER=$(dpkg -s apache2 | grep ^Version | cut -d ' ' -f 2)
  140. # if dpkg --compare-versions $APACHE_VER ge 2.4 ; then
  141. # DEF=/etc/apache2/sites-available/000-default.conf
  142. # NEED_PERMISSIONS=1
  143. # else
  144. # DEF=/etc/apache2/sites-available/default
  145. # NEED_PERMISSIONS=0
  146. # fi
  147. # # Cut out any existing NilmDB stuff
  148. # perl -ne 'print unless /## NilmDB start/../## NilmDB end/' $DEF > $DEF.orig
  149. # # Copy everything up to the first </VirtualHost> line
  150. # perl -ne 'print unless m-^[^#]*</VirtualHost>-..1' $DEF.orig > $DEF
  151. # # Add the NilmDB config
  152. # cat >>$DEF <<"EOF"
  153. # ## NilmDB start
  154. # WSGIScriptAlias /nilmdb /home/nilmdb/nilmdb.wsgi
  155. # WSGIDaemonProcess nilmdb-procgroup threads=32 user=nilmdb group=nilmdb
  156. # <Location /nilmdb>
  157. # WSGIProcessGroup nilmdb-procgroup
  158. # WSGIApplicationGroup nilmdb-appgroup
  159. # </Location>
  160. # WSGIScriptAlias /nilmrun /home/nilmdb/nilmrun.wsgi
  161. # WSGIDaemonProcess nilmrun-procgroup threads=32 user=nilmdb group=nilmdb
  162. # <Location /nilmrun>
  163. # WSGIProcessGroup nilmrun-procgroup
  164. # WSGIApplicationGroup nilmrun-appgroup
  165. # </Location>
  166. # EOF
  167. # if [ $NEED_PERMISSIONS == 1 ] ; then
  168. # cat >>$DEF <<"EOF"
  169. # <Directory /home/nilmdb>
  170. # Options All
  171. # AllowOverride All
  172. # Require all granted
  173. # </Directory>
  174. # EOF
  175. # fi
  176. # cat >>$DEF <<"EOF"
  177. # ## NilmDB end
  178. # EOF
  179. # # Copy everything including and after the first </VirtualHost> line
  180. # perl -ne 'print if m-^[^#]*</VirtualHost>-..1' $DEF.orig >> $DEF
  181. # #### Done editing apache config
  182. # # Create nilmdb capture, processing, and cleanup files
  183. # cat > /home/nilmdb/capture.sh <<"EOF"
  184. # #!/bin/bash -e
  185. # # Don't run capture if we're running off a live CD
  186. # if grep -q boot=casper /proc/cmdline ; then
  187. # echo "Skipping capture, because this is a live CD."
  188. # exit 0
  189. # fi
  190. # echo "Starting capture in background..."
  191. # nilm-pipewatch --daemon --lock "/tmp/nilmdb-capture.lock" --timeout 30 \
  192. # "ethstream -a 192.168.1.209 -n 6 -r 8000" \
  193. # "nilm-insert -m 10 -r 8000 --live /data/raw"
  194. # EOF
  195. # cat > /home/nilmdb/process.sh <<"EOF"
  196. # #!/bin/bash -e
  197. # # Ensure only one copy of this code runs at a time:
  198. # LOCKFILE="/tmp/nilmdb-process.lock"
  199. # exec 99>"$LOCKFILE"
  200. # flock -n -x 99 || exit 0
  201. # trap 'rm -f "$LOCKFILE"' 0
  202. # nilm-sinefit -c 4 /data/raw /data/sinefit
  203. # nilm-prep -c 1 -r 0 /data/raw /data/sinefit /data/prep-a
  204. # nilm-prep -c 2 -r 120 /data/raw /data/sinefit /data/prep-b
  205. # nilm-prep -c 3 -r 240 /data/raw /data/sinefit /data/prep-c
  206. # nilm-decimate-auto /data/raw "/data/prep*"
  207. # nilm-cleanup --yes /home/nilmdb/cleanup.cfg
  208. # EOF
  209. # cat > /home/nilmdb/cleanup.cfg <<"EOF"
  210. # [/data/prep-*]
  211. # keep = 1y
  212. # [/data/raw]
  213. # keep = 2w
  214. # [/data/sinefit]
  215. # keep = 1y
  216. # decimated = false
  217. # EOF
  218. # # Set up crontab
  219. # cat > /home/nilmdb/crontab <<"EOF"
  220. # SHELL=/bin/bash
  221. # PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  222. # # Run capture and processing scripts every 5 minutes
  223. # */5 * * * * chronic /home/nilmdb/capture.sh
  224. # */5 * * * * chronic /home/nilmdb/process.sh
  225. # # Try to run nilmdb-fsck on boot. It should hopefully run before
  226. # # apache opens the database, and apache will return errors to clients
  227. # # until nilmdb-fsck is done.
  228. # @reboot chronic nilmdb-fsck --fix --no-data /home/nilmdb/db
  229. # EOF
  230. # crontab -u nilmdb /home/nilmdb/crontab
  231. # # Fix permissions
  232. # chown -R nilmdb:nilmdb /home/nilmdb
  233. # chmod +x /home/nilmdb/{capture,process}.sh
  234. # # Fetch and build everything. Put it in the nilmdb dir
  235. # echo "machine git.jim.sh login nilm password nilm" > /home/nilmdb/.netrc
  236. # GIT=https://git.jim.sh/jim/lees
  237. # rm -rf /home/nilmdb/git
  238. # mkdir /home/nilmdb/git
  239. # chown nilmdb:nilmdb /home/nilmdb/.netrc /home/nilmdb/git
  240. # REPOS="nilmdb nilmtools nilmrun ethstream"
  241. # # check it out as nilmdb, so the .netrc gets used
  242. # for repo in $REPOS; do
  243. # sudo -i -u nilmdb git clone $GIT/$repo.git git/$repo
  244. # done
  245. # # build as root, because we need to do that for the install
  246. # for repo in $REPOS; do
  247. # make -C /home/nilmdb/git/$repo install
  248. # done
  249. # # fix up all permissions in git dir, so nilmdb user can play with it later
  250. # chown -R nilmdb:nilmdb /home/nilmdb/git
  251. # # Create the initial database and streams by running the standalone
  252. # # server as nilmdb, making the right nilmtool calls, and killing it.
  253. # sudo -i -u nilmdb nilmdb-server -a 127.0.0.1 -p 18646 -d /home/nilmdb/db &
  254. # SERVERPID=$!
  255. # trap "kill -9 $SERVERPID" 0
  256. # for i in $(seq 1 120) ; do
  257. # sleep 1
  258. # echo waiting for nilmdb to start $i
  259. # if nilmtool -u http://127.0.0.1:18646/ info ; then
  260. # break
  261. # fi
  262. # done
  263. # nilmtool -u http://127.0.0.1:18646/ destroy -R "/data/*" || true
  264. # nilmtool -u http://127.0.0.1:18646/ create /data/raw uint16_6
  265. # nilmtool -u http://127.0.0.1:18646/ create /data/sinefit float32_3
  266. # nilmtool -u http://127.0.0.1:18646/ create /data/prep-a float32_8
  267. # nilmtool -u http://127.0.0.1:18646/ create /data/prep-b float32_8
  268. # nilmtool -u http://127.0.0.1:18646/ create /data/prep-c float32_8
  269. # kill $SERVERPID
  270. # wait
  271. # trap "" 0