-
Notifications
You must be signed in to change notification settings - Fork 6
/
customize.sh
140 lines (116 loc) · 5.2 KB
/
customize.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
SKIPUNZIP=0
REPLACE="
"
bootinspect() {
if [ "$BOOTMODE" ] && [ "$KSU" ]; then
ui_print "- Install from KernelSU"
ui_print "- KernelSU Version:$KSU_KERNEL_VER_CODE(App)+ $KSU_VER_CODE(ksud)"
elif [ "$BOOTMODE" ] && [ "$APATCH" ]; then
ui_print "- Install from APatch"
ui_print "- Apatch Version:$APATCH_VER_CODE(App)+ $KERNELPATCH_VERSION(KernelPatch)"
elif [ "$BOOTMODE" ] && [ "$MAGISK_VER_CODE" ]; then
ui_print "- Install from Magisk"
ui_print "- Magisk Version:$MAGISK_VER(App)+ $MAGISK_VER_CODE"
else
abort "- Unsupported installation mode. Please install from the application (Magisk/KernelSu/Apatch)"
fi
[ "$ARCH" != "arm64" ] && abort "- Unsupported platform: $ARCH" || ui_print "- Device platform: $ARCH"
}
link_busybox() {
local busybox_file=""
if [ -f "$MODPATH/bin/busybox" ]; then
busybox_file="$MODPATH/bin/busybox"
else
for path in $BUSYBOX_PATHS; do
if [ -f "$path" ]; then
busybox_file="$path"
break
fi
done
fi
if [ -n "$busybox_file" ]; then
mkdir -p "$MODPATH/bin"
# "$busybox_file" --install -s "$MODPATH/bin"
# This method creates links pointing to all commands of busybox, so it is not recommended. The following is an alternative approach for creating symbolic links pointing to the busybox file for specific commands
for cmd in fuser inotifyd; do
ln -s "$busybox_file" "$MODPATH/bin/$cmd"
done
else
abort "- No available Busybox file found Please check your installation environment"
fi
}
inotifyfile() {
id_value=$(sed -n 's/^id=\(.*\)$/\1/p' "$MODPATH/module.prop")
MONITORFILE=".${id_value}.service.sh"
sed -i "2c MODULEID=\"$id_value\"" "$MODPATH/inotify.sh"
mkdir -p /data/adb/service.d
mv -f "$MODPATH/inotify.sh" "/data/adb/service.d/$MONITORFILE"
chmod +x "/data/adb/service.d/$MONITORFILE"
sed -i "s/inotify.sh/$MONITORFILE/g" "$MODPATH/uninstall.sh"
}
configuration() {
set_perm_recursive "$MODPATH/bin" 0 0 0755 0755
. "$MODPATH/config.conf"
BUSYBOX_PATHS="/data/adb/magisk/busybox
/data/adb/ksu/bin/busybox
/data/adb/ap/bin/busybox"
BASE_DIR="/data"
CONTAINER_DIR="${BASE_DIR}/${RURIMA_LXC_OS}"
echo "CONTAINER_DIR=${BASE_DIR}/${RURIMA_LXC_OS}" >> "$MODPATH/config.conf"
export PATH="$MODPATH/bin:$PATH"
CASE=$(sed -n '/case "\$LXC_OS"/,/^[[:space:]]*esac/p' "$MODPATH/setup/setup.sh")
SUPPORT=$(echo "$CASE" | \
sed -n 's/^[[:space:]]*\([a-zA-Z0-9|]*\))$/\1/p' | \
tr '|' ' ' | \
tr '\n' ' ')
if ! echo "$SUPPORT" | grep -qw "$RURIMA_LXC_OS"; then
abort "- $RURIMA_LXC_OS is not supported by the setup script"
fi
if [ -d "$CONTAINER_DIR" ]; then
ui_print "- Already installed"
ruri -U "$CONTAINER_DIR"
if [ -d "$CONTAINER_DIR.old" ]; then
version=1
while [ -d "$CONTAINER_DIR.old.$version" ]; do
version=$((version + 1))
done
mv "$CONTAINER_DIR.old" "$CONTAINER_DIR.old.$version"
fi
mv -f "$CONTAINER_DIR" "$CONTAINER_DIR.old"
ui_print "- Shut down the container and back up the relevant directories and files to the ${CONTAINER_DIR}.old"
fi
}
automatic() {
ui_print "- A network connection is required to download the root filesystem. Please connect to WiFi before installation whenever possible"
ui_print "- Downloading the root filesystem using the source ${RURIMA_LXC_MIRROR}..."
rurima lxc pull -n -m ${RURIMA_LXC_MIRROR} -o ${RURIMA_LXC_OS} -v ${RURIMA_LXC_OS_VERSION} -s "$CONTAINER_DIR"
if [[ $? != 0 ]]; then
ui_print "- Download failed. Attempting to download the root filesystem using the fallback source ${RURIMA_LXC_MIRROR_FALLBACK}..."
rurima lxc pull -n -m ${RURIMA_LXC_MIRROR_FALLBACK} -o ${RURIMA_LXC_OS} -v ${RURIMA_LXC_OS_VERSION} -s "$CONTAINER_DIR"
fi
ui_print "- Starting the chroot environment to perform automated installation..."
ui_print "- Please ensure the network environment is stable. The process may take some time, so please be patient!"
ui_print ""
sleep 2
getprop ro.product.model > "$CONTAINER_DIR/etc/hostname"
mkdir -p "$CONTAINER_DIR/tmp" "$CONTAINER_DIR/usr/local/lib/servicectl/enabled"
cp "$MODPATH/setup/setup.sh" "$CONTAINER_DIR/tmp/setup.sh"
cp -r "$MODPATH/setup/servicectl"/* "$CONTAINER_DIR/usr/local/lib/servicectl/"
chmod 777 "$CONTAINER_DIR/tmp/setup.sh" "$CONTAINER_DIR/usr/local/lib/servicectl/servicectl" "$CONTAINER_DIR/usr/local/lib/servicectl/serviced"
ruri "$CONTAINER_DIR" /bin/sh /tmp/setup.sh "$RURIMA_LXC_OS" "$PASSWORD" "$PORT"
inotifyfile
ui_print "- Automated installation completed!"
ui_print "- Note: Please change the default password. Exposing an SSH port with password authentication instead of key-based authentication is always a high-risk behavior!"
}
main() {
bootinspect
configuration
link_busybox
automatic
ruri -U "$CONTAINER_DIR"
}
main
# set_perm_recursive $MODPATH 0 0 0755 0644
set_perm "$MODPATH/container_ctrl.sh" 0 0 0755
ui_print ""
ui_print "- Please restart the system"