-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdev
executable file
·91 lines (79 loc) · 2.12 KB
/
dev
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
#!/bin/bash
# Helper script for commands related to the CS Unplugged Classic repository.
#
# TODO:
# - Look at using Hugo's live server for hotreloading.
set -e
ERROR='\033[0;31m'
SUCCESS='\033[0;32m'
CODE='\033[0;36m'
NC='\033[0m' # No Color
cmd_helps=()
defhelp() {
local command="${1?}"
local text="${2?}"
local help_str
help_str="$(printf ' %-28s %s' "$command" "$text")"
cmd_helps+=("$help_str")
}
# Print out help information
cmd_help() {
echo "Script for performing tasks related to the CS Unplugged Classic repository."
echo
echo "Usage: ./dev [COMMAND]"
echo "Replace [COMMAND] with a word from the list below."
echo
echo "COMMAND list:"
for str in "${cmd_helps[@]}"; do
echo -e "$str"
done
}
defhelp help 'View all help.'
# Start development environment
cmd_start() {
echo "Creating systems..."
docker compose -f docker-compose.local.yml up -d
# Alert user that system is ready
echo -e "\n${SUCCESS}System is up!${NC}"
echo -e "Run the command ${CODE}./dev update${NC} to create content."
}
defhelp start 'Start development environment.'
# Stop development environment
cmd_end() {
echo "Stopping systems..."
docker compose -f docker-compose.local.yml down
}
defhelp end 'Stop development environment.'
# Build Docker images
cmd_build() {
echo "Building Docker images..."
docker compose -f docker-compose.local.yml build "$@"
}
defhelp build 'Build or rebuild Docker images.'
# Update all content
cmd_update() {
hugo --config config.yaml,config.local.yaml
echo -e "\n${SUCCESS}Content has been generated!${NC}"
echo "Open your preferred web browser to the URL 'https://classic.cs-unplugged.localhost'"
}
defhelp update 'Create files using Hugo command.'
# --- Core script logic -------------------------------------------------------
silent() {
"$@" > /dev/null 2>&1
}
# If no command given
if [ $# -eq 0 ]; then
echo -e "${ERROR}ERROR: This script requires a command!${NC}"
cmd_help
exit 1
fi
cmd="$1"
shift
if silent type "cmd_$cmd"; then
"cmd_$cmd" "$@"
exit $?
else
echo -e "${ERROR}ERROR: Unknown command!${NC}"
echo "Type './dev help' for available commands."
exit 1
fi