Skip to content
This repository was archived by the owner on Jan 9, 2018. It is now read-only.

Commit fbf6272

Browse files
committed
Curl, ConsoleScript and output dir for plugin.sh
1 parent ee81e92 commit fbf6272

File tree

1 file changed

+43
-16
lines changed

1 file changed

+43
-16
lines changed

plugin.sh

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,57 @@
11
#!/bin/bash
22

33
BRANCH="master"
4-
DEVTOOLS="DevTools.phar"
5-
CONSOLE_SCRIPT="https://raw.githubusercontent.com/PocketMine/DevTools/master/src/DevTools/ConsoleScript.php"
6-
4+
CONSOLE_SCRIPT="ConsoleScript.php"
5+
CONSOLE_SCRIPT_URL="https://raw.githubusercontent.com/PocketMine/DevTools/master/src/DevTools/ConsoleScript.php"
6+
OUTDIR="$(pwd)"
7+
IGNORE_CERT="yes"
78
PHP="$(which php)"
89

910
function usage {
10-
echo "Usage: $0 [-b branch] [-d /path/to/DevTools.phar] [-p /path/to/php] <url>"
11+
echo "Usage: $0 [-b branch] [-p /path/to/php] [-o /out/dir] <url>"
1112
exit 1
1213
}
1314

14-
while getopts "p:b:d:h" opt; do
15+
#Needed to use aliases
16+
shopt -s expand_aliases
17+
type wget > /dev/null 2>&1
18+
if [ $? -eq 0 ]; then
19+
if [ "$IGNORE_CERT" == "yes" ]; then
20+
alias download_file="wget --no-check-certificate -q -O -"
21+
else
22+
alias download_file="wget -q -O -"
23+
fi
24+
else
25+
type curl >> /dev/null 2>&1
26+
if [ $? -eq 0 ]; then
27+
if [ "$IGNORE_CERT" == "yes" ]; then
28+
alias download_file="curl --insecure --silent --location"
29+
else
30+
alias download_file="curl --silent --location"
31+
fi
32+
else
33+
echo "error, curl or wget not found"
34+
fi
35+
fi
36+
37+
while getopts "b:ho:p:h" opt; do
1538
case $opt in
1639
b)
1740
BRANCH="$2"
1841
;;
19-
d)
20-
DEVTOOLS="$2"
42+
h)
43+
usage
44+
;;
45+
o)
46+
OUTDIR="$2"
2147
;;
2248
p)
2349
PHP="$2"
2450
;;
25-
h)
51+
\?)
52+
echo "Invalid option: -$OPTARG" >&2
2653
usage
54+
;;
2755
esac
2856
done
2957

@@ -35,12 +63,9 @@ if [ "$($PHP -r 'echo 1;' 2>/dev/null)" != "1" ]; then
3563
usage
3664
fi
3765

38-
if [ ! -f $DEVTOOLS ]; then
39-
if [ ! -f "ConsoleScript.php" ]; then
40-
echo "[*] Downloading ConsoleScript.php"
41-
wget --no-check-certificate -O - "$CONSOLE_SCRIPT" > ConsoleScript.php
42-
fi
43-
DEVTOOLS="$(pwd)/ConsoleScript.php"
66+
if [ ! -f $CONSOLE_SCRIPT ]; then
67+
echo "[*] Downloading ConsoleScript.php"
68+
download_file "$CONSOLE_SCRIPT_URL" > ConsoleScript.php
4469
fi
4570

4671
if [ "$URL" == "" ]; then
@@ -55,5 +80,7 @@ PLUGIN_VERSION=$(grep 'version: ' plugin.yml | sed 's/^[^:]*: \(.*\)$/\1/g')
5580
GIT_COMMIT="$(git rev-parse HEAD)"
5681
cd ..
5782

58-
$PHP -dphar.readonly=0 "$DEVTOOLS" --make="./plugin/" --relative="./plugin/" --out "${PLUGIN_NAME}_v${PLUGIN_VERSION}-${GIT_COMMIT:0:8}.phar"
59-
rm -fr plugin
83+
$PHP -dphar.readonly=0 "$CONSOLE_SCRIPT" --make="./plugin/" --relative="./plugin/" --out "$OUTDIR/${PLUGIN_NAME}_v${PLUGIN_VERSION}-${GIT_COMMIT:0:8}.phar"
84+
85+
# cleanup
86+
rm -fr plugin ConsoleScript.php

0 commit comments

Comments
 (0)