-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
237 lines (213 loc) · 9.05 KB
/
install.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
#!/usr/bin/env bash
# ZeroCar2w Install Script
# by jrossmanjr -- https://github.com/jrossmnajr/zerocar2w
# Use a RaspberryPi as a WiFi hotspot to serve up files
#--------------------------------------------------------------------------------------------------------------------#
# Shoutout to the folks making PiHole, Adafruit, & PIRATEBOX for showing me the way and essentially teaching me BASH
#
# A lot of help came from ADAFRUIT -- https://learn.adafruit.com/setting-up-a-raspberry-pi-as-a-wifi-access-point/install-software
#
# Thanks to RaspberryConnect.com for some refinement of the setup code
#
# RaspiAP by billz is so awesome -- https://github.com/billz/raspap-webgui
#--------------------------------------------------------------------------------------------------------------------#
# MIT License
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
#documentation files (the "Software"), to deal in the Software without restriction, including without limitation
#the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
#and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
#THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
#OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
#OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#--------------------------------------------------------------------------------------------------------------------#
echo ":::
███████╗███████╗██████╗ ██████╗ ██████╗ █████╗ ██████╗
╚══███╔╝██╔════╝██╔══██╗██╔═══██╗██╔════╝██╔══██╗██╔══██╗
███╔╝ █████╗ ██████╔╝██║ ██║██║ ███████║██████╔╝
███╔╝ ██╔══╝ ██╔══██╗██║ ██║██║ ██╔══██║██╔══██╗
███████╗███████╗██║ ██║╚██████╔╝╚██████╗██║ ██║██║ ██║
╚══════╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝
By - jrossmanjr // https://github.com/jrossmnajr/zerocar2w "
# Find the rows and columns will default to 80x24 is it can not be detected
screen_size=$(stty size 2>/dev/null || echo 24 80)
rows=$(echo $screen_size | awk '{print $1}')
columns=$(echo $screen_size | awk '{print $2}')
# Divide by two so the dialogues take up half of the screen, which looks nice.
r=$(( rows / 2 ))
c=$(( columns / 2 ))
# Unless the screen is tiny
r=$(( r < 20 ? 20 : r ))
c=$(( c < 70 ? 70 : c ))
# Run this script as root or under sudo
if [[ $EUID -eq 0 ]];then
echo "::: You are root."
else
echo "::: sudo will be used."
# Check if it is actually installed
# If it isn't, exit because the install cannot complete
if [[ $(dpkg-query -s sudo) ]];then
export SUDO="sudo"
else
echo "::: Please install sudo or run this script as root."
exit 1
fi
fi
# Into popups and variable setup
whiptail --msgbox --title "ZeroCar2w automated installer" "\nThis installer turns your Raspberry Pi and Wifi Dongle into \nan awesome WiFi router and media streamer!" ${r} ${c}
whiptail --msgbox --title "ZeroCar2w automated installer" "\n\nFirst things first... Lets set up some variables!" ${r} ${c}
var1=$(whiptail --inputbox "Name the DLNA Server" ${r} ${c} ZeroCar2w --title "DLNA Name" 3>&1 1>&2 2>&3)
var2=$(whiptail --inputbox "Name the WiFi Hotspot" ${r} ${c} ZeroCar2w --title "Wifi Name" 3>&1 1>&2 2>&3)
var3=$(whiptail --passwordbox "Please enter a password for the WiFi hotspot (8 character min!)" ${r} ${c} --title "HotSpot Password" 3>&1 1>&2 2>&3)
var4=$(whiptail --inputbox "Please enter a folder name to put your files in" ${r} ${c} --title "Folder Name for Media" 3>&1 1>&2 2>&3)
whiptail --msgbox --title "ZeroCar2w automated installer" "\n\nOk all the data has been entered...The install will now complete!" ${r} ${c}
#--------------------------------------------------------------------------------------------------------------------#
# Functions to setup the rest of the server
#--------------------------------------------------------------------------------------------------------------------#
function delete_junk() {
# delete all the junk that has nothing to do with being a lightweight server
echo ":::"
echo "::: Removing JUNK...from the trunk"
$SUDO apt-get -y purge dns-root-data minecraft-pi python-minecraftpi wolfram-engine sonic-pi libreoffice scratch
$SUDO apt-get autoremove
echo "::: DONE!"
}
function install_the_things() {
# installing samba server so you can connect and add files easily
# installing minidlna to serve up your shit nicely
echo ":::"
echo "::: Installing Samba, Minidlna & Making Directories"
$SUDO mkdir "$var4"
$SUDO apt update
$SUDO apt install -y apt-transport-https
$SUDO apt upgrade -y
$SUDO apt install -y wget samba samba-common-bin exfat-utils exfat-fuse minidlna
echo "::: DONE installing all the things!"
}
function edit_samba() {
# editing Samba
echo ":::"
echo "::: Editing Samba... "
echo "::: You will enter a password for your Folder Share next."
$SUDO smbpasswd -a pi
$SUDO cp /etc/samba/smb.conf /etc/samba/smb.conf.bkp
echo '[Mediadrive]
comment = Public Storage
path = /home/
create mask = 0775
directory mask = 0775
read only = no
browsable = yes
writable = yes
guest ok = yes
guest only = yes' | sudo tee --append /etc/samba/smb.conf > /dev/null
$SUDO /etc/init.d/samba restart
echo "::: DONE!"
}
function instal_raspiap() {
echo ":::"
echo "::: Installing Access Pont Software..."
echo "************************"
echo "*** DO NOT RESTART!! ***"
echo "************************"
curl -sL https://install.raspap.com | bash -s -- --yes --openvpn 0 --adblock 0 --minwrite
}
function edit_hostapd() {
# editing hostapd and associated properties
echo ":::"
echo "::: Editing hostapd"
$SUDO echo 'driver=nl80211
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
beacon_int=100
auth_algs=1
wpa_key_mgmt=WPA-PSK
channel=1
hw_mode=g
interface=wlan0
wpa=2
wpa_pairwise=CCMP
rsn_pairwise=CCMP
country_code=US
macaddr_acl=0
ignore_broadcast_ssid=0
ieee80211n=1
#ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
### SSID AND PASSWORD ###
' > /etc/hostapd/hostapd.conf
echo "ssid=$var2" | sudo tee --append /etc/hostapd/hostapd.conf > /dev/null
echo "wpa_passphrase=$var3" | sudo tee --append /etc/hostapd/hostapd.conf > /dev/null
echo "::: DONE!"
}
function edit_dhcpdconf() {
# editing dhcpcd to stop it from starting the wifi network so the autostart script can
echo ":::"
echo "::: Editing dhcpd.conf"
$SUDO echo '#Defaults from Raspberry Pi configuration
hostname
clientid
persistent
option rapid_commit
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
option ntp_servers
require dhcp_server_identifier
slaac private
nohook lookup-hostname
nohook wpa_supplicant
interface wlan0
static ip_address=10.0.0.1/24
static routers=10.0.0.1
static domain_name_server=1.1.1.1 8.8.8.8' > /etc/dhcpcd.conf
echo "::: DONE!"
}
function edit_dnsmasq() {
# editing dnsmasq
echo ":::"
echo "::: Editing dnsmasq.conf"
echo "domain-needed
interface=wlan0
dhcp-range=10.0.0.2,10.0.0.245,255.255.255.0,24h" > /etc/dnsmasq.conf
echo "::: DONE"
}
function finishing_touches() {
# restarting
echo "::: Finishing touches..."
$SUDO chmod -R 777 /home/pi
$SUDO chmod -R 777 /var/log
$SUDO sysctl -p
echo "::: Please restart the Pi and then connect to the hotspot :::"
}
function edit_minidlna() {
# editing minidlna
echo ":::"
echo -n "::: Editing minidlna"
$SUDO mkdir /home/pi/minidlna
$SUDO cp /etc/minidlna.conf /etc/minidlna.conf.bkp
$SUDO echo "user=root
db_dir=/home/pi/minidlna/
log_dir=/var/log
port=8200
inotify=yes
enable_tivo=no
strict_dlna=no
album_art_names=Folder.jpg/folder.jpg/Thumb.jpg/thumb.jpg/movie.tbn/movie.jpg/Poster.jpg/poster.jpg
notify_interval=900
serial=12345678
model_number=1
root_container=B" > /etc/minidlna.conf
echo "model_name=$var1" | sudo tee --append /etc/minidlna.conf > /dev/null
echo "media_dir=V,$var4" | sudo tee --append /etc/minidlna.conf > /dev/null
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf > /dev/null
$SUDO update-rc.d minidlna defaults
echo "::: DONE!"
}
delete_junk
install_the_things
edit_samba
edit_minidlna
instal_raspiap
edit_hostapd
edit_dhcpdconf
edit_dnsmasq
finishing_touches