-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.sh
executable file
·52 lines (40 loc) · 1.27 KB
/
build.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
#!/usr/bin/env bash
#
# Exit immediately if a command exits with a non-zero status.
set -o nounset
WORKING_DIR=$(mktemp -d)
APP_NAME=$(basename "$PWD")
APP_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
function cleanup() {
rm -rf "$WORKING_DIR"
}
function main() {
echo "Building ${APP_NAME} deployment package..."
echo "----------------------------------------"
echo "[1] Downloading latest BookStack source..."
git clone "https://github.com/BookStackApp/BookStack.git" --branch "release" --single-branch "$WORKING_DIR"
VERSION=$(cat "${WORKING_DIR}/version")
VERSION=${VERSION:1}
echo
echo "[2] Copying Elastic Beanstalk files..."
cp -r . "$WORKING_DIR"
echo
echo "[3] Cleaning source files..."
cd "$WORKING_DIR"
rm -rf ".git"* "build.sh" *".zip" ".DS_Store"
echo
echo "[4] Generating filename..."
FILENAME="${APP_NAME}_${VERSION}_$(date +'%y%m%d-%H%M%S').zip"
echo "$FILENAME"
echo "[5] Compressing files..."
zip -9 -r "${APP_DIR}/${FILENAME}" .
echo
echo "Output file: ${FILENAME}"
cleanup
exit 0
}
# Set a trap for calling the cleanup fuction in case
# the script does not exit normally.
trap "cleanup; exit 1" HUP INT QUIT PIPE TERM
# Start the main function
main "$@"