-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall-base-archlinuxarm.sh
296 lines (254 loc) · 7.91 KB
/
install-base-archlinuxarm.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
#!/bin/bash
######################################################################
# #
# Copyright (c) 2017 revosftw (https://github.com/revosftw) #
# #
######################################################################
RED='\033[0;41;30m'
STD='\033[0;0;39m'
RELEASE=" > /dev/null 2>&1"
DEBUG=""
DFLAG=$DEBUG
function pause() {
read -p "Press [Enter] key to continue..." fackEnterKey
}
function updateSystem() {
echo -e "Updating System"
pacman --noconfirm --needed -Syu ${DFLAG}
}
function installPackage() {
pacman --noconfirm --needed -S $@ ${DFLAG}
}
function initializePacman() {
pacman --noconfirm --needed -Sy pacman ${DFLAG}
pacman-key --init ${DFLAG}
installPackage archlinux-keyring
pacman-key --populate archlinux ${DFLAG}
}
function configurePacman() {
echo -e "Setting options for pacman"
cp /etc/pacman.conf /etc/pacman.conf.bak
sed -i '/Color/s/^#//' /etc/pacman.conf
sed -i 's/#XferCommand = \/usr\/bin\/wget --passive-ftp -c -O %o %u/XferCommand = \/usr\/bin\/wget --passive-ftp -c -q --show-progress -O \x27%o\x27 \x27%u\x27/' /etc/pacman.conf
}
function installBarebone() {
updateSystem
initializePacman
pacman --noconfirm --needed -Syu --ignore filesystem ${DFLAG}
pacman --noconfirm --needed -S filesystem --force ${DFLAG}
echo -e "Installing Base Packages"
installPackage base-devel vim wget diffutils htop ntp packer
echo -e "Install filesystems"
installPackage filesystem nfs-utils autofs ntfs-3g
}
function installWireless() {
echo -e "Installing WiFi packages"
installPackage dialog wpa_supplicant wireless_tools iw crda lshw
}
function installAudio() {
echo -e "Installing Audio packages"
installPackage alsa-utils alsa-firmware alsa-lib alsa-plugins
}
function configureTimezone() {
echo -e "Setting timezone"
timedatectl set-local-rtc 0
local timezone
read -p "Enter a timezone(ex. Asia/Kolkata):" timezone
timezone=${timezone:="Asia/Kolkata"}
echo -e "$timezone" | tee /etc/timezone
systemctl stop ntpd.service
systemctl enable ntpd.service
systemctl start ntpd.service
}
function configureHostname() {
local hostname
read -p "Enter hostname(ex. alarmpi):" hostname
hostname=${hostname:=alarmpi}
hostnamectl set-hostname $hostname
}
function configureNewUser() {
local username
read -p "Enter username[pi]:" user
username=${username:="pi"}
getent passwd $username > /dev/null
if [ $? -eq 0 ]; then
updateUserConfiguration $username
else
useradd -m $username
updateUserConfiguration $username
fi
}
function addRootPriviledgesUser() {
local username=$1
echo -e "Adding root priviledges to $username"
echo -e "$username ALL=(ALL) NOPASSWD:ALL" | tee -a /etc/sudoers
}
function addRootPriviledgesGroup() {
local groupname=$1
echo -e "Adding root priviledges to $groupname"
echo -e "%$groupname ALL=(ALL) NOPASSWD:ALL" | tee -a /etc/sudoers
}
function updateUserConfiguration() {
local username=$1
chfn "$username"
passwd "$username"
local response
read -p "Grant root priviledges to $username?" response
if echo "$response" | grep -iq "^Y"; then
addRootPriviledgesUser $username
fi
}
function deleteOldUser() {
userdel $1
rm -rf /home/${1}
}
function configureBarebone() {
echo -e "Enter new root password: "
passwd
#Set up timezone
configureTimezone
#Set a new hostname
configureHostname
#Setup a new user
configureNewUser
#Setup WiFi
configureWireless
#clean pacman cache
pacman --noconfirm -Scc
pause
}
function installYaourt() {
cd /tmp
#su $default_user
wget https://aur.archlinux.org/packages/pa/package-query/package-query.tar.gz
tar -xvzf package-query.tar.gz
cd package-query
makepkg -si
cd ..
wget https://aur.archlinux.org/packages/ya/yaourt/yaourt.tar.gz
tar -xvzf yaourt.tar.gz
cd yaourt
makepkg -si
}
function installZSH() {
echo -e "Installing ZSH"
installPackage zsh
echo -e "Installing grml-zsh"
curl -L "http://git.grml.org/f/grml-etc-core/etc/zsh/zshrc" --output /home/"$1"/.zshrc${DFLAG}
curl -L "http://git.grml.org/f/grml-etc-core/etc/skel/.zshrc" --output /home/"$1"/.zshrc.local ${DFLAG}
chown /home/"$1"/.zshrc* "$1:$1"
usermod -s /bin/zsh "$1"
}
function installRaspiconfig() {
echo -e "Downloading Raspi-Config"
curl -L https://raw.githubusercontent.com/revosftw/alarmpi_box/master/raspi-config --output /usr/bin/raspi-config
chmod +x /usr/bin/raspi-config;
echo -e "Installed Raspi-Config"
}
function installPython2() {
echo -e "Installing python2"
installPackage python2 python2-pip python2-lxml
pip2 install mitmproxy
}
function installWiringPi() {
git clone git://git.drogon.net/wiringPi /opt/wiringpi
sh /opt/wiringpi/build
gpio -v
gpio readall
}
function installTransmission() {
echo -e "Installing Transmission"
installPackage transmission-cli
usermod -aG users transmission
lsblk
echo -e "Select the drive to be used: (ex:/dev/sda1,\e[1m/dev/sda2\e[21m)"
read externalDrive
externalDrive=${externalDrive:="/dev/sda2"}
echo -e "Provide torrent download folder (ex: \e[1m/media/data\e[21m,/mnt/downloads):"
read downloadFolder
downloadFolder=${downloadFolder:="/media/data"}
mkdir -p $downloadFolder
createMountPoint externalDrive downloadFolder
}
function configureTransmission() {
}
function checkMountPoint() {
if grep -qs '$1' /proc/mounts; then
echo "It's mounted."
else
echo "It's not mounted."
fi
}
function createMountPoint() {
mountDevice=$1
mountPoint=$2
fileName=$(echo $mountPoint|sed 's\^[/]\\'|sed 's\[/]\-\')
partitionType=$(blkid -s TYPE "$mountDevice" | grep -o '"[^"]*"' | sed 's/\"//g')
echo -e "[Unit]
\nDescription=xHD mount script
\n
\n[Mount]
\nWhat=$mountDevice
\nWhere=$mountPoint
\nType=$partition_type
\nOptions=defaults,gid=users,dmask=002,fmask=002" | tee /etc/systemd/system/${fileName}.mount
}
function overclockPi() {
echo -e "##OVERCLOCKING##
\n arm_freq=800
\n arm_freq_min=100
\n core_freq=300
\n core_freq_min=75
\n sdram_freq=400
\n over_voltage=0" | tee -a /boot/config.txt
}
function newRootfs() {
installPackage rsync
newroot="/mnt/newroot"
sudo mkdir ${newroot}
lsblk
echo -e "Choose new root (ex: \e[1m/dev/sda1\e[21m):"
read newrootdevice
newrootdevice=${newrootdevice:="/dev/sda1"}
echo -e "Formatting new root"
mkfs.ext4 -L "armrootfs" ${newrootdevice}
echo -e "Mounting new root"
mount ${newrootdevice} ${newroot}
rsync -avxS --info=progress2 exclude=${newroot} / ${newroot}
cp /boot/cmdline.txt /boot/cmdline.txt.bak
sed "s/root=\/dev\/mmcblk0p2/root=${newrootdevice}/" -i /boot/cmdline.txt
sed "s/elevator=noop//" -i /boot/cmdline.txt
umount ${newroot}
rm -rf ${newroot}
}
function showOptions() {
echo -e "\e[1m[1]\e[21mSetup Raspberry Pi"
echo -e "\e[1m[2]\e[21mInstall Transmission"
echo -e "\e[1m[3]\e[21mInstall Python2"
echo -e "\e[1m[4]\e[21mInstall Raspi-Config"
echo -e "\e[1m[8]\e[21mMove Root to XHD"
echo -e "\e[1m[9]\e[21mOverclock the Pi"
echo -e "\e[1m[0]\e[21mExit"
}
function readOptions() {
local choice
read -p "Enter choice:" choice
case $choice in
1)installBarebone;configureBarebone;;
2)installTransmission;;
3)installPython2;;
4)installRaspiconfig;;
8)newRootfs;;
9)overclockPi;;
0)exit 0;;
*)echo -e "$RED \e[1mERROR:\e[21m $STD INVALID SELECTION" && sleep 2
esac
}
#trap '' SIGINT SIGQUIT SIGTSTP
#main function
[ "$UID" -eq 0 ] || exec su --command="bash $0 $@"
while true;
do
showOptions
readOptions
done