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.
 
 
 

308 lines
8.7 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. # Set up timezone to America/New_York for the live CD
  98. ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime
  99. dpkg-reconfigure -f noninteractive tzdata
  100. # Put some default desktop shortcuts in place
  101. DESKTOP=/etc/skel/Desktop
  102. mkdir -p $DESKTOP
  103. cp /usr/share/applications/exo-terminal-emulator.desktop $DESKTOP || true
  104. cp /usr/share/applications/exo-web-browser.desktop $DESKTOP || true
  105. chmod +x $DESKTOP/*
  106. # Custom background image (which was already copied in by customize.sh)
  107. XML=/etc/xdg/xdg-xubuntu/xfce4/xfconf/xfce-perchannel-xml
  108. sed -i -s -e 's/xubuntu-wallpaper.png/nilmbuntu.png/g' $XML/xfce4-desktop.xml
  109. # Configure Firefox with our default homepage
  110. HOMEPAGE="http://www.wattsworth.net/"
  111. cat >/etc/firefox/syspref.js <<EOF
  112. pref("browser.startup.homepage", "${HOMEPAGE}");
  113. pref("extensions.ubufox@ubuntu.com.custom_homepage", "${HOMEPAGE}");
  114. pref("browser.startup.homepage_override.mstone", "ignore");
  115. EOF
  116. # NilmDB setup below...
  117. # # Create nilmdb user to run the database
  118. # adduser --system --group --shell /bin/bash --disabled-password nilmdb
  119. # cp -rv /etc/skel/.??* /home/nilmdb
  120. # chown -R nilmdb:nilmdb /home/nilmdb
  121. # # Create WSGI scripts
  122. # cat > /home/nilmdb/nilmdb.wsgi <<"EOF"
  123. # import nilmdb.server
  124. # application = nilmdb.server.wsgi_application("/home/nilmdb/db","/nilmdb")
  125. # EOF
  126. # cat > /home/nilmdb/nilmrun.wsgi <<"EOF"
  127. # import nilmrun.server
  128. # application = nilmrun.server.wsgi_application("/nilmrun")
  129. # EOF
  130. # #### Edit apache config
  131. # # Create apache config by hacking up the default one. Might be a better way
  132. # # to do this, and it'll probably break on new versions, but...
  133. # APACHE_VER=$(dpkg -s apache2 | grep ^Version | cut -d ' ' -f 2)
  134. # if dpkg --compare-versions $APACHE_VER ge 2.4 ; then
  135. # DEF=/etc/apache2/sites-available/000-default.conf
  136. # NEED_PERMISSIONS=1
  137. # else
  138. # DEF=/etc/apache2/sites-available/default
  139. # NEED_PERMISSIONS=0
  140. # fi
  141. # # Cut out any existing NilmDB stuff
  142. # perl -ne 'print unless /## NilmDB start/../## NilmDB end/' $DEF > $DEF.orig
  143. # # Copy everything up to the first </VirtualHost> line
  144. # perl -ne 'print unless m-^[^#]*</VirtualHost>-..1' $DEF.orig > $DEF
  145. # # Add the NilmDB config
  146. # cat >>$DEF <<"EOF"
  147. # ## NilmDB start
  148. # WSGIScriptAlias /nilmdb /home/nilmdb/nilmdb.wsgi
  149. # WSGIDaemonProcess nilmdb-procgroup threads=32 user=nilmdb group=nilmdb
  150. # <Location /nilmdb>
  151. # WSGIProcessGroup nilmdb-procgroup
  152. # WSGIApplicationGroup nilmdb-appgroup
  153. # </Location>
  154. # WSGIScriptAlias /nilmrun /home/nilmdb/nilmrun.wsgi
  155. # WSGIDaemonProcess nilmrun-procgroup threads=32 user=nilmdb group=nilmdb
  156. # <Location /nilmrun>
  157. # WSGIProcessGroup nilmrun-procgroup
  158. # WSGIApplicationGroup nilmrun-appgroup
  159. # </Location>
  160. # EOF
  161. # if [ $NEED_PERMISSIONS == 1 ] ; then
  162. # cat >>$DEF <<"EOF"
  163. # <Directory /home/nilmdb>
  164. # Options All
  165. # AllowOverride All
  166. # Require all granted
  167. # </Directory>
  168. # EOF
  169. # fi
  170. # cat >>$DEF <<"EOF"
  171. # ## NilmDB end
  172. # EOF
  173. # # Copy everything including and after the first </VirtualHost> line
  174. # perl -ne 'print if m-^[^#]*</VirtualHost>-..1' $DEF.orig >> $DEF
  175. # #### Done editing apache config
  176. # # Create nilmdb capture, processing, and cleanup files
  177. # cat > /home/nilmdb/capture.sh <<"EOF"
  178. # #!/bin/bash -e
  179. # # Don't run capture if we're running off a live CD
  180. # if grep -q boot=casper /proc/cmdline ; then
  181. # echo "Skipping capture, because this is a live CD."
  182. # exit 0
  183. # fi
  184. # echo "Starting capture in background..."
  185. # nilm-pipewatch --daemon --lock "/tmp/nilmdb-capture.lock" --timeout 30 \
  186. # "ethstream -a 192.168.1.209 -n 6 -r 8000" \
  187. # "nilm-insert -m 10 -r 8000 --live /data/raw"
  188. # EOF
  189. # cat > /home/nilmdb/process.sh <<"EOF"
  190. # #!/bin/bash -e
  191. # # Ensure only one copy of this code runs at a time:
  192. # LOCKFILE="/tmp/nilmdb-process.lock"
  193. # exec 99>"$LOCKFILE"
  194. # flock -n -x 99 || exit 0
  195. # trap 'rm -f "$LOCKFILE"' 0
  196. # nilm-sinefit -c 4 /data/raw /data/sinefit
  197. # nilm-prep -c 1 -r 0 /data/raw /data/sinefit /data/prep-a
  198. # nilm-prep -c 2 -r 120 /data/raw /data/sinefit /data/prep-b
  199. # nilm-prep -c 3 -r 240 /data/raw /data/sinefit /data/prep-c
  200. # nilm-decimate-auto /data/raw "/data/prep*"
  201. # nilm-cleanup --yes /home/nilmdb/cleanup.cfg
  202. # EOF
  203. # cat > /home/nilmdb/cleanup.cfg <<"EOF"
  204. # [/data/prep-*]
  205. # keep = 1y
  206. # [/data/raw]
  207. # keep = 2w
  208. # [/data/sinefit]
  209. # keep = 1y
  210. # decimated = false
  211. # EOF
  212. # # Set up crontab
  213. # cat > /home/nilmdb/crontab <<"EOF"
  214. # SHELL=/bin/bash
  215. # PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  216. # # Run capture and processing scripts every 5 minutes
  217. # */5 * * * * chronic /home/nilmdb/capture.sh
  218. # */5 * * * * chronic /home/nilmdb/process.sh
  219. # # Try to run nilmdb-fsck on boot. It should hopefully run before
  220. # # apache opens the database, and apache will return errors to clients
  221. # # until nilmdb-fsck is done.
  222. # @reboot chronic nilmdb-fsck --fix --no-data /home/nilmdb/db
  223. # EOF
  224. # crontab -u nilmdb /home/nilmdb/crontab
  225. # # Fix permissions
  226. # chown -R nilmdb:nilmdb /home/nilmdb
  227. # chmod +x /home/nilmdb/{capture,process}.sh
  228. # # Fetch and build everything. Put it in the nilmdb dir
  229. # echo "machine git.jim.sh login nilm password nilm" > /home/nilmdb/.netrc
  230. # GIT=https://git.jim.sh/jim/lees
  231. # rm -rf /home/nilmdb/git
  232. # mkdir /home/nilmdb/git
  233. # chown nilmdb:nilmdb /home/nilmdb/.netrc /home/nilmdb/git
  234. # REPOS="nilmdb nilmtools nilmrun ethstream"
  235. # # check it out as nilmdb, so the .netrc gets used
  236. # for repo in $REPOS; do
  237. # sudo -i -u nilmdb git clone $GIT/$repo.git git/$repo
  238. # done
  239. # # build as root, because we need to do that for the install
  240. # for repo in $REPOS; do
  241. # make -C /home/nilmdb/git/$repo install
  242. # done
  243. # # fix up all permissions in git dir, so nilmdb user can play with it later
  244. # chown -R nilmdb:nilmdb /home/nilmdb/git
  245. # # Create the initial database and streams by running the standalone
  246. # # server as nilmdb, making the right nilmtool calls, and killing it.
  247. # sudo -i -u nilmdb nilmdb-server -a 127.0.0.1 -p 18646 -d /home/nilmdb/db &
  248. # SERVERPID=$!
  249. # trap "kill -9 $SERVERPID" 0
  250. # for i in $(seq 1 120) ; do
  251. # sleep 1
  252. # echo waiting for nilmdb to start $i
  253. # if nilmtool -u http://127.0.0.1:18646/ info ; then
  254. # break
  255. # fi
  256. # done
  257. # nilmtool -u http://127.0.0.1:18646/ destroy -R "/data/*" || true
  258. # nilmtool -u http://127.0.0.1:18646/ create /data/raw uint16_6
  259. # nilmtool -u http://127.0.0.1:18646/ create /data/sinefit float32_3
  260. # nilmtool -u http://127.0.0.1:18646/ create /data/prep-a float32_8
  261. # nilmtool -u http://127.0.0.1:18646/ create /data/prep-b float32_8
  262. # nilmtool -u http://127.0.0.1:18646/ create /data/prep-c float32_8
  263. # kill $SERVERPID
  264. # wait
  265. # trap "" 0