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.
 
 
 

372 lines
11 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. # # Create nilmdb user to run the database
  101. # adduser --system --group --shell /bin/bash --disabled-password nilmdb
  102. # cp -rv /etc/skel/.??* /home/nilmdb
  103. # chown -R nilmdb:nilmdb /home/nilmdb
  104. # # Create WSGI scripts
  105. # cat > /home/nilmdb/nilmdb.wsgi <<"EOF"
  106. # import nilmdb.server
  107. # application = nilmdb.server.wsgi_application("/home/nilmdb/db","/nilmdb")
  108. # EOF
  109. # cat > /home/nilmdb/nilmrun.wsgi <<"EOF"
  110. # import nilmrun.server
  111. # application = nilmrun.server.wsgi_application("/nilmrun")
  112. # EOF
  113. # #### Edit apache config
  114. # # Create apache config by hacking up the default one. Might be a better way
  115. # # to do this, and it'll probably break on new versions, but...
  116. # APACHE_VER=$(dpkg -s apache2 | grep ^Version | cut -d ' ' -f 2)
  117. # if dpkg --compare-versions $APACHE_VER ge 2.4 ; then
  118. # DEF=/etc/apache2/sites-available/000-default.conf
  119. # NEED_PERMISSIONS=1
  120. # else
  121. # DEF=/etc/apache2/sites-available/default
  122. # NEED_PERMISSIONS=0
  123. # fi
  124. # # Cut out any existing NilmDB stuff
  125. # perl -ne 'print unless /## NilmDB start/../## NilmDB end/' $DEF > $DEF.orig
  126. # # Copy everything up to the first </VirtualHost> line
  127. # perl -ne 'print unless m-^[^#]*</VirtualHost>-..1' $DEF.orig > $DEF
  128. # # Add the NilmDB config
  129. # cat >>$DEF <<"EOF"
  130. # ## NilmDB start
  131. # WSGIScriptAlias /nilmdb /home/nilmdb/nilmdb.wsgi
  132. # WSGIDaemonProcess nilmdb-procgroup threads=32 user=nilmdb group=nilmdb
  133. # <Location /nilmdb>
  134. # WSGIProcessGroup nilmdb-procgroup
  135. # WSGIApplicationGroup nilmdb-appgroup
  136. # </Location>
  137. # WSGIScriptAlias /nilmrun /home/nilmdb/nilmrun.wsgi
  138. # WSGIDaemonProcess nilmrun-procgroup threads=32 user=nilmdb group=nilmdb
  139. # <Location /nilmrun>
  140. # WSGIProcessGroup nilmrun-procgroup
  141. # WSGIApplicationGroup nilmrun-appgroup
  142. # </Location>
  143. # EOF
  144. # if [ $NEED_PERMISSIONS == 1 ] ; then
  145. # cat >>$DEF <<"EOF"
  146. # <Directory /home/nilmdb>
  147. # Options All
  148. # AllowOverride All
  149. # Require all granted
  150. # </Directory>
  151. # EOF
  152. # fi
  153. # cat >>$DEF <<"EOF"
  154. # ## NilmDB end
  155. # EOF
  156. # # Copy everything including and after the first </VirtualHost> line
  157. # perl -ne 'print if m-^[^#]*</VirtualHost>-..1' $DEF.orig >> $DEF
  158. # #### Done editing apache config
  159. # # Create nilmdb capture, processing, and cleanup files
  160. # cat > /home/nilmdb/capture.sh <<"EOF"
  161. # #!/bin/bash -e
  162. # # Don't run capture if we're running off a live CD
  163. # if grep -q boot=casper /proc/cmdline ; then
  164. # echo "Skipping capture, because this is a live CD."
  165. # exit 0
  166. # fi
  167. # echo "Starting capture in background..."
  168. # nilm-pipewatch --daemon --lock "/tmp/nilmdb-capture.lock" --timeout 30 \
  169. # "ethstream -a 192.168.1.209 -n 6 -r 8000" \
  170. # "nilm-insert -m 10 -r 8000 --live /data/raw"
  171. # EOF
  172. # cat > /home/nilmdb/process.sh <<"EOF"
  173. # #!/bin/bash -e
  174. # # Ensure only one copy of this code runs at a time:
  175. # LOCKFILE="/tmp/nilmdb-process.lock"
  176. # exec 99>"$LOCKFILE"
  177. # flock -n -x 99 || exit 0
  178. # trap 'rm -f "$LOCKFILE"' 0
  179. # nilm-sinefit -c 4 /data/raw /data/sinefit
  180. # nilm-prep -c 1 -r 0 /data/raw /data/sinefit /data/prep-a
  181. # nilm-prep -c 2 -r 120 /data/raw /data/sinefit /data/prep-b
  182. # nilm-prep -c 3 -r 240 /data/raw /data/sinefit /data/prep-c
  183. # nilm-decimate-auto /data/raw "/data/prep*"
  184. # nilm-cleanup --yes /home/nilmdb/cleanup.cfg
  185. # EOF
  186. # cat > /home/nilmdb/cleanup.cfg <<"EOF"
  187. # [/data/prep-*]
  188. # keep = 1y
  189. # [/data/raw]
  190. # keep = 2w
  191. # [/data/sinefit]
  192. # keep = 1y
  193. # decimated = false
  194. # EOF
  195. # # Set up crontab
  196. # cat > /home/nilmdb/crontab <<"EOF"
  197. # SHELL=/bin/bash
  198. # PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  199. # # Run capture and processing scripts every 5 minutes
  200. # */5 * * * * chronic /home/nilmdb/capture.sh
  201. # */5 * * * * chronic /home/nilmdb/process.sh
  202. # # Try to run nilmdb-fsck on boot. It should hopefully run before
  203. # # apache opens the database, and apache will return errors to clients
  204. # # until nilmdb-fsck is done.
  205. # @reboot chronic nilmdb-fsck --fix --no-data /home/nilmdb/db
  206. # EOF
  207. # crontab -u nilmdb /home/nilmdb/crontab
  208. # # Fix permissions
  209. # chown -R nilmdb:nilmdb /home/nilmdb
  210. # chmod +x /home/nilmdb/{capture,process}.sh
  211. # # Fetch and build everything. Put it in the nilmdb dir
  212. # echo "machine git.jim.sh login nilm password nilm" > /home/nilmdb/.netrc
  213. # GIT=https://git.jim.sh/jim/lees
  214. # rm -rf /home/nilmdb/git
  215. # mkdir /home/nilmdb/git
  216. # chown nilmdb:nilmdb /home/nilmdb/.netrc /home/nilmdb/git
  217. # REPOS="nilmdb nilmtools nilmrun ethstream"
  218. # # check it out as nilmdb, so the .netrc gets used
  219. # for repo in $REPOS; do
  220. # sudo -i -u nilmdb git clone $GIT/$repo.git git/$repo
  221. # done
  222. # # build as root, because we need to do that for the install
  223. # for repo in $REPOS; do
  224. # make -C /home/nilmdb/git/$repo install
  225. # done
  226. # # fix up all permissions in git dir, so nilmdb user can play with it later
  227. # chown -R nilmdb:nilmdb /home/nilmdb/git
  228. # # Create the initial database and streams by running the standalone
  229. # # server as nilmdb, making the right nilmtool calls, and killing it.
  230. # sudo -i -u nilmdb nilmdb-server -a 127.0.0.1 -p 18646 -d /home/nilmdb/db &
  231. # SERVERPID=$!
  232. # trap "kill -9 $SERVERPID" 0
  233. # for i in $(seq 1 120) ; do
  234. # sleep 1
  235. # echo waiting for nilmdb to start $i
  236. # if nilmtool -u http://127.0.0.1:18646/ info ; then
  237. # break
  238. # fi
  239. # done
  240. # nilmtool -u http://127.0.0.1:18646/ destroy -R "/data/*" || true
  241. # nilmtool -u http://127.0.0.1:18646/ create /data/raw uint16_6
  242. # nilmtool -u http://127.0.0.1:18646/ create /data/sinefit float32_3
  243. # nilmtool -u http://127.0.0.1:18646/ create /data/prep-a float32_8
  244. # nilmtool -u http://127.0.0.1:18646/ create /data/prep-b float32_8
  245. # nilmtool -u http://127.0.0.1:18646/ create /data/prep-c float32_8
  246. # kill $SERVERPID
  247. # wait
  248. # trap "" 0
  249. # Put some default desktop shortcuts in place
  250. DESKTOP=/etc/skel/Desktop
  251. mkdir -p $DESKTOP
  252. cp /usr/share/applications/exo-terminal-emulator.desktop $DESKTOP || true
  253. cp /usr/share/applications/exo-web-browser.desktop $DESKTOP || true
  254. chmod +x $DESKTOP/*
  255. # # XFCE / theme customizations
  256. # if [ -d /usr/share/themes/Clearlooks ] ; then
  257. # cat > /usr/share/gconf/defaults/88_nilmdbuntu-gtk-theme <<"EOF"
  258. # /desktop/gnome/interface/gtk_theme "Clearlooks"
  259. # EOF
  260. # fi
  261. # if [ -d /usr/share/icons/elementary-xfce ] ; then
  262. # cat > /usr/share/gconf/defaults/88_nilmdbuntu-icon-theme <<"EOF"
  263. # /desktop/gnome/interface/icon_theme "elementary-xfce"
  264. # EOF
  265. # fi
  266. # update-gconf-defaults
  267. # XML=/etc/xdg/xdg-xubuntu/xfce4/xfconf/xfce-perchannel-xml
  268. # BG=/usr/share/xfce4/backdrops
  269. # mkdir -p $XML
  270. # cat >$XML/xfce4-desktop.xml <<"EOF"
  271. # <?xml version="1.0" encoding="UTF-8"?>
  272. # <channel name="xfce4-desktop" version="1.0">
  273. # <property name="desktop-icons" type="empty">
  274. # <property name="style" type="int" value="2"/>
  275. # <property name="file-icons" type="empty">
  276. # <property name="show-home" type="bool" value="true"/>
  277. # <property name="show-filesystem" type="bool" value="true"/>
  278. # <property name="show-removable" type="bool" value="true"/>
  279. # <property name="show-trash" type="bool" value="true"/>
  280. # </property>
  281. # </property>
  282. # <property name="backdrop" type="empty">
  283. # <property name="screen0" type="empty">
  284. # <property name="monitor0" type="empty">
  285. # <property name="image-path" type="string"
  286. # value="/usr/share/xfce4/backdrops/nilmdbuntu.png"/>
  287. # <property name="image-show" type="bool" value="true"/>
  288. # <property name="image-style" type="int" value="4"/>
  289. # <property name="color-style" type="int" value="0"/>
  290. # <property name="color1" type="array">
  291. # <value type="uint" value="0"/>
  292. # <value type="uint" value="0"/>
  293. # <value type="uint" value="0"/>
  294. # <value type="uint" value="65535"/>
  295. # </property>
  296. # </property>
  297. # <property name="monitor1" type="empty">
  298. # <property name="image-path" type="string"
  299. # value="/usr/share/xfce4/backdrops/nilmdbuntu.png"/>
  300. # <property name="image-show" type="bool" value="true"/>
  301. # <property name="image-style" type="int" value="4"/>
  302. # <property name="color-style" type="int" value="0"/>
  303. # <property name="color1" type="array">
  304. # <value type="uint" value="0"/>
  305. # <value type="uint" value="0"/>
  306. # <value type="uint" value="0"/>
  307. # <value type="uint" value="65535"/>
  308. # </property>
  309. # </property>
  310. # </property>
  311. # </property>
  312. # </channel>
  313. # EOF
  314. # sed -i -s -e 's/Greybird/Default/g' $XML/xfwm4.xml || true
  315. # sed -i -s -e 's/Greybird/Clearlooks/g' $XML/xsettings.xml || true
  316. # sed -i -s -e \
  317. # 's/elementary-xfce-dark(er)?/elementary-xfce/g' $XML/xsettings.xml || true
  318. # Firefox defaults
  319. cat >/etc/firefox/syspref.js <<"EOF"
  320. pref("browser.startup.homepage", "http://wattsworth.net/");
  321. EOF
  322. #cat >/etc/xul-ext/homepage.properties <<"EOF"
  323. #browser.startup.homepage=http://nilmdb.com/
  324. #EOF
  325. #cat >/etc/xul-ext/ubufox.js <<"EOF"
  326. #pref("browser.startup.homepage", "file:/etc/xul-ext/homepage.properties");
  327. #EOF