-
Notifications
You must be signed in to change notification settings - Fork 1
/
linux-deploy
193 lines (143 loc) · 4.68 KB
/
linux-deploy
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
#!/bin/bash
CONFIG=/data/user/0/ru.meefik.linuxdeploy/files/config/linux.conf
USERNAME=$(sudo cat $CONFIG | awk -F '"|"' '/USER_NAME/{print $2}')
CHROOT_DIR=/data/local/mnt
INTERNAL_STORAGE=/sdcard
DEPLOY=/data/user/0/ru.meefik.linuxdeploy/files/bin/linuxdeploy
if [ -n "$(sudo ls -A /mnt/media_rw)" ]
then
EXTERNAL_STORAGE=/mnt/media_rw/$(sudo ls /mnt/media_rw)
else
EXTERNAL_STORAGE=""
fi
ARG1=$1
ARG2=$2
#This function contains the commands required to start the Xwayland socket in the chroot.
xwayland(){
echo "Creating the socket"
sudo mkdir -p $CHROOT_DIR/tmp/runtime-$USERNAME
su -c $DEPLOY shell -u root "chown $USERNAME:$USERNAME /tmp/runtime-$USERNAME"
taskset -c 4-7 termux-x11 &
sleep 20
sudo touch $CHROOT_DIR/tmp/runtime-$USERNAME/wayland-0
sudo busybox mount --bind $TMPDIR/wayland-0 $CHROOT_DIR/tmp/runtime-$USERNAME/wayland-0
sudo chmod a+rwx $CHROOT_DIR/tmp/runtime-$USERNAME/wayland-0
}
sparkle(){
if [ ! -f "$CHROOT_DIR/bin/sparkle" ]
then
echo "Installing sparkle script"
curl https://raw.githubusercontent.com/Pipetto-crypto/Chroot-Docs/main/sparkle/sparkle.sh > sparkle.sh
sudo mv sparkle.sh $CHROOT_DIR/bin/sparkle
sudo chmod a+x $CHROOT_DIR/bin/sparkle
fi
echo "Binding sparkle private directory into the chroot"
sudo mount --bind /data/data/com.sion.sparkle/files $CHROOT_DIR/sparkle
}
update(){
echo -e "\nMounting the container"
su -c $DEPLOY start -m
echo -e "\nCopying all scripts in the home directory"
sudo rm -rf $CHROOT_DIR/home/$USERNAME/scripts
sudo mkdir -p $CHROOT_DIR/home/$USERNAME/scripts
wget https://raw.githubusercontent.com/Pipetto-crypto/Chroot-Docs/main/setup/install_box.sh
wget https://raw.githubusercontent.com/Pipetto-crypto/Chroot-Docs/main/setup/install_vnc.sh
wget https://raw.githubusercontent.com/Pipetto-crypto/Chroot-Docs/main/setup/setup_env.sh
sudo mv install_box.sh install_vnc.sh setup_env.sh $CHROOT_DIR/home/$USERNAME/scripts
sudo chmod -R 777 $CHROOT_DIR/home/$USERNAME/scripts
echo -e "\nUpdate the linux-deploy script"
wget https://raw.githubusercontent.com/Pipetto-crypto/Chroot-Docs/main/linux-deploy
chmod +x linux-deploy
mv linux-deploy $PATH
echo -e "\nUnmounting the container"
su -c $DEPLOY stop -u
}
start(){
echo -e "\nInitializing audio server before startup"
pulseaudio --start --exit-idle-time=-1
pacmd load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1
echo -e "\nStarting the chroot"
su -c $DEPLOY start -m
echo -e "\nBinding internal storage"
#This is not required if you are using proot-distro
sudo mkdir -p $CHROOT_DIR/media/internal_storage
sudo bindfs -o perms=a+rwx -o nonempty $INTERNAL_STORAGE $CHROOT_DIR/media/internal_storage
if [ "$EXTERNAL_STORAGE" != "" ]
then
echo -e "\nBinding external storage"
sudo mkdir -p $CHROOT_DIR/media/external_sd
sudo bindfs -o perms=a+rwx -o nonempty $EXTERNAL_STORAGE $CHROOT_DIR/media/external_sd
else
echo -e "\nSD card is not present, won't mount external storage"
fi
if [ -d /proc/sys/fs/binfmt_misc ]
then
echo -e "\nLoading binfmts entries"
su -c $DEPLOY shell -u $USERNAME "sudo update-binfmts --enable > /dev/null 2>&1"
else
echo "Binfmt support not detected, skipping loading of binfmt entries"
fi
if [ "$ARG2" = "-w" ]
then
xwayland #calls the xwayland function after starting the chroot
elif [ "$ARG2" = "-s" ]
then
sparkle
echo "Starting the Xwayland server in the chroot through the script"
su -c $DEPLOY shell -u $USERNAME sparkle
fi
echo -e "\nAll preparations completed, connecting now\n"
ssh $USERNAME@localhost
}
stop(){
pid=$(sudo pidof com.termux.x11)
if [ "$pid" != "" ];
then
sudo kill $pid
fi
su -c $DEPLOY stop -u
}
help(){
echo -e "\nA basic script to integrate Linux-Deploy with Termux. It launches your linux chroots with audio, internal and external storage and a X server to use with Termux:X11 or Sparkle"
echo -e "\nOptions:\n"
echo -e "\nstart - Launches the chroot, run -w option to start the Xwayland server with Termux-X11 or -s for Sparkle"
echo "stop - Stops the chroot"
echo "restart - Restart the chroot, you can use same options as the start command"
echo "update - Updates this wrapper and downloads useful installation scripts inside the chroot"
echo -e "help - Print this help page\n"
}
while [ True ];
do
if [ "$ARG1" = "stop" ]
then
stop
break
elif [ "$ARG1" = "start" ]
then
if [ -d $CHROOT_DIR/home ]
then
echo "Chroot already mounted, connecting"
ssh $USERNAME@localhost
else
start
fi
break
elif [ "$ARG1" = "restart" ]
then
stop
start
break
elif [ "$ARG1" = "update" ]
then
update
break
elif [ "$ARG1" = "help" ]
then
help
break
else
echo -e "\nNo option specified\n"
help
break
fi
done