forked from tuanpham-dev/termux-ubuntu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
firstrun
220 lines (197 loc) · 6.04 KB
/
firstrun
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
#!/bin/bash
# suppress dmesg output while the script is running
# echo 1 > /proc/sys/kernel/printk
apt update
apt install sudo dialog -y
#variables
TMPDIR=/var/tmp
SWITCH=/usr/share/andronix/switchuser
# Functions
msg() {
ALL_OFF="\e[1;0m"
BOLD="\e[1;1m"
GREEN="${BOLD}\e[1;32m"
local mesg=$1; shift
printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}
show_spinner() {
local -r pid="${1}"
local -r delay='0.75'
local spinstr='\|/-'
local temp
printf "${GREEN} This might take a while.. "
while ! grep -q "done" $TMPDIR/status ; do
temp="${spinstr#?}"
printf " [%c] " "${spinstr}"
spinstr=${temp}${spinstr%"${temp}"}
sleep "${delay}"
printf "\b\b\b\b\b\b"
done
printf "Done! \b\b\b\b"
echo ""
}
create_oem_install() {
echo "$USER" > $TMPDIR/user
echo "$PASSWORD" >> $TMPDIR/password
echo "$PASSWORD" >> $TMPDIR/password
echo "$ROOTPASSWORD" >> $TMPDIR/rootpassword
echo "$ROOTPASSWORD" >> $TMPDIR/rootpassword
msg "Setting root password..."
passwd root < $TMPDIR/rootpassword 1> /dev/null 2>&1
/usr/local/bin/vncpasswd -f <<<"$ROOTPASSWORD"$'\n'"$ROOTPASSWORD" > /root/.vnc/passwd
msg "Adding user $USER..."
echo "" > $TMPDIR/status
useradd -m -G sudo -s /bin/bash -U $(cat $TMPDIR/user) 1> /dev/null 2>&1 && echo "done" > $TMPDIR/status &
show_spinner
msg "Setting full name to $FULLNAME..."
chfn -f "$FULLNAME" $(cat $TMPDIR/user) 1> /dev/null 2>&1
msg "Setting password for $USER..."
mkdir -p /home/$USER/.vnc
passwd $(cat $TMPDIR/user) < $TMPDIR/password 1> /dev/null 2>&1
/usr/local/bin/vncpasswd -f <<<"$PASSWORD"$'\n'"$PASSWORD" > /home/$USER/.vnc/passwd
sed -i "/^root/a $USER ALL=(ALL) ALL" /etc/sudoers
msg "Applying system settings..."
systemctl disable systemd-resolved.service 1> /dev/null 2>&1
msg "Cleaning install for unwanted files..."
rm -rf /var/log/*
# Remove temp files on host
rm -rf $TMPDIR/user $TMPDIR/password $TMPDIR/rootpassword
}
# Using Dialog to ask for user input for variables
USER=$(dialog --clear --title "Finish Andronix Install" \
--inputbox "Enter username:
(Usernames can only be lower case)" 8 50 \
3>&1 1>&2 2>&3 3>&-)
if [ ! -z "$USER" ]
then
FULLNAME=$(dialog --clear --title "Finish Andronix Install" \
--inputbox "Enter Full Name for $USER:" 8 50 \
3>&1 1>&2 2>&3 3>&- \
)
fi
if [ ! -z "$FULLNAME" ]
then
PASSWORD=$(dialog --clear --title "Finish Andronix Install" \
--insecure \
--passwordbox "Enter Password for $USER (at least 6 characters):" 8 50 \
3>&1 1>&2 2>&3 3>&- )
else
clear
msg "Configuration aborted. Restarting OEM script..."
sleep 5 && exec bash /usr/share/andronix/firstrun
#exit 1
fi
if [ ! -z "$PASSWORD" ]
then
LEN=${#PASSWORD}
stat=1
if [[ "$LEN" -ge 6 ]]; then
stat=$?
else
clear
msg "Password does not match minimum lenght of 6 characters. Restarting OEM script..."
sleep 5 && exec bash /usr/share/andronix/firstrun
fi
fi
if [ ! -z "$PASSWORD" ]
then
CONFIRMPASSWORD=$(dialog --clear --title "Andronix Installer" \
--insecure --passwordbox "Confirm Password for $USER:" 8 50 \
3>&1 1>&2 2>&3 3>&- \
)
else
clear
msg "Configuration aborted. Restarting OEM script..."
sleep 5 && exec bash /usr/share/andronix/firstrun
#exit 1
fi
if [[ "$PASSWORD" != "$CONFIRMPASSWORD" ]]; then
clear
msg "User passwords do not match! Restarting OEM script..."
sleep 5 && exec bash /usr/share/andronix/firstrun
#exit 1
fi
if [ ! -z "$CONFIRMPASSWORD" ]
then
ROOTPASSWORD=$(dialog --clear --title "Finish Andronix Install" \
--insecure \
--passwordbox "Enter Root Password (at least 6 characters):" 8 50 \
3>&1 1>&2 2>&3 3>&- \
)
else
clear
msg "Configuration aborted. Restarting OEM script..."
sleep 5 && exec bash /usr/share/andronix/firstrun
#exit 1
fi
if [ ! -z "$ROOTPASSWORD" ]
then
LEN=${#ROOTPASSWORD}
stat=1
if [[ "$LEN" -ge 6 ]]; then
stat=$?
else
clear
msg "Password does not match minimum lenght of 6 characters. Restarting OEM script..."
sleep 5 && exec bash /usr/share/andronix/firstrun
fi
fi
if [ ! -z "$ROOTPASSWORD" ]
then
CONFIRMROOTPASSWORD=$(dialog --clear --title "Andronix Installer" \
--insecure --passwordbox "Confirm Root Password:" 8 50 \
3>&1 1>&2 2>&3 3>&- \
)
else
clear
msg "Configuration aborted. Restarting OEM script..."
sleep 5 && exec bash /usr/share/andronix/firstrun
#exit 1
fi
if [[ "$ROOTPASSWORD" != "$CONFIRMROOTPASSWORD" ]]; then
clear
msg "Root passwords do not match! Restarting OEM script..."
sleep 5 && exec bash /usr/share/andronix/firstrun
#exit 1
fi
if [ ! -z "$CONFIRMROOTPASSWORD" ]
then
dialog --clear --title "Finish Andronix Install" \
--yesno "Is the below information correct:
Username = $USER
Full Name for $USER = $FULLNAME
Password for $USER = $PASSWORD
Password for root = $ROOTPASSWORD" 20 50 \
3>&1 1>&2 2>&3 3>&-
else
clear
msg "Configuration aborted. Restarting OEM script..."
sleep 5 && exec bash /usr/share/andronix/firstrun
#exit 1
fi
response=$?
case $response in
0) clear; msg "Proceeding....";;
1) clear; msg "Configuration aborted. Restarting OEM script..."; sleep 5 && exec bash /usr/share/andronix/firstrun;;
255) clear; msg "Configuration aborted. Restarting OEM script..."; sleep 5 && exec bash /usr/share/andronix/firstrun;;
esac
create_oem_install
msg "Configuration complete. Cleaning up..."
# Here we export the DISPLAY variable for all know users
echo "export DISPLAY=:1" >> /root/.bashrc && echo "export DISPLAY=:1" >> /home/$USER/.profile
touch /home/$USER/.hushlogin
# Here we overwrite .bash_login to drop the oem first run and the hack to redirect the user after the oem intaller has finished.
echo "exec su - $USER" > $SWITCH
echo "$SWITCH; exit" > /root/.bash_profile
chmod +x $SWITCH
if [ -e /etc/ssh/sshd_config ]
then
sed -i s/"PermitRootLogin yes"/"#PermitRootLogin prohibit-password"/g /etc/ssh/sshd_config
fi
msg "You can start using your newly installed Andronix Modded OS..."
if [ -f /usr/share/andronix/de-install ]; then
chmod +x /usr/share/andronix/de-install
/usr/share/andronix/de-install $USER
fi
# Replace the current activity with a new shell for the user
exec su - $USER