-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish.sh
executable file
·122 lines (97 loc) · 2.86 KB
/
publish.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
120
121
122
#!/bin/bash
# Correct dimensions for banner
CORRECT_B_W=800
CORRECT_B_H=450
WORK_DIR=/tmp/devcade_publishing_script_temp
#ZIP_NAME=devcade-publishing-script-output # Oops actually it has to be the name of the game.
HOME_BASE_DIR=$(pwd)
set -e # Peace out if shit breaks
function help() {
echo "Publish a dotnet game and output to a folder called 'publish' in the current directory."
echo
echo "-b : Set banner path | -i : Set icon path | -g : Set game path | -h : Print help"
}
function validate_images() {
# Check banner/icon file type
BANNER_TYPE=$(file -b --mime-type $BANNER)
ICON_TYPE=$(file -b --mime-type $ICON)
if [[ "$BANNER_TYPE" != "image/png" ]]; then
echo Banner is $BANNER_TYPE
echo "Error: Banner must be PNG!"
exit 1
fi
if [[ "$ICON_TYPE" != "image/png" ]]; then
echo Icon is $ICON_TYPE
echo "Error: Icon must be PNG!"
exit 1
fi
# Check width and height
BANNER_WIDTH=$(file -b $BANNER | awk '{print $4}' | sed 's/,//g')
BANNER_HEIGHT=$(file -b $BANNER | awk '{print $6}' | sed 's/,//g')
ICON_WIDTH=$(file -b $ICON | awk '{print $4}' | sed 's/,//g')
ICON_HEIGHT=$(file -b $ICON | awk '{print $6}' | sed 's/,//g')
if [[ "$BANNER_WIDTH" != "$CORRECT_B_W" || "$BANNER_HEIGHT" != "$CORRECT_B_H" ]]; then
echo "Error: Banner dimensions must be $CORRECT_B_W x $CORRECT_B_H!"
exit 1
fi
if [[ "$ICON_WIDTH" != "$ICON_HEIGHT" ]]; then
echo "Error: Icon dimensions must be square!"
exit 1
fi
}
function build_game() {
# Check that the game directory is actually a directory
GAME_DIR_TYPE=$(file -b $GAME)
if [[ $GAME_DIR_TYPE != "directory" ]]; then
echo "Error: Game must be a Directory!"
exit 1
fi
# Try building a dotnet app in that directory. The Dotnet SDK should do the rest for us.
echo "Building Game. Please be paitent."
cd $GAME
dotnet publish -c Release -r linux-x64 --self-contained
cd ..
echo "Build complete."
}
function package_game() {
# Create temporary directory
rm -rf $WORK_DIR
mkdir -p $WORK_DIR
# Copy assets to temporary directory
PUB="$GAME/bin/Release/net6.0/linux-x64/publish"
cp -r $BANNER $ICON $PUB $WORK_DIR
cd $WORK_DIR
ZIP_NAME=$(basename $GAME)
zip -r "$ZIP_NAME.zip" $BANNER $ICON "publish"
cp "$ZIP_NAME.zip" $HOME_BASE_DIR
# Delete temporary directory
cd $HOME_BASE_DIR
rm -rf $WORK_DIR
echo "Finished. Upload \""$ZIP_NAME.zip"\" to https://devcade.csh.rit.edu"
}
# === MAIN SCRIPT ===
# Get command line args
while getopts ":hb:i:g:" option; do
case $option in
b) # Set banner path
BANNER=$OPTARG;;
i) # Set icon path
ICON=$OPTARG;;
g) # Set game path
GAME=$OPTARG;;
h) # Print help
help
exit;;
esac
done
# Check args
if [[ -z $BANNER || -z $ICON || -z $GAME ]]; then
help
exit 1
fi
# Banner/Icon validation
validate_images
# Build the game
build_game
# Package the game
package_game