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.
 
 
 

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