-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathimage.sh
More file actions
260 lines (205 loc) · 5.12 KB
/
image.sh
File metadata and controls
260 lines (205 loc) · 5.12 KB
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
#!/bin/bash
set -e
DATE=`date '+%Y%m%d%H%M%S'`
HOME="/home/pi"
SERVICE="pinkcoin.service"
allowScripts() {
FILE="/etc/sudoers.d/pinkpi"
cat > "$FILE" << EOL
# Enable scripts controlled by user action (or crontab PHP)
www-data ALL=(ALL) NOPASSWD: /home/pi/scripts/network_*.sh
www-data ALL=(ALL) NOPASSWD: /home/pi/scripts/transactions_*.sh
www-data ALL=(ALL) NOPASSWD: /home/pi/scripts/wallet_*.sh
EOL
# Correct permissions
chmod 440 "$FILE"
}
configureHostname() {
HOST="pinkpi.local"
# Setup hostname resolve
echo "172.24.1.2 $HOST" >> "/etc/hosts"
# Change hostname
hostnamectl set-hostname "$HOST"
}
configureSwap() {
# 2GB swap allocation (default: 100MB)
sed -i 's/.*CONF_SWAPSIZE=.*/CONF_SWAPSIZE=1024/' "/etc/dphys-swapfile"
# Restart swap service
"/etc/init.d/dphys-swapfile" restart
}
createPinkcoinService() {
FILE="/etc/systemd/system/$SERVICE"
cat > "$FILE" << EOL
[Unit]
Description=Pinkcoin Wallet
Wants=network.target
After=network.target
[Service]
User=pi
Group=pi
WorkingDirectory=~
RuntimeDirectory=pinkcoin
Type=forking
ExecStart=/usr/bin/pink2d
ExecStop=/usr/bin/pink2d stop
PIDFile=$HOME/.pink2/pinkcoind.pid
Restart=always
RestartSec=60
TimeoutStartSec=0
TimeoutStopSec=120
[Install]
WantedBy=multi-user.target
EOL
# Correct file permissions
chmod 664 "$FILE"
# Refresh System Control
systemctl daemon-reload
# Enable the Pinkcoin Wallet
systemctl enable "$SERVICE"
}
createWWW() {
DIR="/etc/nginx"
# Create include file dependencies
cat > "$DIR/conf.d/upstream_php.conf" << EOL
upstream php {
server unix:/run/php/php7.0-fpm.sock;
}
EOL
cat > "$DIR/fastcgi" << EOL
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param HTTP_MOD_REWRITE on;
fastcgi_pass php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
EOL
cat > "$DIR/fastcgi_params" << EOL
fastcgi_param SCRIPT_FILENAME \$realpath_root\$fastcgi_script_name;
fastcgi_param QUERY_STRING \$query_string;
fastcgi_param REQUEST_METHOD \$request_method;
fastcgi_param CONTENT_TYPE \$content_type;
fastcgi_param CONTENT_LENGTH \$content_length;
fastcgi_param SCRIPT_NAME \$fastcgi_script_name;
fastcgi_param REQUEST_URI \$request_uri;
fastcgi_param DOCUMENT_URI \$document_uri;
fastcgi_param DOCUMENT_ROOT \$realpath_root;
fastcgi_param SERVER_PROTOCOL \$server_protocol;
fastcgi_param REQUEST_SCHEME \$scheme;
fastcgi_param HTTPS \$https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/\$nginx_version;
fastcgi_param REMOTE_ADDR \$remote_addr;
fastcgi_param REMOTE_PORT \$remote_port;
fastcgi_param SERVER_ADDR \$server_addr;
fastcgi_param SERVER_PORT \$server_port;
fastcgi_param SERVER_NAME \$server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
EOL
cat > "$DIR/sites-available/default" << EOL
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /home/pi/html;
index index.html index.php;
location /generate_204 {
return 302 http://pinkpi.local/settings/;
}
location / {
try_files \$uri \$uri/ =404;
}
location ~* \.(css|gif|html|ico|js|jpg|jpeg|pdf|png|svg|txt|xml)$ {
access_log off;
expires 1m;
log_not_found off;
}
location ~* \.php$ {
try_files \$uri \$uri/ =404;
include fastcgi;
}
}
EOL
# Restart Nginx to take effect
systemctl restart nginx
}
installUi() {
DIR="$HOME/pinkpiui"
TAG="0.1.10"
TARGET="$DIR/$DATE"
URL_REPO="https://github.com/Pink2Dev/PinkPiUi"
# Download latest version
git clone --branch "$TAG" "$URL_REPO" "$TARGET"
if [ $? -ne 0 ]
then
exit 0
fi
# Mark current version
echo "$TAG" > "$TARGET/VERSION"
# Correct permissions
chown -R pi:pi "$DIR"
chown -R pi:pi "$TARGET"
# Install PinkPiUi
"$TARGET/scripts/ui_upgrade.sh"
# Correct permissions
chown pi:pi "$DIR/VERSION"
}
installWallet() {
DIR="$HOME/pinkcoin"
TAG="2.1.0.4"
TARGET="$DIR/$DATE"
URL_REPO="https://github.com/Pink2Dev/Pink2"
# Download latest version
git clone --branch "$TAG" "$URL_REPO" "$TARGET"
if [ $? -ne 0 ]
then
exit 0
fi
# Mark current version
echo "$TAG" > "$TARGET/VERSION"
# Create directory
mkdir -p "$HOME/.pink2"
# Placeholder cofiguration
cat > "$HOME/.pink2/pinkconf.txt" << EOL
daemon=1
listen=1
rpcallowip="127.0.0.1"
rpcpassword="password"
rpcport=31415
rpcssl=0
rpcsslciphers="TLSv1.2+HIGH:TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!3DES:@STRENGTH"
rpcuser="username"
server=1
staking=1
txindex=1
EOL
# Correct permissions
chown -R pi:pi "$DIR"
chown -R pi:pi "$TARGET"
chown -R pi:pi "$HOME/.pink2"
chmod 755 "$HOME/.pink2"
}
# Adjust swap size
configureSwap
# Configure hostname
configureHostname
# Update to latest
apt-get clean
apt-get update
apt-get dist-upgrade -y
apt-get autoclean
# Install dependencies
apt-get install -y dnsmasq hostapd samba git nginx php-fpm php-bcmath php-curl
# Install web server
createWWW
# Enable Pinkcoin Wallet
createPinkcoinService
# Install initial PinkPiUi version
installUi
# Install initial Pinkcoin Wallet version
installWallet
# Allow interface to execute scripts
allowScripts
# Setup Maintenance
ln -fns "$HOME/crontab/pinkpi" /etc/cron.d/pinkpi
# Self-destruct
rm "$0"