脚本介绍
首先,脚本头部写了很多的自定义函数,有:
yule "text"
:=echo -e " text"
。在输出的文本前面加了个空格,方便阅读。
yulen "text"
:=echo -en " text"
。
sepa
:=echo "-------------------------------"
blank n
:=n
个echo ""
。输出n
个空白行,缺省值为1
。
jsonread [路径/文件名.json] [关键词]
:简单的.json读取器
示例 1
/data/1.json
1
| {"name":"Nekogram","type":"1","suf":"all","dir":"/storage/emulated/0/Android/data/tw.nekomimi.nekogram/files/Telegram/","del":"no","data":"2024-09-28 06:29:11"}
|
输入
1
| jsonread /data/1.json del
|
输出
dlog text
:输出普通日志。格式为[日期时间] 操作: [text]
errlog text
:输出错误日志。格式为[日期时间] 错误: [text]
finlog text
:输出完成日志。格式为[日期时间] 完成: [text]
main
:定义各个应用的
name
(应用名)
dir
(路径)
type
(1 表示目录用文件夹进行了分类,此时下面的suf不生效;0 表示文件夹内就是要移动的文件)
suf
(要搜寻的文件后缀名,type 为 1 时不生效,使用 | 分割,all 表示所有文件)
main3
:面向某个类型或者应用要进行的操作
以方便你修改。自己适配应用需要修改的有:main
main3
menu
和底部的脚本介绍
修改main
现有的main
内容如下:
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
| main() { if [[ $menu == "1" ]]; then name="哔哩哔哩" dir="/storage/emulated/0/Android/data/tv.danmaku.bili/download/" type="1" suf=".m4s|.json" elif [[ $menu == "2" ]]; then name="微信" dir="/data/data/com.tencent.mm/MicroMsg/" type="1" suf="wechat file" elif [[ $menu == "3" ]]; then name="QQ" dir="/storage/emulated/0/Android/data/com.tencent.mobileqq/Tencent/QQfile_recv/" type="0" suf="all" elif [[ $menu == "4" ]]; then name="Nekogram" dir="/storage/emulated/0/Android/data/tw.nekomimi.nekogram/files/Telegram/" type="1" suf="all" fi main2 }
|
你应该在fi
的上一行开始,按格式定义应用的:
name
(应用名)
dir
(路径)
type
(1 表示目录用文件夹进行了分类,此时下面的suf不生效;0 表示文件夹内就是要移动的文件)
suf
(要搜寻的文件后缀名,type 为 1 时不生效,使用 | 分割,all 表示所有文件)
修改main3
现有的main3
内容如下:
1 2 3 4 5 6 7 8 9 10
| main3() { ...... ...... touch ${output}/last.json echo "{\"name\":\"$name\",\"type\":\"$type\",\"suf\":\"$suf\",\"dir\":\"$dir\",\"del\":\"$delete\",\"data\":\"$(date +"%Y-%m-%d %H:%M:%S")\"}" > ${output}/last.json rm -f ${output}/error exit 0 }
|
一般情况下,你应在touch ${output}/last.json
前添加你要执行的操作,比如:
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
| elif [[ $type == "1" && $suf == "all" ]]; then sepa yule "${CY}- 复制文件...${RES}" yulen "· 创建./$name/" mkdir "${output}/$name" 2>/dev/null yule "${GR} [完成]${RES}" yulen "· 移动文件到./$name/" cp -r ${dir}* ${output}/${name} 2>/${output}/error err=$? yule "${GR} [完成]${RES}" if [[ $err == "0" ]]; then yule "${GR}· 复制完成${RES}" sepa if [[ $delete == "yes" ]]; then rm -rf $dir/* yule "${GR}删除源文件成功${RES}" fi finlog "[$name]转移成功" yule "${GR}已完成转移${RES}" yule "路径${output}/$name" else blank sepa blank 2 errtext=$(cat ${output}/error) yule "ERR: $errtext" errlog "[$name]复制文件失败: $errtext" blank 2 yule "${RE}· 复制出错,请检查:${RES}" yule " 1.存储空间是否足够" yule " 2.是否未下载文件" yule " 3.软件是否为旧版" yule " 4.是否未授权Root" exit 1 fi
|
修改介绍
和选择开始菜单
介绍
现有的介绍
位于脚本的525
行(v1.0),内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| clear blank 2 yule "${YE}本脚本可以将应用所下载的文件转移到你设定的目录${RES}" blank yule "${BL}已支持应用:${RES}" yule "- 哔哩哔哩" yule "- 微信" yule "- QQ" yule "- Nekogram"
blank sepa yulen "${GR}开始[1]${RES}" yulen "${RE} 退出[2]${RES}" yule "${CY} 配置路径[3]${RES}" yule "${BL} 我要学习自己适配应用[4]${RES}"
|
一般情况下,你只要在上面代码加上新的应用名和序号即可,详见上方注释。
选择开始菜单
现有的选择开始菜单
位于脚本的542
行(v1.0),内容如下:
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
| for err_num in {10..0}; do sepa yulen "请输入[1]/[2]/[3]/[4]:" read menu_1 case $menu_1 in 1) clear blank 2 menu exit 0 ;; 2) blank yule "${GR}脚本已退出,欢迎下次使用${RES}" exit 0 ;; 3) clear blank 2 yulen "功能研发中,请编辑脚本顶部的 output= 进行配置" exit 0 ;; 4) am start -a android.intent.action.VIEW -d "https://baidu.com/" exit 0 ;; n) ...... ;; *|\n) jam $err_num $menu_1 ;; esac done
blank yule "${RE}你已连续输入错误10次,被系统判定为卡死,已退出脚本"
|
这里被介绍
的
1 2 3 4
| yulen "${GR}开始[1]${RES}" yulen "${RE} 退出[2]${RES}" yule "${CY} 配置路径[3]${RES}" yule "${BL} 我要学习自己适配应用[4]${RES}"
|
所选择,只要在*|\n)
的上一行添加
就可以了。
相关内容
缓存转移开源 | YuleのBlog - Post 12
缓存转移下载 | 123云盘