-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcpkgen.sh
executable file
·89 lines (75 loc) · 1.97 KB
/
cpkgen.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
#!/bin/bash
if [ ! -f "$(which uuidgen)" ]
then
echo 'uuidgen is not installed'
echo 'exp. on debian system: apt-get install uuid-runtime'
echo '----------------------'
exit 1
fi
if [ ! -f "$(which zip)" ]
then
echo 'zip is not installed'
exit 1
fi
CPKGEN_VERSION="1.0"
CREATE=0
PACKAGE=0
while [ $# -gt 0 ]
do
key="$1"
case $key in
-h|--help)
echo -e "useage:\n"
echo "create plugin:"
echo -e "-c/--create project_name \nexp.: ./cpkgen.sh -c myProj"
echo ""
echo "package plugin:"
echo -e "-p/--package project_name \nexp.: ./cpkgen.sh -p myProj.cplugin"
exit 1
;;
-c|--create)
CREATE=1
PROJ_NAME=$2
shift
;;
-p|--package)
PACKAGE=1
PROJ_NAME=$2
shift
;;
--default)
DEFAULT=YES
;;
*)
echo "unknow arg"
exit 1
;;
esac
shift
done
if [ $CREATE -eq 1 ] && [ $PACKAGE -eq 1 ]
then
echo "can't both create and package"
exit 1
fi
PLUGIN_NAME="${PROJ_NAME}.cplugin"
BUNDLE_ID=$(uuidgen | awk -F '-' '{print $1}')
INFO_FILE="plugin_name = \"developr\"\nplugin_bundle_id = \"com.developer.${BUNDLE_ID}\"\nplugin_desc = \"信息描述\"\nplugin_version = \"1.0\"\nplugin_author = \"http://clipber.com\"\ncpkgen_version = \"${CPKGEN_VERSION}\""
MAIN_FILE="function main(text)\n\t-- edit here\n\treturn text\nend"
if [ $CREATE -eq 1 ]
then
echo "create plugin $PROJ_NAME in current dir"
mkdir -p "$PLUGIN_NAME"
echo -e $INFO_FILE > ${PLUGIN_NAME}/info.lua
echo -e $MAIN_FILE > ${PLUGIN_NAME}/main.lua
fi
if [ $PACKAGE -eq 1 ]
then
PLUGIN_NAME=$(basename -s .cplugin $PROJ_NAME)
PLUGIN_DIR="${PLUGIN_NAME}.cplugin"
rm -rf Payload "${PLUGIN_NAME}.cpk"
mkdir -p Payload
cp -a $PLUGIN_DIR Payload/
zip -r -1 "${PLUGIN_NAME}.cpk" Payload
rm -rf Payload
fi