-
Notifications
You must be signed in to change notification settings - Fork 9
/
skynet-creator.sh
executable file
·122 lines (100 loc) · 2.71 KB
/
skynet-creator.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
#!/bin/bash
RESOURCES_DIR="/usr/local/share/skynet-creator"
SKYNET_REPO="https://github.com/cloudwu/skynet.git"
function usage() {
cat <<EOF
用法: skynet-creator [选项] <操作> [参数]
选项:
-f, --force 如果目标目录已存在,强制覆盖
操作:
create <路径> 创建一个新的 skynet 项目
import <模块...> 向当前目录的项目导入一个或多个模块
示例:
skynet-creator create /path/to/new/project
skynet-creator --force create /path/to/new/project
skynet-creator import module1 module2 module3
EOF
}
function create_project() {
local force="$1"
local workdir="$2"
echo "workdir: ${workdir}"
if [[ "$force" == "true" ]]; then
rm -rf "${workdir}/etc"
rm -rf "${workdir}/make"
rm -rf "${workdir}/service"
rm -rf "${workdir}/lualib"
else
if [ -d "${workdir}" ]; then
echo "${workdir} is already created!"
return
fi
fi
mkdir -p "${workdir}"
cp "${RESOURCES_DIR}/templates/.gitignore" "${workdir}/"
mkdir -p "${workdir}/lualib"
# cp -r "${RESOURCES_DIR}/templates/lualib"/* "${workdir}/lualib/"
mkdir -p "${workdir}/service"
cp "${RESOURCES_DIR}/templates/service"/* "${workdir}/service/"
mkdir -p "${workdir}/etc"
cp -r "${RESOURCES_DIR}/templates/etc"/* "${workdir}/etc/"
mkdir -p "${workdir}/make"
cp "${RESOURCES_DIR}/templates/Makefile" "${workdir}/"
cp "${RESOURCES_DIR}/templates/make/skynet.mk" "${workdir}/make/"
cp "${RESOURCES_DIR}/templates/test.sh" "${workdir}/"
cd "${workdir}"
git init
git branch -m master
# skynet
if [ ! -d "${workdir}/skynet" ]; then
echo "add skynet: ${SKYNET_REPO}"
git submodule add "${SKYNET_REPO}"
fi
}
function import_modules() {
for module in "$@"; do
echo "导入模块: $module"
module_script="${RESOURCES_DIR}/modules/${module}.sh"
if [ -f "$module_script" ]; then
RESOURCES_DIR="${RESOURCES_DIR}" bash "$module_script"
echo "导入完成"
else
echo "模块导入脚本不存在: $module_script"
fi
done
}
# 解析命令行选项
while true; do
case "$1" in
-f | --force)
force=true
shift
;;
*)
break
;;
esac
done
# 检查是否提供了足够的参数
if [[ $# -lt 1 ]]; then
usage
exit 1
fi
action="$1"
shift
if [[ "$action" == "create" ]]; then
if [[ $# -lt 1 ]]; then
usage
exit 1
fi
create_project "$force" "$1"
elif [[ "$action" == "import" ]]; then
if [[ $# -lt 1 ]]; then
usage
exit 1
fi
import_modules "$@"
else
echo "未知操作: $action"
exit 1
fi