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.

customize-inner.sh 11 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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