Skip to content

Commit d5bd444

Browse files
committed
feat: 源码上传
1 parent c3c8aea commit d5bd444

File tree

9 files changed

+359
-0
lines changed

9 files changed

+359
-0
lines changed
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
#!/sbin/sh
2+
3+
#################
4+
# Initialization
5+
#################
6+
7+
umask 022
8+
9+
# Global vars
10+
TMPDIR=/dev/tmp
11+
PERSISTDIR=/sbin/.magisk/mirror/persist
12+
13+
rm -rf $TMPDIR 2>/dev/null
14+
mkdir -p $TMPDIR
15+
16+
# echo before loading util_functions
17+
ui_print() { echo "$1"; }
18+
19+
require_new_magisk() {
20+
ui_print "*******************************"
21+
ui_print " Please install Magisk v19.0+! "
22+
ui_print "*******************************"
23+
exit 1
24+
}
25+
26+
is_legacy_script() {
27+
unzip -l "$ZIPFILE" install.sh | grep -q install.sh
28+
return $?
29+
}
30+
31+
print_modname() {
32+
local len
33+
len=`echo -n $MODNAME | wc -c`
34+
len=$((len + 2))
35+
local pounds=`printf "%${len}s" | tr ' ' '*'`
36+
ui_print "$pounds"
37+
ui_print " $MODNAME "
38+
ui_print "$pounds"
39+
ui_print "*******************"
40+
ui_print " Powered by Magisk "
41+
ui_print "*******************"
42+
}
43+
44+
##############
45+
# Environment
46+
##############
47+
48+
OUTFD=$2
49+
ZIPFILE=$3
50+
51+
mount /data 2>/dev/null
52+
53+
# Load utility functions
54+
[ -f /data/adb/magisk/util_functions.sh ] || require_new_magisk
55+
. /data/adb/magisk/util_functions.sh
56+
[ $MAGISK_VER_CODE -gt 18100 ] || require_new_magisk
57+
58+
# Preperation for flashable zips
59+
setup_flashable
60+
61+
# Mount partitions
62+
mount_partitions
63+
64+
# Detect version and architecture
65+
api_level_arch_detect
66+
67+
# Setup busybox and binaries
68+
$BOOTMODE && boot_actions || recovery_actions
69+
70+
##############
71+
# Preparation
72+
##############
73+
74+
# Extract prop file
75+
unzip -o "$ZIPFILE" module.prop -d $TMPDIR >&2
76+
[ ! -f $TMPDIR/module.prop ] && abort "! Unable to extract zip file!"
77+
78+
$BOOTMODE && MODDIRNAME=modules_update || MODDIRNAME=modules
79+
MODULEROOT=$NVBASE/$MODDIRNAME
80+
MODID=`grep_prop id $TMPDIR/module.prop`
81+
MODPATH=$MODULEROOT/$MODID
82+
MODNAME=`grep_prop name $TMPDIR/module.prop`
83+
84+
# Create mod paths
85+
rm -rf $MODPATH 2>/dev/null
86+
mkdir -p $MODPATH
87+
88+
##########
89+
# Install
90+
##########
91+
92+
if is_legacy_script; then
93+
unzip -oj "$ZIPFILE" module.prop install.sh uninstall.sh 'common/*' -d $TMPDIR >&2
94+
95+
# Load install script
96+
. $TMPDIR/install.sh
97+
98+
# Callbacks
99+
print_modname
100+
on_install
101+
102+
# Custom uninstaller
103+
[ -f $TMPDIR/uninstall.sh ] && cp -af $TMPDIR/uninstall.sh $MODPATH/uninstall.sh
104+
105+
# Skip mount
106+
$SKIPMOUNT && touch $MODPATH/skip_mount
107+
108+
# prop file
109+
$PROPFILE && cp -af $TMPDIR/system.prop $MODPATH/system.prop
110+
111+
# Module info
112+
cp -af $TMPDIR/module.prop $MODPATH/module.prop
113+
114+
# post-fs-data scripts
115+
$POSTFSDATA && cp -af $TMPDIR/post-fs-data.sh $MODPATH/post-fs-data.sh
116+
117+
# service scripts
118+
$LATESTARTSERVICE && cp -af $TMPDIR/service.sh $MODPATH/service.sh
119+
120+
ui_print "- Setting permissions"
121+
set_permissions
122+
else
123+
print_modname
124+
125+
unzip -o "$ZIPFILE" customize.sh -d $MODPATH >&2
126+
127+
if ! grep -q '^SKIPUNZIP=1$' $MODPATH/customize.sh 2>/dev/null; then
128+
ui_print "- Extracting module files"
129+
unzip -o "$ZIPFILE" -x 'META-INF/*' -d $MODPATH >&2
130+
131+
# Default permissions
132+
set_perm_recursive $MODPATH 0 0 0755 0644
133+
fi
134+
135+
# Load customization script
136+
[ -f $MODPATH/customize.sh ] && . $MODPATH/customize.sh
137+
fi
138+
139+
# Handle replace folders
140+
for TARGET in $REPLACE; do
141+
ui_print "- Replace target: $TARGET"
142+
mktouch $MODPATH$TARGET/.replace
143+
done
144+
145+
if $BOOTMODE; then
146+
# Update info for Magisk Manager
147+
mktouch $NVBASE/modules/$MODID/update
148+
cp -af $MODPATH/module.prop $NVBASE/modules/$MODID/module.prop
149+
fi
150+
151+
# Copy over custom sepolicy rules
152+
if [ -f $MODPATH/sepolicy.rule -a -e $PERSISTDIR ]; then
153+
ui_print "- Installing custom sepolicy patch"
154+
PERSISTMOD=$PERSISTDIR/magisk/$MODID
155+
mkdir -p $PERSISTMOD
156+
cp -af $MODPATH/sepolicy.rule $PERSISTMOD/sepolicy.rule
157+
fi
158+
159+
# Remove stuffs that don't belong to modules
160+
rm -rf \
161+
$MODPATH/system/placeholder $MODPATH/customize.sh \
162+
$MODPATH/README.md $MODPATH/.git* 2>/dev/null
163+
164+
##############
165+
# Finalizing
166+
##############
167+
168+
cd /
169+
$BOOTMODE || recovery_cleanup
170+
rm -rf $TMPDIR
171+
172+
ui_print "- Done"
173+
exit 0
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#MAGISK
2+
#Xzhi

