summarylogtreecommitdiffstats
path: root/ethoscope-device.install
blob: 880454f7ccccc5fcdb48856f677c6daf8a7dfa8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
## arg 1:  the new package version
#pre_install() {
	# do something here
#}

# arg 1:  the new package version
post_install() {
    echo "changing the remote GIT source to BARE on node"
    cd /opt/ethoscope-device
    git remote set-url origin git://node/ethoscope.git

    echo "setting GIT branch"
    git checkout dev

    echo "installing python package"
    cd /opt/ethoscope-device/src
    python setup.py develop

    echo "create 000 machine files"
    echo "ETHOSCOPE_000" > /etc/machine-name
    echo "ETHOSCOPE_000" > /etc/hostname

    echo "create an ethoclient command"
    echo $'#!/bin/env bash\npython /opt/ethoscope-device/src/scripts/ethoclient.py $@' > /usr/bin/ethoclient
    chmod +x /usr/bin/ethoclient

    echo "create the default network configuration files"
    echo $'[Match]\nName=eth0\n\n[Network]\nDHCP=yes\n\n[DHCPv4]\nRouteMetric=10\n' > /etc/systemd/network/20-wired.network
    echo $'[Match]\nName=wlan0\n\n\n[Network]\nDHCP=yes\n\n[DHCPv4]\nRouteMetric=20\n' > /etc/systemd/network/25-wireless.network
    systemctl enable systemd-networkd --now

    wpa_passphrase ETHOSCOPE_WIFI ETHOSCOPE_1234 > /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
    systemctl enable wpa_supplicant --now
    systemctl enable wpa_supplicant@wlan0.service

    #create a verbose login prompt
    echo 'Ethoscope Linux \r  (\n) (\l)' > /etc/issue
    echo 'Ethernet IP: \4{eth0}' >> /etc/issue
    echo 'WIFI IP: \4{wlan0}' >> /etc/issue
    echo 'Time on Device: \d \t' >> /etc/issue

    echo "activates remote journal upload"
    echo $'[Upload]\nURL=http://node:19532\n' > /etc/systemd/journal-upload.conf

    echo "configure the NTP file"
    echo 'server node' > /etc/ntp.conf
    echo 'server 127.127.1.0' >> /etc/ntp.conf
    echo 'fudge 127.127.1.0 stratum 10' >> /etc/ntp.conf
    echo 'restrict default kod limited nomodify nopeer noquery notrap' >> /etc/ntp.conf
    echo 'restrict 127.0.0.1' >> /etc/ntp.conf
    echo 'restrict ::1' >> /etc/ntp.conf
    echo 'driftfile /var/lib/ntp/ntp.drift' >> /etc/ntp.conf

    echo "enabling DEVICE specific systemd service files"
    systemctl enable ethoscope_device.service ethoscope_listener.service ethoscope_update.service ethoscope_GPIO_listener.service
    systemctl enable ntpd.service mysqld.service sshd.service mysqld.service avahi-daemon.service
    #systemctl enable fake-hwclock fake-hwclock-save.timer

    echo "Set up mysql database"
    mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
    systemctl start mysqld.service
    mysql -u root -e "CREATE USER 'ethoscope'@'localhost' IDENTIFIED BY 'ethoscope'"
    mysql -u root -e "CREATE USER 'ethoscope'@'%' IDENTIFIED BY 'ethoscope'"
    mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO 'ethoscope'@'localhost' WITH GRANT OPTION";
    mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO 'ethoscope'@'%' WITH GRANT OPTION";
    chown -R mysql:mysql /var/lib/mysql

    #echo "creating and handling binary log in mariadb configuration"
    #echo '[server]' > /etc/my.cnf.d/server.cnf
    #echo 'log-bin=mysql-bin' >> /etc/my.cnf.d/server.cnf
    #echo 'binlog_format=mixed' >> /etc/my.cnf.d/server.cnf
    #echo 'expire_logs_days = 10' >> /etc/my.cnf.d/server.cnf
    #echo 'max_binlog_size  = 100M' >> /etc/my.cnf.d/server.cnf

    echo "install picamera settings into the boot/config.txt"
    echo 'start_file=start_x.elf' > /boot/config.txt
    echo 'fixup_file=fixup_x.dat' >> /boot/config.txt
    echo 'disable_camera_led=1' >> /boot/config.txt
    echo 'gpu_mem=256' >> /boot/config.txt
    echo 'cma_lwm=' >> /boot/config.txt
    echo 'cma_hwm=' >> /boot/config.txt

    echo 'cma_offline_start=' >> /boot/config.txt
    echo 'hdmi_force_hotplug=1' >> /boot/config.txt

    # https://github.com/raspberrypi/firmware/issues/1167
    echo 'awb_auto_is_greyworld=1' >> /boot/config.txt

    echo 'Loading bcm2835 module'
    echo 'bcm2835-v4l2' > /etc/modules-load.d/picamera.conf

    echo "limiting journal log space"
    echo 'SystemMaxUse=250MB' >> /etc/systemd/journald.conf

    echo "generating locale"
    echo "en_GB.UTF-8 UTF-8" >> /etc/locale.gen
    locale-gen

    echo "disable bluetooth"
    echo 'dtoverlay=pi3-disable-bt' >> /boot/config.txt

    #https://madflex.de/use-i2c-on-raspberry-pi-with-archlinux-arm/
    echo "adding support to I2C"
    echo 'dtparam=i2c_arm=on' >> /boot/config.txt
    echo 'i2c-dev' >> /etc/modules-load.d/raspberrypi.conf

    echo "Please reboot this PI now."

}

## arg 1:  the new package version
## arg 2:  the old package version
#pre_upgrade() {
    # do something here
#}

# arg 1:  the new package version
# arg 2:  the old package version
post_upgrade() {
    echo "changing the remote GIT source to BARE on node"
    cd /opt/ethoscope-device
    git remote set-url origin git://node/ethoscope.git

    #setting branch
    git checkout dev
}

# arg 1:  the old package version
pre_remove() {
    echo "disabling systemd service files"
    systemctl disable ethoscope_device.service ethoscope_listener.service ethoscope_update.service ethoscope_GPIO_listener.service
}

## arg 1:  the old package version
#post_remove() {
    # do something here
#}