This repository has been archived by the owner on Sep 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
odroid-setup.sh
207 lines (185 loc) · 7.78 KB
/
odroid-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
#!/bin/bash
################################
### ###
### Config Section ###
### ###
################################
# Change stuff to match in here. Add ALL your gluster nodes to the clusterhosts before you run this script
# Hostname of the node you are adding
HN=gluster10tb06
# Get your IP cause DHCP FTW
MAINIP=$(ip route get 1 | awk '{print $7;exit}')
# Pick a filesystem. I would choose either ext4 or xfs. It's up to you!
FILESYSTEM=ext4
# Name of the encrypted volume. This can be anything you want
CRYPTVOL=securedata
# This is where we are mounting the 3.5" drive
MOUNTPOINT=/gluster
# This is what we are naming the brick.
BRICKNAME=brick1
# GTYPE can be "distributed" or "dispersed". This is the type of volume you will be setting up. If using replicated disable BURST
GTYPE=distributed
# Do you want to set up Telegraf? 1 is on 0 is off. You need influx and grafana for this to be of any use.
TELEGRAF=1
INFLUXSERVER=http://192.168.2.4:8086
# Do you want to mine burst on your free space? Set to 0 to disable.
BURST=0
# Enter the Pool you want to use.
BURSTPOOL=http://voiplanparty.com:8124
# Don't know if you really need this but this is the account id for which you are mining.
BURSTACCOUNT=XXXXXXXXXXXXXXXXXXXXXXX
# This is based on total TB you are mining with. Do research on the pool and the space you have for mining.
BURSTDEADLINE=11087847
# This path is dependant on the type of volume in gluster you are creating
if [ $GTYPE == "distributed" ]; then
BURSTPATH=/$MOUNTPOINT/$BRICKNAME/burst
else
BUSTPATH=/$MOUNTPOINT/burst
fi
###############################
### ###
### This is the magic ###
### ###
###############################
# Don't mess with anything below this unless you know what you are doing.
if [ ! -f 1stboot ]; then
# Set the Hostname
hostnamectl set-hostname $HN
# Change the hosts file
sed -i "s/odroid/$HN/g" /etc/hosts
# Add all the nodes to the local hosts file
cat clusterhosts | while read line
do
echo $line >> /etc/hosts
done
# Add the new gluster node to all the other nodes
# Yes this is lame
cat clusterhosts | grep -v $HN | awk '{print $1}' >> hostscluster
CMD=$(echo "$MAINIP $HN")
echo $CMD
for host in $(cat hostscluster); do ssh -o StrictHostKeyChecking=accept-new root@$host sudo echo "$CMD >> /etc/hosts"; done
rm hostscluster
# Update the OS
apt update
echo "Upgrading all the things"
apt -y upgrade
# Install some tools we need.
apt -y install wget parted curl cryptsetup
# Add some Repos
wget -O- https://download.gluster.org/pub/gluster/glusterfs/3.12/rsa.pub | apt-key add -
add-apt-repository ppa:gluster/glusterfs-4.1
wget -O- https://repos.influxdata.com/influxdb.key | apt-key add -
echo "deb https://repos.influxdata.com/ubuntu bionic stable" > /etc/apt/sources.list.d/influxdata.list
apt update
# Install what we came here for.
echo "Installing Gluster Server.. This will error out sometimes but that is ok."
apt install glusterfs-server -y
echo " If you got an error about gluster server don't worry about it."
touch 1stboot
echo "Rebooting in 30s... Re-run this script when you log in again."
sleep 30
reboot
fi
if [ -f 1stboot ]; then
# Toss up the warning. Can't say I didn't warn you!
install="no"
while [ "$install" != "yes" ]; do
echo "###########################################"
echo "## ** W A R N I N G ** ##"
echo "## _______________________________ ##"
echo "## ##"
echo "## If you continue from here ##"
echo "## ALL DATA on the 3.5 inch drive ##"
echo "## WILL BE DESTROYED! ##"
echo "## ##"
echo "## ** ALL DATA WILL BE LOST ** ##"
echo "###########################################"
echo "Do you wish to continue? (Type the entire word "yes" to proceed.) "
read install
done
# Partition and encrypt
echo "Nuking all the partitions on the 3.5 incher"
dd if=/dev/zero of=/dev/sda bs=512 count=1
echo "Partitioning the drive"
parted -a opt /dev/sda mktable gpt
parted -a opt /dev/sda mkpart primary 0% 100%
# Crypto Time
echo "Loading Crypto Modules into the Kernel"
modprobe dm-crypt sha256 aes
# Wipe the partition
echo "Wiping the partition"
wipefs -a /dev/sda1
# This key is used to auto mount the drive on reboot. If someone swipes your entire system then they could get to the data.
# The main reason for this is so that if you RMA a drive your data is encrypted.
# This is not meant to protect you from the Matrix.
echo "Generating a random key for auto mount purposes"
dd if=/dev/urandom of=/root/keyfile bs=1024 count=4
chmod 400 /root/keyfile
# Make this like at least 32 characters
echo "Make a hard password and remember it or store in a password manager"
cryptsetup --verify-passphrase luksFormat /dev/sda1 -c aes-ctr-plain -h sha256 -s 128
echo "Opening the encrypted volume"
cryptsetup luksOpen /dev/sda1 $CRYPTVOL
ls -la /dev/mapper
echo "Creating a $FILESYSTEM filesystem on the encrypted volume $CRYPTVOL"
mkfs -t $FILESYSTEM -m 1 /dev/mapper/$CRYPTVOL
echo "Closing the volume so we can apply the key to it for booting.. This will take a sec"
cryptsetup -v luksClose $CRYPTVOL
sleep 30
echo " Applying key to the volume. You will need that password again."
cryptsetup luksAddKey /dev/sda1 /root/keyfile
echo "Setting up the crypttab"
echo "$CRYPTVOL /dev/sda1 /root/keyfile luks" >> /etc/crypttab
echo "Assigning the key to cryptdisks"
sed -i "/CRYPTDISKS_MOUNT*/c\CRYPTDISKS_MOUNT=\"/root/keyfile\"" /etc/default/cryptdisks
mkdir -p $MOUNTPOINT
echo "Adding the mount to /etc/fstab FIX THE TABS HERE"
echo "/dev/mapper/$CRYPTVOL $MOUNTPOINT $FILESYSTEM default,rw 0 2" >> /etc/fstab
echo "Mounting the encrypted drive. You will need that PW one last time"
cryptsetup luksOpen /dev/sda1 $CRYPTVOL
mount -a
mkdir -p $MOUNTPOINT/$BRICKNAME
# Get Telegraf rocking if it is enabled.
if [ $TELEGRAF == 1 ]; then
echo "Installing Telegraf to monitor the things"
apt -y install telegraf smartmontools
mkdir -p /var/log/temps
touch /var/log/temps/hddtemps.log
cp drivetemp.sh /usr/sbin/
chmod 755 /usr/sbin/drivetemp.sh
# Add the job to Cron
echo "*/10 * * * * root /usr/sbin/drivetemp.sh" > /etc/cron.d/hddtemp
cp telegraf.conf /etc/telegraf/
sed -i "s/ACIDINFLUX/$INFLUXSERVER/g" /etc/telegraf/telegraf.conf
systemctl restart telegraf
systemctl enable telegraf
fi
if [ $BURST == 1 ]; then
echo "Installing Burst"
wget https://github.com/TOoSmOotH/glusterdroid/releases/download/scav1.6.6/scavenger-1.6.6-odroid.tar.gz
tar zxf scavenger-1.6.6-odroid.tar.gz
mkdir -p /opt
mv release /opt/scavenger
cp burstconfig.yaml /opt/scavenger/config.yaml
sed -i "s/POOL/$BURSTPOOL/g" /opt/scavenger/config.yaml
sed -i "s/PLOTPATH/$BURSTPATH/g" /opt/scavenger/config.yaml
sed -i "s/DEADLINE/$BURSTDEADLINE/g" /opt/scavenger/config.yaml
sed -i "s/ACNT/$BURSTACCOUNT/g" /opt/scavenger/config.yaml
# Install screen
apt -y install screen
# Create a junky script
echo "cd /opt/scavenger" > /usr/sbin/scav.sh
echo "./scavenger" >> /usr/sbin/scav.sh
chmod +x /usr/sbin/scav.sh
echo "screen -dmS scav /usr/sbin/scav.sh" > /usr/sbin/screenscav.sh
chmod +x /usr/sbin/screenscav.sh
# Add this so it starts at boot
cp scav.service /etc/systemd/system/
systemctl daemon-reload
systemctl enable scav.service
# Launch scavenger in the background. You can connect by doing screen -r scav
systemctl start scav
fi
# This should not be automated because there are a multitude of options here.
echo "All Done. It's up to you to handle the gluster volume creation"
fi