constant.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/system/bin/sh
2+
3+
user_config_dir="/data/media/0/Android/Xzhi/custom-dir-mount"
4+
config_file="$user_config_dir/目录挂载.conf"
5+
log_file="$user_config_dir/run.log"
6+
mount_record_file="$user_config_dir/.勿删除勿修改"

customize.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
ui_print "
2+
*****************************************************************
3+
* [Xzhi-自定义目录挂载]模块的配置文件路径:
4+
/storage/emulated/0/Android/Xzhi/custom-dir-mount/目录挂载.conf
5+
6+
/data/media/0/Android/Xzhi/custom-dir-mount/目录挂载.conf
7+
8+
* 如果是第一次安装,请在配置文件里添加需要挂载目录的路径。
9+
*****************************************************************
10+
"
11+
12+
source $MODPATH/constant.sh
13+
14+
mkdir -p "$user_config_dir"
15+
[[ ! -f "$config_file" ]] && echo '#使用说明:
16+
#如果要添加注释,第一个字符一定加上#这个符号,否则模块可能出现异常
17+
#格式(注意有空格):"源目录路径" "目标目录路径",例子:
18+
#应用双开-阿里云盘目录挂载
19+
#"/data/media/999/AliYunPan" "/data/media/0/_Xzhi/目录挂载/阿里云盘"' >"$config_file"
20+
cp -f "$MODPATH/更新配置.sh" "$user_config_dir/更新配置.sh"

log.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/system/bin/sh
2+
MODDIR="$(dirname "$0")"
3+
source $MODDIR/constant.sh
4+
5+
log() {
6+
log_msg="[$(date "+%Y-%m-%d %H:%M:%S")] - $1"
7+
if [ -z "$2" ]; then
8+
echo $log_msg >>$log_file
9+
else
10+
echo $log_msg >$log_file
11+
fi
12+
}

module.prop

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
id=Xzhi-custom-dir-mount
2+
name=Xzhi-自定义目录挂载
3+
version=v2.0.65
4+
versionCode=20230830
5+
author=Xzhi
6+
description=配置文件路径:/storage/emulated/0/Android/Xzhi/custom-dir-mount/目录挂载.conf 或 /data/media/0/Android/Xzhi/custom-dir-mount/目录挂载.conf

