-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·88 lines (72 loc) · 1.87 KB
/
build.sh
File metadata and controls
executable file
·88 lines (72 loc) · 1.87 KB
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
#!/usr/bin/env bash
set -Eeuo pipefail
IFS=$'\n\t'
# === CONFIG ===
BUILD_DIR="build"
OUTPUT_FILE="$BUILD_DIR/nepali-calendar.plasmoid"
SOURCE_DIR="package"
LOG_FILE="/tmp/$(basename "$0").log"
# === COLORS ===
RED="\033[0;31m"
GREEN="\033[0;32m"
YELLOW="\033[1;33m"
BLUE="\033[0;34m"
NC="\033[0m" # No Color
# === LOGGING ===
log() {
local level="$1"
local message="$2"
local color="$NC"
case "$level" in
INFO) color="$BLUE" ;;
SUCCESS) color="$GREEN" ;;
WARNING) color="$YELLOW" ;;
ERROR) color="$RED" ;;
esac
echo -e "[$(date +'%Y-%m-%d %H:%M:%S')] ${color}${level}:${NC} $message" | tee -a "$LOG_FILE"
}
# === CLEANUP AND ERROR HANDLING ===
cleanup() {
log INFO "Performing cleanup before exit..."
}
error_handler() {
local exit_code=$?
local line=$1
log ERROR "Error on or near line $line (exit code: $exit_code)."
cleanup
exit "$exit_code"
}
trap 'error_handler $LINENO' ERR
trap cleanup EXIT INT TERM
# === DEPENDENCY CHECK ===
check_dependencies() {
local missing=0
for cmd in zip; do
if ! command -v "$cmd" &>/dev/null; then
log ERROR "Required command '$cmd' not found in PATH."
missing=1
fi
done
if [[ $missing -eq 1 ]]; then
log ERROR "Please install missing dependencies and retry."
exit 1
fi
}
# === MAIN BUILD LOGIC ===
main() {
log INFO "Starting build process..."
check_dependencies
if [[ ! -d "$SOURCE_DIR" ]]; then
log ERROR "Source directory '$SOURCE_DIR' does not exist."
exit 1
fi
if [[ -d "$BUILD_DIR" ]]; then
log WARNING "Removing existing build directory..."
rm -rf "$BUILD_DIR"
fi
mkdir -p "$BUILD_DIR"
log INFO "Creating plasmoid package..."
zip -rq "$OUTPUT_FILE" "$SOURCE_DIR"
log SUCCESS "Build successful. Output: $OUTPUT_FILE"
}
main "$@"