This repository has been archived by the owner on Jan 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
plugin.sh
executable file
·90 lines (77 loc) · 1.96 KB
/
plugin.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
#!/bin/bash
BRANCH="master"
CONSOLE_SCRIPT="ConsoleScript.php"
CONSOLE_SCRIPT_URL="https://raw.githubusercontent.com/PocketMine/DevTools/master/src/DevTools/ConsoleScript.php"
OUTDIR="$(pwd)"
IGNORE_CERT="yes"
PHP="$(which php)"
function usage {
echo "Usage: $0 [-b branch] [-p /path/to/php] [-o /out/dir] <url>"
exit 1
}
#Needed to use aliases
shopt -s expand_aliases
type wget > /dev/null 2>&1
if [ $? -eq 0 ]; then
if [ "$IGNORE_CERT" == "yes" ]; then
alias download_file="wget --no-check-certificate -q -O -"
else
alias download_file="wget -q -O -"
fi
else
type curl >> /dev/null 2>&1
if [ $? -eq 0 ]; then
if [ "$IGNORE_CERT" == "yes" ]; then
alias download_file="curl --insecure --silent --location"
else
alias download_file="curl --silent --location"
fi
else
echo "error, curl or wget not found"
fi
fi
while getopts "b:ho:p:h" opt; do
case $opt in
b)
BRANCH="$2"
;;
h)
usage
;;
o)
OUTDIR="$2"
;;
p)
PHP="$2"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
;;
esac
done
shift $(expr $OPTIND - 1 )
URL="$1"
if [ "$($PHP -r 'echo 1;' 2>/dev/null)" != "1" ]; then
echo "[*] PHP not found"
usage
fi
if [ ! -f $CONSOLE_SCRIPT ]; then
echo "[*] Downloading ConsoleScript.php"
download_file "$CONSOLE_SCRIPT_URL" > ConsoleScript.php
fi
if [ ! -d $OUTDIR ]; then
mkdir -p "$OUTDIR"
fi
if [ "$URL" == "" ]; then
usage
fi
git clone -b "$BRANCH" "$URL" plugin
cd plugin
PLUGIN_NAME=$(grep 'name: ' plugin.yml | sed 's/^[^:]*: \(.*\)$/\1/g')
PLUGIN_VERSION=$(grep 'version: ' plugin.yml | sed 's/^[^:]*: \(.*\)$/\1/g')
GIT_COMMIT="$(git rev-parse HEAD)"
cd ..
$PHP -dphar.readonly=0 "$CONSOLE_SCRIPT" --make="./plugin/" --relative="./plugin/" --out "$OUTDIR/${PLUGIN_NAME}_v${PLUGIN_VERSION}-${GIT_COMMIT:0:8}.phar"
# cleanup
rm -fr plugin ConsoleScript.php