mount_dir.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/system/bin/sh
2+
MODDIR="$(dirname "$0")"
3+
source $MODDIR/constant.sh
4+
source $MODDIR/log.sh
5+
6+
mount_dir() {
7+
log "开始读取配置文件"
8+
echo -n >$mount_record_file
9+
if [[ -f "$config_file" ]]; then
10+
# 读取配置文件
11+
while IFS= read -r line || [[ -n "$line" ]]; do
12+
# 去除行两端的空格
13+
line=$(echo "$line" | awk '{$1=$1};1')
14+
# 忽略没有内容的一行
15+
if [ -z "$line" ]; then
16+
continue
17+
fi
18+
# 检查行末尾是否有换行符
19+
if ! echo "$line" | grep -q $'\n'; then
20+
line="$line"$'\n'
21+
fi
22+
# 忽略以 "#" 开头的注释行
23+
if [[ $line != \#* ]]; then
24+
# 分割行为源路径和目标路径
25+
source_path=$(echo "$line" | awk '{print $1}')
26+
target_path=$(echo "$line" | awk '{print $2}')
27+
#去除路径中的双引号
28+
source_path=$(sed 's/"//g' <<<"$source_path")
29+
target_path=$(sed 's/"//g' <<<"$target_path")
30+
[[ ! -d $target_path ]] && mkdir -p "$target_path"
31+
if [[ -d $source_path ]]; then
32+
mount -o make,private,gid=9997,uid=9997,bind,rw "$source_path" "$target_path"
33+
chcon u:object_r:media_rw_data_file:s0 "$source_path"
34+
chown media_rw:media_rw "$target_path"
35+
# chmod -R 2777 "$target_path"
36+
source_path_mount_record="${source_path%/}"
37+
echo $source_path_mount_record >>$mount_record_file
38+
log "目录挂载成功,源路径:$source_path >>> 目标路径:$target_path"
39+
else
40+
log "(T_T) 挂载失败,源路径:$source_path 不存在该目录 (T_T)"
41+
fi
42+
fi
43+
done <"$config_file"
44+
else
45+
log "(T_T) 配置文件$config_file 读取失败 (T_T)"
46+
fi
47+
log "^_^ 自定义目录挂载结束 ^_^"
48+
}
49+
50+
mount_dir

service.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/system/bin/sh
2+
MODDIR=${0%/*}
3+
source $MODDIR/log.sh
4+
5+
system_init_check() {
6+
until [[ $(getprop sys.boot_completed) -eq 1 ]]; do
7+
sleep 2
8+
done
9+
10+
local test_file="/sdcard/Android/.test_file_Xzhi"
11+
touch $test_file
12+
while [[ ! -f $test_file ]]; do
13+
touch $test_file
14+
sleep 1
15+
done
16+
rm $test_file
17+
}
18+
19+
call_mount_dir() {
20+
log "^_^ 开启自定义目录挂载 ^_^" "清空历史日志"
21+
chown root:root $MODDIR/mount_dir.sh
22+
chmod 777 $MODDIR/mount_dir.sh
23+
/system/bin/sh $MODDIR/mount_dir.sh &>/dev/null &
24+
}
25+
26+
system_init_check
27+
call_mount_dir
28+
29+
exit 0

更新配置.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/system/bin/sh
2+
3+
user_config_dir="/data/media/0/Android/Xzhi/custom-dir-mount"
4+
config_file="$user_config_dir/目录挂载.conf"
5+
log_file="$user_config_dir/run.log"
6+
mount_record_file="$user_config_dir/.勿删除勿修改"
7+
8+
mount_dir() {
9+
log "^_^ 开始更新配置 ^_^"
10+
if [[ -f "$config_file" ]]; then
11+
# 读取配置文件
12+
while IFS= read -r line || [[ -n "$line" ]]; do
13+
# 去除行两端的空格
14+
line=$(echo "$line" | awk '{$1=$1};1')
15+
# 忽略没有内容的一行
16+
if [ -z "$line" ]; then
17+
continue
18+
fi
19+
# 检查行末尾是否有换行符
20+
if ! echo "$line" | grep -q $'\n'; then
21+
line="$line"$'\n'
22+
fi
23+
# 忽略以 "#" 开头的注释行
24+
if [[ $line != \#* ]]; then
25+
# 分割行为源路径和目标路径
26+
source_path=$(echo "$line" | awk '{print $1}')
27+
target_path=$(echo "$line" | awk '{print $2}')
28+
#去除路径中的双引号
29+
source_path=$(sed 's/"//g' <<<"$source_path")
30+
target_path=$(sed 's/"//g' <<<"$target_path")
31+
[[ ! -d $target_path ]] && mkdir -p "$target_path"
32+
if [[ -d $source_path ]]; then
33+
#查询该源目录是否曾挂载成功过
34+
source_path_mount_record="${source_path%/}"
35+
source_path_exist=$(grep "$source_path_mount_record" "$mount_record_file")
36+
if [[ -z $source_path_exist ]]; then
37+
mount -o make,private,gid=9997,uid=9997,bind,rw "$source_path" "$target_path"
38+
chcon u:object_r:media_rw_data_file:s0 "$source_path"
39+
chown media_rw:media_rw "$target_path"
40+
# chmod -R 2777 "$target_path"
41+
echo $source_path_mount_record >>$mount_record_file
42+
log "更新成功,源路径:$source_path >>> 目标路径:$target_path"
43+
else
44+
log "源路径:$source_path (包含子目录或父目录)已经挂载成功无需更新"
45+
fi
46+
else
47+
log "(T_T) 挂载失败,源路径:$source_path 不存在该目录 (T_T)"
48+
fi
49+
fi
50+
done <"$config_file"
51+
else
52+
log "(T_T) 配置文件$config_file 读取失败 (T_T)"
53+
fi
54+
log "^_^ 更新配置结束 ^_^"
55+
}
56+
57+
log() {
58+
echo "[$(date "+%Y-%m-%d %H:%M:%S")] - $1" >>$log_file
59+
}
60+
61+
mount_dir

0 commit comments

Comments
 (0)