-
Notifications
You must be signed in to change notification settings - Fork 67
/
panda
executable file
·209 lines (199 loc) · 7.03 KB
/
panda
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/usr/bin/env bash
# resolve shell-specifics
case "$(echo "$SHELL" | sed -E 's|/usr(/local)?||g')" in
"/bin/zsh")
RCPATH="$HOME/.zshrc"
SOURCE="${BASH_SOURCE[0]:-${(%):-%N}}"
;;
*)
RCPATH="$HOME/.bashrc"
if [[ -f "$HOME/.bash_aliases" ]]; then
RCPATH="$HOME/.bash_aliases"
fi
SOURCE="${BASH_SOURCE[0]}"
;;
esac
# get base dir regardless of execution location
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ "$SOURCE" != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
SOURCE=$([[ "$SOURCE" = /* ]] && echo "$SOURCE" || echo "$PWD/${SOURCE#./}")
basedir=$(dirname "$SOURCE")
gitcmd="git -c commit.gpgsign=false"
source "$basedir/scripts/functions.sh"
"$basedir"/scripts/requireDeps.sh || exit 1
failed=0
case "$1" in
"rb" | "rbp" | "rebuild")
(
set -e
cd "$basedir"
scripts/rebuildPatches.sh "$basedir" $2 || exit 1
) || failed=1
;;
"rbf" | "rbfull")
(
set -e
cd "$basedir"
scripts/rebuildPatches.sh "$basedir" "nofilter" || exit 1
) || failed=1
;;
"setup")
(
set -e
cd "$basedir"
scripts/build.sh "$basedir" "--setup" || exit 1
) || failed=1
;;
"p" | "patch")
(
set -e
cd "$basedir"
scripts/build.sh "$basedir" || exit 1
) || failed=1
;;
"j" | "jar")
(
set -e
cd "$basedir"
scripts/build.sh "$basedir" "--jar" || exit 1
) || failed=1
;;
"pc" | "paperclip")
(
set -e
cd "$basedir"
scripts/paperclip.sh "$basedir" || exit 1
) || failed=1
;;
"make")
(
if [[ "$2" = "bacon" ]] ; then
set -e
cd "$basedir"
scripts/build.sh "$basedir" "--jar"
fi
)
;;
"r" | "root")
cd "$basedir"
;;
"a" | "api")
cd "$basedir/PandaSpigot-API"
;;
"s" | "server")
cd "$basedir/PandaSpigot-Server"
;;
"c" | "clean")
rm -rf PandaSpigot-API
rm -rf PandaSpigot-Server
rm -rf base
echo "Cleaned build files"
;;
"con" | "continue")
if [ -d ".git/rebase-apply" ]; then
git -c commit.gpgsign=false am --continue
elif [ -d ".git/rebase-merge" ]; then
git -c commit.gpgsign=false rebase --continue
fi
;;
"e" | "edit")
case "$2" in
"s" | "server")
mkdir -p "$basedir/work/Temp"
echo "$basedir/PandaSpigot-Server" > "$basedir/work/Temp/PAPER_LAST_EDIT"
cd "$basedir/PandaSpigot-Server"
(
set -e
paperstash
$gitcmd rebase -i upstream/upstream
paperunstash
)
;;
"a" | "api")
mkdir -p "$basedir/work/Temp"
echo "$basedir/PandaSpigot-API" > "$basedir/work/Temp/PAPER_LAST_EDIT"
cd "$basedir/PandaSpigot-API"
(
set -e
paperstash
$gitcmd rebase -i upstream/upstream
paperunstash
)
;;
"c" | "continue")
cd "$( < "$basedir/work/Temp/PAPER_LAST_EDIT")"
rm -f "$basedir/work/Temp/PAPER_LAST_EDIT"
(
set -e
$gitcmd add .
$gitcmd commit --amend
$gitcmd rebase --continue
cd "$basedir"
scripts/rebuildPatches.sh "$basedir"
)
;;
*)
echo "You must edit either the api or server."
;;
esac
;;
"install")
if [[ -f "$RCPATH" ]] ; then
NAME="panda"
if [[ ! -z "${2+x}" ]] ; then
NAME="$2"
fi
(grep "alias $NAME=" "$RCPATH" > /dev/null) && (sed -i "s|alias $NAME=.*|alias $NAME='. $SOURCE'|g" "$RCPATH") || (echo "alias $NAME='. $SOURCE'" >> "$RCPATH")
alias "$NAME=. $SOURCE"
echo "You can now just type '$NAME' at any time to access the panda tool."
else
echo "We were unable to install the panda build tool alias: $RCPATH is missing"
fi
;;
*)
echo "PandaSpigot build tool command. This provides a variety of commands to build and manage the PandaSpigot build"
echo "environment. For all of the functionality of this command to be available, you must first run the"
echo "'install' command. View below for details. For essential building and patching, you do not need to do the install."
echo ""
echo " Normal commands:"
echo " * rb, rebuild | Rebuild patches, can be called from anywhere."
echo " * setup | Remap, decompile, and patch Minecraft. Can be run from anywhere."
echo " * p, patch | Apply all patches to the project without building it. Can be run from anywhere."
echo " * j, jar | Apply all patches and build the project, paperclip.jar will be output. Can be run from anywhere."
echo " * c, clean | Removes all generated files, PandaSpigot-API, PandaSpigot-Server, and work."
echo " * con, continue | Shortcut command for running git am --continue, or git rebase --continue."
echo ""
echo " These commands require the install command before use:"
echo " * r, root | Change directory to the root of the project."
echo " * a. api | Move to the PandaSpigot-API directory."
echo " * s, server | Move to the PandaSpigot-Server directory."
echo " * e, edit | Use to edit a specific patch, give it the argument \"server\" or \"api\""
echo " | respectively to edit the correct project. Use the argument \"continue\" after"
echo " | the changes have been made to finish and rebuild patches. Can be called from anywhere."
echo ""
echo " * install | Add an alias to $RCPATH to allow full functionality of this script. Run as:"
echo " | . ./panda install"
echo " | After you run this command you'll be able to just run 'panda' from anywhere."
echo " | The default name for the resulting alias is 'panda', you can give an argument to override"
echo " | this default, such as:"
echo " | . ./panda install example"
echo " | Which will allow you to run 'example' instead."
;;
esac
unset RCPATH
unset SOURCE
unset basedir
unset -f color
unset -f colorend
unset -f paperstash
unset -f paperunstash
if [[ "$failed" == "1" ]]; then
unset failed
false
else
unset failed
true
fi