-
Notifications
You must be signed in to change notification settings - Fork 155
/
package.sh
executable file
·119 lines (99 loc) · 3.04 KB
/
package.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
#!/bin/sh
BASE_DIR=$(cd $(dirname $0); pwd)
echo ""
echo "WARNING!"
echo "--------------------------------"
echo "package.sh has been deprecated."
echo "Please use @kintone/plugin-packer instead."
echo "https://www.npmjs.com/package/@kintone/plugin-packer"
echo "--------------------------------"
echo ""
if [ $# -lt 1 ]; then
echo "usage: $0 PLUGIN_DIR [PRIVATE_KEY_FILE]"
exit 1
fi
if [ "$(basename $1)" = "." ]; then
PLUGIN_DIR=$(cd $(dirname $1); pwd)
else
PLUGIN_DIR=$(cd $(dirname $1); pwd)/$(basename $1)
fi
# Plugin name to cases
PLUGIN_NAME=${PLUGIN_DIR##*/}
if [ -f "$2" ]; then
PPK_FILE=$(cd $(dirname $2); pwd)/$(basename $2)
fi
# Check directory and files
if [ ! -d $PLUGIN_DIR ]; then
echo "Plugin directory $PLUGIN_DIR not found."
exit 1
fi
if [ ! -f "$PLUGIN_DIR/manifest.json" ]; then
echo "Manifest file $PLUGIN_DIR/manifest.json not found."
exit 1
fi
DOT_FILES=`find $PLUGIN_DIR -name ".*" | grep -v "/\.$"`
if [ "$DOT_FILES" != "" ]; then
echo "PLUGIN_DIR must not contain dot files or directories."
for DOT_FILE in $DOT_FILES; do
echo $DOT_FILE
done
exit 1
fi
PPK_FILES=`find $PLUGIN_DIR -name "*.ppk"`
if [ "$PPK_FILES" != "" ]; then
echo "PLUGIN_DIR must not contain *.ppk files."
exit 1
fi
# Command
if [ -x /bin/sed ]; then
SED="/bin/sed"
elif [ -x /usr/bin/sed ]; then
SED="/usr/bin/sed"
else
echo "missing sed."
exit 1
fi
# Create secret key
if [ ! -f "$PPK_FILE" ]; then
/bin/mkdir $BASE_DIR/vault >/dev/null 2>&1
/bin/mkdir $BASE_DIR/vault/keys >/dev/null 2>&1
PPK_FILE=$BASE_DIR/vault/keys/tmp.ppk
PPK_FILE_TMP=$PPK_FILE
/usr/bin/openssl genrsa -out $PPK_FILE 1024 >/dev/null 2>&1
fi
# Create a temporary directory for the package
PACKAGE_DIR=$BASE_DIR/tmp
/bin/rm -rf $PACKAGE_DIR
/bin/mkdir $PACKAGE_DIR
# And creating a content file by compressing the plug Directory
CONTENTS_FILE=$PACKAGE_DIR/contents.zip
cd $PLUGIN_DIR
/usr/bin/zip -r $CONTENTS_FILE ./ >/dev/null
# Create a signature and public key
PUB_FILE=$PACKAGE_DIR/PUBKEY
SIG_FILE=$PACKAGE_DIR/SIGNATURE
/usr/bin/openssl sha1 -sha1 -binary -sign $PPK_FILE < $CONTENTS_FILE > $SIG_FILE
/usr/bin/openssl rsa -pubout -outform DER < $PPK_FILE > $PUB_FILE 2>/dev/null
UUID=`/usr/bin/openssl dgst -sha256 < $PUB_FILE | $SED 's/^.* //' | /usr/bin/cut -c 1-32 | /usr/bin/tr '0-9a-f' 'a-p'`
# Rename the secret key
if [ "$PPK_FILE_TMP" != "" ]; then
PPK_FILE=$(cd $(dirname $PPK_FILE); pwd)/`basename $PLUGIN_DIR`.$UUID.ppk
/bin/mv $PPK_FILE_TMP $PPK_FILE
fi
# Create a package file
OUTPUT_DIR=$BASE_DIR/vault/plugins/$PLUGIN_NAME.$UUID
/bin/mkdir $BASE_DIR/vault >/dev/null 2>&1
/bin/mkdir $BASE_DIR/vault/plugins >/dev/null 2>&1
/bin/mkdir $OUTPUT_DIR > /dev/null 2>&1
OUTPUT_FILE=$OUTPUT_DIR/$PLUGIN_NAME.plugin.zip
/bin/rm $OUTPUT_FILE >/dev/null 2>&1
cd $PACKAGE_DIR
/usr/bin/zip -r $OUTPUT_FILE ./ >/dev/null
# Cleanup
cd $BASE_DIR
/bin/rm -rf $PACKAGE_DIR
echo "Plugin ID: $UUID"
echo "Plugin file: $OUTPUT_FILE"
if [ "$PPK_FILE_TMP" != "" ]; then
echo "Private key file: $PPK_FILE"
fi