-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pack.sh
executable file
·13 lines (12 loc) · 2.87 KB
/
Pack.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
R="[1;31m";G="[1;32m";Y="[1;33m";C="[1;36m";B="[1;m";O="[m";abort(){ echo "
$R! $@$O";exit 1;};echo "$B—————————————————————————
$R Shell$Y Script$G Pack$C Tools$O
—————————————————————————
${G}作者:${C}时雨🌌星空$O";[ -d "$1" ]&&[ -f "$1.sh" ]&&INPUT="$(realpath "$1")"&&BASEINPUT="$(basename "$INPUT")"||abort "输入文件(夹)不存在";[ -n "$2" ]&&OUTPUT="$(realpath "$2")"||abort "输出文件不存在";command -v shc>/dev/null||abort "shc编译器不存在";echo "
$Y- 正在使用shc编译脚本$O
";shc -vrBf "$1.sh"||abort "脚本编译失败";echo "
$Y- 正在打包为自释放脚本$O
";echo '#脚本已经过编译,需要源代码请联系作者:时雨🌌星空
[ "$(id -u)" = 0 ]||{ echo "'"$Y"'- 正在获取root权限'"$O"'";exec su -c "sh \"$0\" \"$@\"";};runtime(){ RUNTIME="/data/adb/TimeRainStarSky/Runtime";export PATH="/data/adb/magisk:$PATH";[ -d "$RUNTIME" ]&&[ -f "$RUNTIME/verify" ]&&[ "$(ls "$RUNTIME")" = "$(cat "$RUNTIME/verify")" ]||{ echo "'"$Y"'- 正在配置运行环境'"$O"'";abort(){ rm -rf "$RUNTIME";echo "'"$R"'! $@'"$O"'";exit 1;};rm -rf "$RUNTIME";mkdir -p "$RUNTIME";setcmd(){ CMDPATH="$(command -v "$1")"&&cp "$CMDPATH" "$RUNTIME"&&"$RUNTIME/$@"|tr " " "\n"|while read i;do [ -z "$i" ]&&continue;ln -sf "$1" "$RUNTIME/$i";done||abort "找不到$1,请安装运行环境后重试";};setcmd busybox --list;setcmd toybox;ls "$RUNTIME">"$RUNTIME/verify";};export PATH="$DIR:$RUNTIME:$PATH";export LD_LIBRARY_PATH="$DIR:$RUNTIME:$LD_LIBRARY_PATH";};DIR="/data/adb/TimeRainStarSky/'"$BASEINPUT"'";runtime;FILE="$(realpath "$0")";cd "$(dirname "$FILE")";EXEC="$DIR/'"$BASEINPUT"'.sh.x";abort(){ rm -rf "$DIR";echo "'"$R"'! $@'"$O"'";exit 1;};mktmp(){ TMP="${DIR}_tmp"&&rm -rf "$TMP"&&mkdir -p "$TMP"||abort "创建缓存文件夹失败";};output_file(){ echo "'"$Y"'- 正在释放脚本'"$O"'";mktmp;tail -n "+$(awk "/$(echo "5a6a5L2N56ym"|base64 -d)/{print NR+1}" "$FILE"|head -n 1)" "$FILE"|xzcat|tar -xvC "$TMP"||abort "脚本释放失败";rm -rf "$DIR";mv -f "$TMP" "$DIR"||abort "脚本移动失败";OUTPUTED=1;};check_exec(){ if [ -x "$EXEC" ]&&[ "$(md5sum "$EXEC"|head -c 32)" = "'"$(md5sum "$INPUT.sh.x"|head -c 32)"'" ];then echo "'"$G"'- 脚本校验成功,开始执行'"$O"'";"$EXEC" "$(pwd)" "$FILE"||abort "脚本执行失败";elif [ "$OUTPUTED" != 1 ];then output_file;check_exec;else abort "脚本释放失败";fi;};check_exec;exit;定位符'>"$OUTPUT"||abort "脚本打包失败";mv -f "$INPUT.sh.x" "$INPUT";cd "$INPUT";tar -c *|xz -9cev>>"$OUTPUT"||abort "脚本打包失败";echo -n "$(sed -n 2p "$INPUT.sh"|tr "[A-Z]" "[a-z]"|tr ";" "\n")
md5=$(md5sum "$OUTPUT"|head -c 32)">"$(dirname "$OUTPUT")/version"||abort "脚本版本文件生成失败";cat "$(dirname "$OUTPUT")/version"||abort "脚本版本文件生成失败";echo "
$G- 打包完成$O"