-
Notifications
You must be signed in to change notification settings - Fork 0
/
debian_config.sh
executable file
Β·193 lines (165 loc) Β· 6.83 KB
/
debian_config.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
#!/usr/bin/env bash
set -e -u
# Colored Environment Variables
if [ -x "$(command -v tput)" ]; then
RED="$(tput setaf 1)$(tput bold)"
GREEN="$(tput setaf 2)$(tput bold)"
YELLOW="$(tput setaf 3)$(tput bold)"
NOATTR="$(tput sgr0)"
else
RED=""
GREEN=""
YELLOW=""
NOATTR=""
fi
# Needed to indicate if the configuration is still ongoing
: >/.setup_has_not_done
# Github repo page to fetch files
DEBDROID__URL_REPO="https://raw.githubusercontent.com/zavocc/debdroid/2.0"
# Suppress some errors if trying to configure
rm -rf /etc/ld.so.preload
rm -rf /usr/local/lib/libdisableselinux.so
# Add 'contrib' component
[ -f /etc/apt/sources.list ] || sources_list="/etc/apt/sources.list.d/debian.sources"
if ! grep -q "main contrib" "${sources_list:-/etc/apt/sources.list}"; then
sed -i "s/main/main contrib/g" "${sources_list:-/etc/apt/sources.list}"
fi
# Delete Docker Related files as if they're not essential and may cause problems
rm -rf /etc/apt/apt.conf.d/docker-*
# Fill the nameservers with Google's DNS needed for networking
rm /etc/resolv.conf
cat > /etc/resolv.conf <<- EOM
nameserver 8.8.8.8
nameserver 8.8.4.4
EOM
# Perform installation
echo "${GREEN}I: Updating packages if necessary, this may take several minutes, you also need to have a strong network connection and have a sufficient battery power to avoid interruption${NOATTR}"
apt update
apt upgrade -yy
echo "${GREEN}I: Installing some packages${NOATTR}"
apt install nano sudo tzdata procps curl dialog apt-utils command-not-found lsb-release locales -yy --no-install-recommends
echo "${GREEN}I: Perfoming necessary fixes${NOATTR}"
dpkg --configure -a ||:
apt install -f -y ||:
echo "${GREEN}I: Replacing system binaries with a stub${NOATTR}"
ln -fs /bin/true /usr/local/bin/udevadm
ln -fs /bin/true /usr/local/bin/dpkg-statoverride
echo "${GREEN}I: Trying to reconfigure it once again: fixes dpkg errors${NOATTR}"
dpkg --configure -a
# Update command-not-found database
echo "${GREEN}I: Populating ${YELLOW}command-not-found${GREEN} database${NOATTR}"
update-command-not-found
apt update
# Create 'addusers' script
cat > /usr/local/bin/addusers <<- EOM
#!/usr/bin/env bash
########################################################################
# This script allows to create one or more users easily
# And can be granted with sudo access automatically
#
# For Changing Users, user must value a username within echo from file:
# /.proot.debdroid/userinfo.rc
########################################################################
ARGUMENT="\$1"
if [ ! "\$(whoami)" == "root" ]; then
echo "${RED}Please run me as root to use this tool${NOATTR}"
exit 1
fi
# Check for zero argument
if [ -z "\$ARGUMENT" ]; then
echo "${RED}Please specify a user to add! This script only takes few arguments${NOATTR}"
exit 1
fi
# Add a user
echo "${GREEN}Adding a user \${ARGUMENT} and adding a sudoers file for a user to use administrative commands${NOATTR}"
if ! useradd -m "\${ARGUMENT}" -s /bin/bash; then
exit 1
fi
if ! passwd "\${ARGUMENT}"; then
exit 1
fi
echo "\${ARGUMENT} ALL=(ALL:ALL) NOPASSWD:ALL" > "/etc/sudoers.d/99-debdroid-user-\${ARGUMENT}"
echo "${GREEN}Successfully added a user \${ARGUMENT}${NOATTR}"
EOM
chmod 755 /usr/local/bin/addusers
# Download required files to launch debian
curl --insecure --fail --silent --output /.proot.debdroid/run_debian "${DEBDROID__URL_REPO}/run_debian.sh"
curl --insecure --fail --silent --output /.proot.debdroid/mountpoints.sh "${DEBDROID__URL_REPO}/mountpoints.sh"
# Preload libdisableselinux.so library to avoid messing up Debian from Android security features
case $(dpkg --print-architecture) in
arm64|aarch64)
curl --insecure --fail --silent --output /usr/local/lib/libdisableselinux.so "${DEBDROID__URL_REPO}/libs/arm64/libdisableselinux.so"
;;
armhf)
curl --insecure --fail --silent --output /usr/local/lib/libdisableselinux.so "${DEBDROID__URL_REPO}/libs/armhf/libdisableselinux.so"
;;
i*86|x86)
curl --insecure --fail --silent --output /usr/local/lib/libdisableselinux.so "${DEBDROID__URL_REPO}/libs/i386/libdisableselinux.so"
;;
amd64|x86_64)
curl --insecure --fail --silent --output /usr/local/lib/libdisableselinux.so "${DEBDROID__URL_REPO}/libs/amd64/libdisableselinux.so"
;;
esac
chmod 755 /usr/local/lib/libdisableselinux.so
echo /usr/local/lib/libdisableselinux.so >> /etc/ld.so.preload
# Enable interoperability if possible
if [ ! -e /.proot.debdroid/binfmt/corrosive-session ]; then
mkdir /.proot.debdroid/binfmt -p
echo 1 > /.proot.debdroid/binfmt/corrosive-session
fi
# Perform final configuration
echo "${GREEN}I: Performing Final Configuration${NOATTR}"
dpkg-reconfigure tzdata || :
# Multi-launguage environment
if ! dpkg-reconfigure locales; then
# check if existing LANG variable exists since this could have been set when doing reconfiguration
if ! grep "^LANG" /etc/default/locale 1>/dev/null; then
echo "${GREEN}I: The language environment isn't configured: falling back to C.UTF-8${NOATTR}"
echo "LANG=C.UTF-8" >> /etc/default/locale
sleep 3
fi
fi
# Implementation of hostname, this feature uniquely identifies your container, see https://github.com/termux/proot/issues/80 issue for more details
hostname_info=$(
dialog --title "Finish Debian Setup" --backtitle "DebDroid Configuration" \
--nocancel --inputbox "Enter your hostname to uniquely identify your container, you may leave it blank for defaults, you may customize it again later by editing /etc/hostname" 12 40 \
--output-fd 1
)
if [ ! -z "${hostname_info}" ]; then
echo "${hostname_info}" > /etc/hostname
else
echo "${YELLOW}N: Falling Back to hostname: termux-debian${NOATTR}"
echo "termux-debian" > /etc/hostname
fi
if [ ! -e /.proot.debdroid/userinfo.rc ]; then
env_username=$(
dialog --title "Finish Debian Setup" --backtitle "DebDroid Configuration" \
--nocancel --inputbox "Enter your desired username for your default user account" 9 40 \
--output-fd 1
)
if [ ! -z "${env_username}" ]; then
echo "${env_username}" > /.proot.debdroid/userinfo.rc
useradd -s /bin/bash -m "${env_username}"
else
echo "${RED}N: No username is specified, falling back to defaults${NOATTR}"
sleep 5
echo "user" > /.proot.debdroid/userinfo.rc
useradd -s /bin/bash -m "user"
fi
echo "$(head -n 1 /.proot.debdroid/userinfo.rc) ALL=(ALL:ALL) NOPASSWD:ALL" > /etc/sudoers.d/debdroid-user
env_password=$(
dialog --title "Finish Debian Setup" --backtitle "DebDroid Configuration" \
--nocancel --insecure --passwordbox "Enter your password for your default user account" 9 40 \
--output-fd 1
)
if [ ! -z "${env_password}" ]; then
echo "$(head -n 1 /.proot.debdroid/userinfo.rc)":"${env_password}" | chpasswd
else
echo "${RED}N: No password is specified, the default password is ${YELLOW}passw0rd${NOATTR}"
sleep 5
echo "$(head -n 1 /.proot.debdroid/userinfo.rc)":"passw0rd" | chpasswd
fi
else
echo "${YELLOW}I: The user account is already been set up... Skipping${NOATTR}"
fi
rm /.setup_has_not_done