-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.sh
65 lines (52 loc) · 1.39 KB
/
lib.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
PORTABLE_DIR=/d/Tools
clean_target() {
target=$1
echo "删除已有的 $target"
if [[ -d "$target" ]]; then
for f in "$target"/*; do
[[ -e "$f" ]] || break
rm -rf "$f"
done
fi
}
install_to_target() {
source=$1
target=$2
if [[ ! -d "$target" ]]; then
mkdir -p "$target"
fi
echo "复制配置到 $target"
exclusion_list=("README.md" "install.sh" "update.sh")
for f in "$source"/*; do
[[ -e "$f" ]] || break
name=${f##*/}
if [[ ! ${exclusion_list[*]} =~ $name ]]; then
cp -rf "$f" "$target"
fi
done
}
download_github_latest() {
author=$1
repo=$2
file=$3
output=$4
curl -kL -o "$output" "$(curl -ks "https://api.github.com/repos/$author/$repo/releases/latest" | grep "browser_download_url" | cut -d \" -f 4 | grep "$file")"
}
execute_scripts_of_subdirectories() {
parent_dir=$1
script_name=$2
description=$3
for d in "$parent_dir"/*; do
if [[ -d $d ]]; then
name=${d##*/}
cd "$d" || continue
if [[ -f $script_name ]]; then
echo "开始:$name $description"
sh "$script_name"
echo "结束:$name $description"
echo "----------------------------------------"
fi
cd "$DIR" || continue
fi
done
}