Browse Source

Start cleaning up some of the customization for 16.04

tags/nilmbuntu-5
Jim Paris 8 years ago
parent
commit
f14b1684bc
1 changed files with 286 additions and 298 deletions
  1. +286
    -298
      customize-inner.sh

+ 286
- 298
customize-inner.sh View File

@@ -5,16 +5,15 @@ if [ "$IN_CHROOT" != "1" ] ; then
exit 1
fi

echo ---------------CUSTOMIZE_INNER GIVING UP-----------------
exit

set -e
set -x

try_install() {
# try to install packages, but ignore failure
for pkg in "$@"; do
apt-get -y install "$pkg" || true
if ! apt-get -y install "$pkg" ; then
echo ---- WARNING: Failed to install package: $pkg
fi
done
}

@@ -22,35 +21,23 @@ try_install() {
cat >/etc/casper.conf <<"EOF"
export USERNAME="ubuntu"
export USERFULLNAME="Live session user"
export HOST="nilmdb"
export HOST="nilmbuntu"
export BUILD_SYSTEM="Ubuntu"
export FLAVOUR="NilmDBuntu"
export FLAVOUR="NILMbuntu"
EOF

# In 13.10, this is needed to upgrade the "whoopsie" package; bug #1272269
grep '13[.]10' /etc/issue && ln -sf /lib/init/upstart-job /etc/init.d/whoopsie

# Upgrade packages, remove old kernels
# Upgrade packages and remove old kernels
apt-get update
# in 13.04, doing upgrade & dist-upgrade together tries to install 2 kernels
# at the same time, which breaks for some reason. Also, try the upgrade
# multiple times since that can help
apt-get -y upgrade || apt-get -y upgrade || true
apt-get -y dist-upgrade || apt-get -y dist-upgrade || true
apt-get -y dist-upgrade
apt-get -y --purge autoremove
for VER in $(ls --sort=version /lib/modules/ | head -n -1) ; do
apt-get -y --purge remove ".*$VER.*"
apt-get -y --purge remove "linux-.*$VER"
done

# Disable upgrade popups
sed -i -s -e 's/Prompt=normal/Prompt=never/g' \
sed -i -s -e 's/Prompt=.*/Prompt=never/g' \
/etc/update-manager/release-upgrades || true

# some stuff we need from Ubuntu
try_install \
wbritish \
thunderbird-locale-en-us

# Set up & install postfix for local mail delivery
debconf-set-selections <<"EOF"
postfix postfix/mailname string localdomain
@@ -58,8 +45,9 @@ postfix postfix/main_mailer_type select Local only
EOF
apt-get -y install postfix

# install nilmdb things
# Required packages
apt-get -y install \
python3 \
python2.7 \
python2.7-dev \
python-setuptools \
@@ -83,301 +71,301 @@ apt-get -y install \
python-scipy \
python-daemon

# install other useful but optional stuff
# Install other useful but optional stuff
try_install \
emacs-goodies-el \
emacs23-nox \
octave \
octave-signal \
octave-missing-functions \
gnuplot \
curl \
devscripts \
dlocate \
emacs \
emacs-goodies-el \
gcc-arm-none-eabi \
gdb-arm-none-eabi \
gddrescue \
gnuplot \
help2man \
luatex \
pgf \
ipython \
libnewlib-arm-none-eabi \
libstdc++-arm-none-eabi-newlib \
texlive \
mailutils \
moreutils \
ntfsprogs \
subversion \
dlocate \
ack-grep \
mutt \
python-matplotlib \
ipython \
openvpn \
network-manager-openvpn-gnome \
octave \
octave-missing-functions \
octave-signal \
openocd \
openssl \
tcpdump \
openvpn \
python-matplotlib \
screen \
devscripts \
mailutils

# required
apt-get -y install \
openssh-server
silversearcher-ag \
subversion \
tcpdump \
zip

# Set up timezone to America/New_York for the live CD
echo America/New_York > /etc/timezone
ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime
dpkg-reconfigure -f noninteractive tzdata

# Create nilmdb user to run the database
adduser --system --group --shell /bin/bash --disabled-password nilmdb
cp -rv /etc/skel/.??* /home/nilmdb
chown -R nilmdb:nilmdb /home/nilmdb
# Create WSGI scripts
cat > /home/nilmdb/nilmdb.wsgi <<"EOF"
import nilmdb.server
application = nilmdb.server.wsgi_application("/home/nilmdb/db","/nilmdb")
EOF
cat > /home/nilmdb/nilmrun.wsgi <<"EOF"
import nilmrun.server
application = nilmrun.server.wsgi_application("/nilmrun")
EOF
#### Edit apache config
# Create apache config by hacking up the default one. Might be a better way
# to do this, and it'll probably break on new versions, but...
APACHE_VER=$(dpkg -s apache2 | grep ^Version | cut -d ' ' -f 2)
if dpkg --compare-versions $APACHE_VER ge 2.4 ; then
DEF=/etc/apache2/sites-available/000-default.conf
NEED_PERMISSIONS=1
else
DEF=/etc/apache2/sites-available/default
NEED_PERMISSIONS=0
fi
# Cut out any existing NilmDB stuff
perl -ne 'print unless /## NilmDB start/../## NilmDB end/' $DEF > $DEF.orig
# Copy everything up to the first </VirtualHost> line
perl -ne 'print unless m-^[^#]*</VirtualHost>-..1' $DEF.orig > $DEF
# Add the NilmDB config
cat >>$DEF <<"EOF"
## NilmDB start
WSGIScriptAlias /nilmdb /home/nilmdb/nilmdb.wsgi
WSGIDaemonProcess nilmdb-procgroup threads=32 user=nilmdb group=nilmdb
<Location /nilmdb>
WSGIProcessGroup nilmdb-procgroup
WSGIApplicationGroup nilmdb-appgroup
</Location>
WSGIScriptAlias /nilmrun /home/nilmdb/nilmrun.wsgi
WSGIDaemonProcess nilmrun-procgroup threads=32 user=nilmdb group=nilmdb
<Location /nilmrun>
WSGIProcessGroup nilmrun-procgroup
WSGIApplicationGroup nilmrun-appgroup
</Location>
EOF
if [ $NEED_PERMISSIONS == 1 ] ; then
cat >>$DEF <<"EOF"
<Directory /home/nilmdb>
Options All
AllowOverride All
Require all granted
</Directory>
EOF
fi
cat >>$DEF <<"EOF"
## NilmDB end
EOF
# Copy everything including and after the first </VirtualHost> line
perl -ne 'print if m-^[^#]*</VirtualHost>-..1' $DEF.orig >> $DEF
#### Done editing apache config
# Create nilmdb capture, processing, and cleanup files
cat > /home/nilmdb/capture.sh <<"EOF"
#!/bin/bash -e
# Don't run capture if we're running off a live CD
if grep -q boot=casper /proc/cmdline ; then
echo "Skipping capture, because this is a live CD."
exit 0
fi
echo "Starting capture in background..."
nilm-pipewatch --daemon --lock "/tmp/nilmdb-capture.lock" --timeout 30 \
"ethstream -a 192.168.1.209 -n 6 -r 8000" \
"nilm-insert -m 10 -r 8000 --live /data/raw"
EOF
cat > /home/nilmdb/process.sh <<"EOF"
#!/bin/bash -e
# Ensure only one copy of this code runs at a time:
LOCKFILE="/tmp/nilmdb-process.lock"
exec 99>"$LOCKFILE"
flock -n -x 99 || exit 0
trap 'rm -f "$LOCKFILE"' 0
nilm-sinefit -c 4 /data/raw /data/sinefit
nilm-prep -c 1 -r 0 /data/raw /data/sinefit /data/prep-a
nilm-prep -c 2 -r 120 /data/raw /data/sinefit /data/prep-b
nilm-prep -c 3 -r 240 /data/raw /data/sinefit /data/prep-c
nilm-decimate-auto /data/raw "/data/prep*"
nilm-cleanup --yes /home/nilmdb/cleanup.cfg
EOF
cat > /home/nilmdb/cleanup.cfg <<"EOF"
[/data/prep-*]
keep = 1y
[/data/raw]
keep = 2w
[/data/sinefit]
keep = 1y
decimated = false
EOF
# Set up crontab
cat > /home/nilmdb/crontab <<"EOF"
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# Run capture and processing scripts every 5 minutes
*/5 * * * * chronic /home/nilmdb/capture.sh
*/5 * * * * chronic /home/nilmdb/process.sh
# Try to run nilmdb-fsck on boot. It should hopefully run before
# apache opens the database, and apache will return errors to clients
# until nilmdb-fsck is done.
@reboot chronic nilmdb-fsck --fix --no-data /home/nilmdb/db
EOF
crontab -u nilmdb /home/nilmdb/crontab
# Fix permissions
chown -R nilmdb:nilmdb /home/nilmdb
chmod +x /home/nilmdb/{capture,process}.sh
# Fetch and build everything. Put it in the nilmdb dir
echo "machine git.jim.sh login nilm password nilm" > /home/nilmdb/.netrc
GIT=https://git.jim.sh/jim/lees
rm -rf /home/nilmdb/git
mkdir /home/nilmdb/git
chown nilmdb:nilmdb /home/nilmdb/.netrc /home/nilmdb/git
REPOS="nilmdb nilmtools nilmrun ethstream"
# check it out as nilmdb, so the .netrc gets used
for repo in $REPOS; do
sudo -i -u nilmdb git clone $GIT/$repo.git git/$repo
done
# build as root, because we need to do that for the install
for repo in $REPOS; do
make -C /home/nilmdb/git/$repo install
done
# fix up all permissions in git dir, so nilmdb user can play with it later
chown -R nilmdb:nilmdb /home/nilmdb/git
# Create the initial database and streams by running the standalone
# server as nilmdb, making the right nilmtool calls, and killing it.
sudo -i -u nilmdb nilmdb-server -a 127.0.0.1 -p 18646 -d /home/nilmdb/db &
SERVERPID=$!
trap "kill -9 $SERVERPID" 0
for i in $(seq 1 120) ; do
sleep 1
echo waiting for nilmdb to start $i
if nilmtool -u http://127.0.0.1:18646/ info ; then
break
fi
done
nilmtool -u http://127.0.0.1:18646/ destroy -R "/data/*" || true
nilmtool -u http://127.0.0.1:18646/ create /data/raw uint16_6
nilmtool -u http://127.0.0.1:18646/ create /data/sinefit float32_3
nilmtool -u http://127.0.0.1:18646/ create /data/prep-a float32_8
nilmtool -u http://127.0.0.1:18646/ create /data/prep-b float32_8
nilmtool -u http://127.0.0.1:18646/ create /data/prep-c float32_8
kill $SERVERPID
wait
trap "" 0
# # Create nilmdb user to run the database
# adduser --system --group --shell /bin/bash --disabled-password nilmdb
# cp -rv /etc/skel/.??* /home/nilmdb
# chown -R nilmdb:nilmdb /home/nilmdb
# # Create WSGI scripts
# cat > /home/nilmdb/nilmdb.wsgi <<"EOF"
# import nilmdb.server
# application = nilmdb.server.wsgi_application("/home/nilmdb/db","/nilmdb")
# EOF
# cat > /home/nilmdb/nilmrun.wsgi <<"EOF"
# import nilmrun.server
# application = nilmrun.server.wsgi_application("/nilmrun")
# EOF
# #### Edit apache config
# # Create apache config by hacking up the default one. Might be a better way
# # to do this, and it'll probably break on new versions, but...
# APACHE_VER=$(dpkg -s apache2 | grep ^Version | cut -d ' ' -f 2)
# if dpkg --compare-versions $APACHE_VER ge 2.4 ; then
# DEF=/etc/apache2/sites-available/000-default.conf
# NEED_PERMISSIONS=1
# else
# DEF=/etc/apache2/sites-available/default
# NEED_PERMISSIONS=0
# fi
# # Cut out any existing NilmDB stuff
# perl -ne 'print unless /## NilmDB start/../## NilmDB end/' $DEF > $DEF.orig
# # Copy everything up to the first </VirtualHost> line
# perl -ne 'print unless m-^[^#]*</VirtualHost>-..1' $DEF.orig > $DEF
# # Add the NilmDB config
# cat >>$DEF <<"EOF"
# ## NilmDB start
# WSGIScriptAlias /nilmdb /home/nilmdb/nilmdb.wsgi
# WSGIDaemonProcess nilmdb-procgroup threads=32 user=nilmdb group=nilmdb
# <Location /nilmdb>
# WSGIProcessGroup nilmdb-procgroup
# WSGIApplicationGroup nilmdb-appgroup
# </Location>
# WSGIScriptAlias /nilmrun /home/nilmdb/nilmrun.wsgi
# WSGIDaemonProcess nilmrun-procgroup threads=32 user=nilmdb group=nilmdb
# <Location /nilmrun>
# WSGIProcessGroup nilmrun-procgroup
# WSGIApplicationGroup nilmrun-appgroup
# </Location>
# EOF
# if [ $NEED_PERMISSIONS == 1 ] ; then
# cat >>$DEF <<"EOF"
# <Directory /home/nilmdb>
# Options All
# AllowOverride All
# Require all granted
# </Directory>
# EOF
# fi
# cat >>$DEF <<"EOF"
# ## NilmDB end
# EOF
# # Copy everything including and after the first </VirtualHost> line
# perl -ne 'print if m-^[^#]*</VirtualHost>-..1' $DEF.orig >> $DEF
# #### Done editing apache config
# # Create nilmdb capture, processing, and cleanup files
# cat > /home/nilmdb/capture.sh <<"EOF"
# #!/bin/bash -e
# # Don't run capture if we're running off a live CD
# if grep -q boot=casper /proc/cmdline ; then
# echo "Skipping capture, because this is a live CD."
# exit 0
# fi
# echo "Starting capture in background..."
# nilm-pipewatch --daemon --lock "/tmp/nilmdb-capture.lock" --timeout 30 \
# "ethstream -a 192.168.1.209 -n 6 -r 8000" \
# "nilm-insert -m 10 -r 8000 --live /data/raw"
# EOF
# cat > /home/nilmdb/process.sh <<"EOF"
# #!/bin/bash -e
# # Ensure only one copy of this code runs at a time:
# LOCKFILE="/tmp/nilmdb-process.lock"
# exec 99>"$LOCKFILE"
# flock -n -x 99 || exit 0
# trap 'rm -f "$LOCKFILE"' 0
# nilm-sinefit -c 4 /data/raw /data/sinefit
# nilm-prep -c 1 -r 0 /data/raw /data/sinefit /data/prep-a
# nilm-prep -c 2 -r 120 /data/raw /data/sinefit /data/prep-b
# nilm-prep -c 3 -r 240 /data/raw /data/sinefit /data/prep-c
# nilm-decimate-auto /data/raw "/data/prep*"
# nilm-cleanup --yes /home/nilmdb/cleanup.cfg
# EOF
# cat > /home/nilmdb/cleanup.cfg <<"EOF"
# [/data/prep-*]
# keep = 1y
# [/data/raw]
# keep = 2w
# [/data/sinefit]
# keep = 1y
# decimated = false
# EOF
# # Set up crontab
# cat > /home/nilmdb/crontab <<"EOF"
# SHELL=/bin/bash
# PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# # Run capture and processing scripts every 5 minutes
# */5 * * * * chronic /home/nilmdb/capture.sh
# */5 * * * * chronic /home/nilmdb/process.sh
# # Try to run nilmdb-fsck on boot. It should hopefully run before
# # apache opens the database, and apache will return errors to clients
# # until nilmdb-fsck is done.
# @reboot chronic nilmdb-fsck --fix --no-data /home/nilmdb/db
# EOF
# crontab -u nilmdb /home/nilmdb/crontab
# # Fix permissions
# chown -R nilmdb:nilmdb /home/nilmdb
# chmod +x /home/nilmdb/{capture,process}.sh
# # Fetch and build everything. Put it in the nilmdb dir
# echo "machine git.jim.sh login nilm password nilm" > /home/nilmdb/.netrc
# GIT=https://git.jim.sh/jim/lees
# rm -rf /home/nilmdb/git
# mkdir /home/nilmdb/git
# chown nilmdb:nilmdb /home/nilmdb/.netrc /home/nilmdb/git
# REPOS="nilmdb nilmtools nilmrun ethstream"
# # check it out as nilmdb, so the .netrc gets used
# for repo in $REPOS; do
# sudo -i -u nilmdb git clone $GIT/$repo.git git/$repo
# done
# # build as root, because we need to do that for the install
# for repo in $REPOS; do
# make -C /home/nilmdb/git/$repo install
# done
# # fix up all permissions in git dir, so nilmdb user can play with it later
# chown -R nilmdb:nilmdb /home/nilmdb/git
# # Create the initial database and streams by running the standalone
# # server as nilmdb, making the right nilmtool calls, and killing it.
# sudo -i -u nilmdb nilmdb-server -a 127.0.0.1 -p 18646 -d /home/nilmdb/db &
# SERVERPID=$!
# trap "kill -9 $SERVERPID" 0
# for i in $(seq 1 120) ; do
# sleep 1
# echo waiting for nilmdb to start $i
# if nilmtool -u http://127.0.0.1:18646/ info ; then
# break
# fi
# done
# nilmtool -u http://127.0.0.1:18646/ destroy -R "/data/*" || true
# nilmtool -u http://127.0.0.1:18646/ create /data/raw uint16_6
# nilmtool -u http://127.0.0.1:18646/ create /data/sinefit float32_3
# nilmtool -u http://127.0.0.1:18646/ create /data/prep-a float32_8
# nilmtool -u http://127.0.0.1:18646/ create /data/prep-b float32_8
# nilmtool -u http://127.0.0.1:18646/ create /data/prep-c float32_8
# kill $SERVERPID
# wait
# trap "" 0

# Put some default desktop shortcuts in place
DESKTOP=/etc/skel/Desktop
mkdir -p $DESKTOP
cp /usr/share/applications/exo-terminal-emulator.desktop $DESKTOP || true
cp /usr/share/applications/exo-web-browser.desktop $DESKTOP || true
chmod +x $DESKTOP/* # needs to be executable for 13.04+
# XFCE / theme customizations
if [ -d /usr/share/themes/Clearlooks ] ; then
cat > /usr/share/gconf/defaults/88_nilmdbuntu-gtk-theme <<"EOF"
/desktop/gnome/interface/gtk_theme "Clearlooks"
EOF
fi
if [ -d /usr/share/icons/elementary-xfce ] ; then
cat > /usr/share/gconf/defaults/88_nilmdbuntu-icon-theme <<"EOF"
/desktop/gnome/interface/icon_theme "elementary-xfce"
EOF
fi
update-gconf-defaults
XML=/etc/xdg/xdg-xubuntu/xfce4/xfconf/xfce-perchannel-xml
BG=/usr/share/xfce4/backdrops
mkdir -p $XML
cat >$XML/xfce4-desktop.xml <<"EOF"
<?xml version="1.0" encoding="UTF-8"?>
<channel name="xfce4-desktop" version="1.0">
<property name="desktop-icons" type="empty">
<property name="style" type="int" value="2"/>
<property name="file-icons" type="empty">
<property name="show-home" type="bool" value="true"/>
<property name="show-filesystem" type="bool" value="true"/>
<property name="show-removable" type="bool" value="true"/>
<property name="show-trash" type="bool" value="true"/>
</property>
</property>
<property name="backdrop" type="empty">
<property name="screen0" type="empty">
<property name="monitor0" type="empty">
<property name="image-path" type="string"
value="/usr/share/xfce4/backdrops/nilmdbuntu.png"/>
<property name="image-show" type="bool" value="true"/>
<property name="image-style" type="int" value="4"/>
<property name="color-style" type="int" value="0"/>
<property name="color1" type="array">
<value type="uint" value="0"/>
<value type="uint" value="0"/>
<value type="uint" value="0"/>
<value type="uint" value="65535"/>
</property>
</property>
<property name="monitor1" type="empty">
<property name="image-path" type="string"
value="/usr/share/xfce4/backdrops/nilmdbuntu.png"/>
<property name="image-show" type="bool" value="true"/>
<property name="image-style" type="int" value="4"/>
<property name="color-style" type="int" value="0"/>
<property name="color1" type="array">
<value type="uint" value="0"/>
<value type="uint" value="0"/>
<value type="uint" value="0"/>
<value type="uint" value="65535"/>
</property>
</property>
</property>
</property>
</channel>
EOF
sed -i -s -e 's/Greybird/Default/g' $XML/xfwm4.xml || true
sed -i -s -e 's/Greybird/Clearlooks/g' $XML/xsettings.xml || true
sed -i -s -e \
's/elementary-xfce-dark(er)?/elementary-xfce/g' $XML/xsettings.xml || true
chmod +x $DESKTOP/*
# # XFCE / theme customizations
# if [ -d /usr/share/themes/Clearlooks ] ; then
# cat > /usr/share/gconf/defaults/88_nilmdbuntu-gtk-theme <<"EOF"
# /desktop/gnome/interface/gtk_theme "Clearlooks"
# EOF
# fi
# if [ -d /usr/share/icons/elementary-xfce ] ; then
# cat > /usr/share/gconf/defaults/88_nilmdbuntu-icon-theme <<"EOF"
# /desktop/gnome/interface/icon_theme "elementary-xfce"
# EOF
# fi
# update-gconf-defaults
# XML=/etc/xdg/xdg-xubuntu/xfce4/xfconf/xfce-perchannel-xml
# BG=/usr/share/xfce4/backdrops
# mkdir -p $XML
# cat >$XML/xfce4-desktop.xml <<"EOF"
# <?xml version="1.0" encoding="UTF-8"?>
# <channel name="xfce4-desktop" version="1.0">
# <property name="desktop-icons" type="empty">
# <property name="style" type="int" value="2"/>
# <property name="file-icons" type="empty">
# <property name="show-home" type="bool" value="true"/>
# <property name="show-filesystem" type="bool" value="true"/>
# <property name="show-removable" type="bool" value="true"/>
# <property name="show-trash" type="bool" value="true"/>
# </property>
# </property>
# <property name="backdrop" type="empty">
# <property name="screen0" type="empty">
# <property name="monitor0" type="empty">
# <property name="image-path" type="string"
# value="/usr/share/xfce4/backdrops/nilmdbuntu.png"/>
# <property name="image-show" type="bool" value="true"/>
# <property name="image-style" type="int" value="4"/>
# <property name="color-style" type="int" value="0"/>
# <property name="color1" type="array">
# <value type="uint" value="0"/>
# <value type="uint" value="0"/>
# <value type="uint" value="0"/>
# <value type="uint" value="65535"/>
# </property>
# </property>
# <property name="monitor1" type="empty">
# <property name="image-path" type="string"
# value="/usr/share/xfce4/backdrops/nilmdbuntu.png"/>
# <property name="image-show" type="bool" value="true"/>
# <property name="image-style" type="int" value="4"/>
# <property name="color-style" type="int" value="0"/>
# <property name="color1" type="array">
# <value type="uint" value="0"/>
# <value type="uint" value="0"/>
# <value type="uint" value="0"/>
# <value type="uint" value="65535"/>
# </property>
# </property>
# </property>
# </property>
# </channel>
# EOF
# sed -i -s -e 's/Greybird/Default/g' $XML/xfwm4.xml || true
# sed -i -s -e 's/Greybird/Clearlooks/g' $XML/xsettings.xml || true
# sed -i -s -e \
# 's/elementary-xfce-dark(er)?/elementary-xfce/g' $XML/xsettings.xml || true

# Firefox defaults
cat >/etc/firefox/syspref.js <<"EOF"
pref("browser.startup.homepage", "http://nilmdb.com/");
EOF
cat >/etc/xul-ext/homepage.properties <<"EOF"
browser.startup.homepage=http://nilmdb.com/
EOF
cat >/etc/xul-ext/ubufox.js <<"EOF"
pref("browser.startup.homepage", "file:/etc/xul-ext/homepage.properties");
pref("browser.startup.homepage", "http://wattsworth.net/");
EOF
#cat >/etc/xul-ext/homepage.properties <<"EOF"
#browser.startup.homepage=http://nilmdb.com/
#EOF
#cat >/etc/xul-ext/ubufox.js <<"EOF"
#pref("browser.startup.homepage", "file:/etc/xul-ext/homepage.properties");
#EOF

Loading…
Cancel
Save