-
Notifications
You must be signed in to change notification settings - Fork 17
/
setup.sh
executable file
·298 lines (253 loc) · 8.49 KB
/
setup.sh
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#!/bin/bash
#
# cd /home/pi/
# wget -O setup.sh https://raw.githubusercontent.com/chirimen-oh/chirimen/master/setup.sh
# chmod 777 setup.sh
# ./setup.sh
#
# 一時的にスリープを無効
sudo xset s off
sudo xset -dpms
sudo xset s noblank
# スリープを無効
grep 'consoleblank=0' /boot/cmdline.txt
if [ $? -ge 1 ]; then
sudo sed '1s/$/ consoleblank=0/' /boot/cmdline.txt |\
sudo tee /tmp/cmdline && sudo cat /tmp/cmdline |\
sudo tee /boot/cmdline.txt && sudo rm -f /tmp/cmdline
fi
if [ ! -f /etc/xdg/lxsession/LXDE-pi/autostart.orig ]; then
sudo cp /etc/xdg/lxsession/LXDE-pi/autostart /etc/xdg/lxsession/LXDE-pi/autostart.orig
fi
sudo sh -c "cat << EOF > /etc/xdg/lxsession/LXDE-pi/autostart
@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@xscreensaver -no-splash
@xset s off
@xset -dpms
@xset s noblank
@/usr/bin/chromium-browser https://localhost/top
EOF"
# aptをmirrorで指定
sudo sh -c "cat << EOF > /etc/apt/mirrors.txt
http://ftp.jaist.ac.jp/raspbian/
http://ftp.tsukuba.wide.ad.jp/Linux/raspbian/raspbian/
http://ftp.yz.yamagata-u.ac.jp/pub/linux/raspbian/raspbian/
http://raspbian.raspberrypi.org/raspbian/
EOF"
if [ ! -f /etc/apt/sources.list.orig ]; then
sudo cp /etc/apt/sources.list /etc/apt/sources.list.orig
fi
sudo sh -c "cat << EOF > /etc/apt/sources.list
deb mirror+file:/etc/apt/mirrors.txt buster main contrib non-free rpi
EOF"
sudo apt-get update
# 必要な項目をインストール
sudo apt-get install at-spi2-core
# update
sudo apt-get -y update
sudo apt-get -y upgrade
# raspiはupgrade失敗しやすいので念の為2回
sudo apt-get -y update
sudo apt-get -y upgrade
# 各種ツールをインストール
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get -y install fonts-noto-cjk uim uim-mozc nodejs apache2 arduino code vim emacs libnss3-tools
# インストール失敗しやすいので2回
sudo apt-get -y install fonts-noto-cjk uim uim-mozc nodejs apache2 arduino code vim emacs libnss3-tools
sudo apt-get -y autoremove
# Node.jsのバージョンの差異による不具合を防ぐ目的
sudo apt-mark hold nodejs
# 利用者のNode.jsのバージョン管理目的
sudo npm i n -g
# 日本語設定
# デフォルトの設定が en_GB.UTF-8 になっている
sudo sed 's/#\sen_GB\.UTF-8\sUTF-8/en_GB\.UTF-8 UTF-8/g' /etc/locale.gen |\
sudo tee /tmp/locale && sudo cat /tmp/locale |\
sudo tee /etc/locale.gen && sudo rm -f /tmp/locale
sudo sed 's/#\sja_JP\.EUC-JP\sEUC-JP/ja_JP\.EUC-JP EUC-JP/g' /etc/locale.gen |\
sudo tee /tmp/locale && sudo cat /tmp/locale |\
sudo tee /etc/locale.gen && sudo rm -f /tmp/locale
sudo sed 's/#\sja_JP\.UTF-8\sUTF-8/ja_JP\.UTF-8 UTF-8/g' /etc/locale.gen |\
sudo tee /tmp/locale && sudo cat /tmp/locale |\
sudo tee /etc/locale.gen && sudo rm -f /tmp/locale
sudo locale-gen ja_JP.UTF-8
sudo update-locale LANG=ja_JP.UTF-8
# 時間設定
sudo raspi-config nonint do_change_timezone Asia/Tokyo
# キーボード設定
sudo raspi-config nonint do_configure_keyboard jp
# Wi-Fi設定
sudo raspi-config nonint do_wifi_country JP
# VSCode extension
sudo npm i eslint prettier -g
code --install-extension MS-CEINTL.vscode-language-pack-ja
code --install-extension dbaeumer.vscode-eslint
code --install-extension esbenp.prettier-vscode
# VSCode設定
mkdir -p /home/pi/.config/Code/User
cat << EOF > /home/pi/.config/Code/User/settings.json
{
"editor.fontFamily": "'Noto Sans Mono CJK JP', 'Droid Sans Mono', 'monospace', monospace, 'Droid Sans Fallback'",
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
}
EOF
mkdir -p /home/pi/.vscode
cat << EOF > /home/pi/.vscode/argv.json
{
"locale": "ja"
}
EOF
# JSのデフォルトをVSCodeに
cat << EOF > /home/pi/.config/mimeapps.list
[Added Associations]
application/javascript=code.desktop;
[Default Applications]
application/javascript=code.desktop;
EOF
# カメラを有効化
sudo raspi-config nonint do_camera 0
grep 'bcm2835-v4l2' /etc/modprobe.d/bcm2835-v4l2.conf
if [ $? -ge 1 ]; then
echo 'options bcm2835-v4l2 gst_v4l2src_is_broken=1' | sudo tee -a /etc/modprobe.d/bcm2835-v4l2.conf
fi
grep 'bcm2835-v4l2' /etc/modules-load.d/modules.conf
if [ $? -ge 1 ]; then
echo 'bcm2835-v4l2' | sudo tee -a /etc/modules-load.d/modules.conf
fi
# I2Cを有効化
sudo raspi-config nonint do_i2c 0
# _gc設定
cd /home/pi/
if [ ! -f /home/pi/_gc.zip ]; then
wget https://r.chirimen.org/_gc.zip
fi
if [ ! -d /home/pi/_gc/ ]; then
unzip ./_gc.zip
fi
cd /home/pi/_gc/srv
npm i
sudo npm i forever -g
cd /home/pi/
crontab -l > /tmp/tmp_crontab
grep '/home/pi/_gc/srv/startup.sh' /tmp/tmp_crontab
if [ $? = 1 ]; then
echo "@reboot sudo -u pi /home/pi/_gc/srv/startup.sh" | crontab
fi
ln -s /home/pi/_gc/srv/reset.sh /home/pi/Desktop/reset.sh
mkdir /home/pi/.config/chromium/
mkdir /home/pi/.config/chromium/Default/
cp /home/pi/_gc/bookmark/Bookmarks /home/pi/.config/chromium/Default/Bookmarks
pcmanfm --set-wallpaper /home/pi/_gc/wallpaper/wallpaper-720P.png
# Web Bluetooth有効化
cat << EOF > '/home/pi/.config/chromium/Local State'
{"browser":{"enabled_labs_experiments":["enable-experimental-web-platform-features"]}}
EOF
# gc設定
chromium-browser &
cd /home/pi/
if [ ! -f /home/pi/gc.zip ]; then
wget https://r.chirimen.org/gc.zip
fi
# chromiumの起動待ちダウンロード
if [ ! -d /home/pi/Desktop/gc/ ]; then
unzip ./gc.zip -d /home/pi/Desktop
fi
# chromiumの起動待ち
sleep 120s
# Apache設定
if [ ! -f /etc/apache2/sites-available/000-default.conf.orig ]; then
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/000-default.conf.orig
fi
sudo sh -c 'cat << EOF > /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /home/pi/Desktop/gc
ErrorLog \${APACHE_LOG_DIR}/error.log
CustomLog \${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
EOF'
if [ ! -f /etc/apache2/apache2.conf.orig ]; then
sudo cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf.orig
fi
sudo sh -c 'cat << EOF > /etc/apache2/apache2.conf
DefaultRuntimeDir \${APACHE_RUN_DIR}
PidFile \${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User \${APACHE_RUN_USER}
Group \${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog \${APACHE_LOG_DIR}/error.log
LogLevel warn
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory /home/pi/Desktop/gc>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
AccessFileName .htaccess
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf
EOF'
sudo sh -c 'cat << EOF > /etc/apache2/sites-available/vhost-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin webmaster@localhost
DocumentRoot /home/pi/Desktop/gc
ErrorLog \${APACHE_LOG_DIR}/error.log
CustomLog \${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /home/pi/_gc/srv/crt/server.crt
SSLCertificateKeyFile /home/pi/_gc/srv/crt/server.key
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
</VirtualHost>
</IfModule>
EOF'
sudo a2ensite vhost-ssl
sudo a2enmod ssl
sudo systemctl restart apache2
# 証明書追加
certfile="/home/pi/_gc/srv/crt/ca.crt"
certname="org-TripArts"
for certDB in $(find ~/ -name "cert9.db")
do
certdir=$(dirname ${certDB});
certutil -A -n "${certname}" -t "TCu,Cu,Tu" -i ${certfile} -d sql:${certdir}
done
####
# 最後にダイアログをOKにしてrebootして完了
####
sudo reboot