-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocal-build.sh
executable file
·95 lines (76 loc) · 2.88 KB
/
local-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
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
#!/usr/bin/env bash
set -e # Exit immediately if a command exits with a non-zero status
MANIFEST_FILE="com.artemis_rgb.Artemis.yml"
BRANCH="test"
# Function to print error messages
error() {
echo "Error: $1" >&2
exit 1
}
# Function to check if a command exists
check_command() {
local cmd="$1"
if ! command -v "$cmd" &> /dev/null; then
error "$cmd is not installed. Please install $cmd and try again."
fi
echo "$cmd is installed."
}
# Check if required commands are installed
check_command "flatpak"
check_command "flatpak-builder"
check_command "yq"
# Extract required information from the manifest
if [ ! -f "$MANIFEST_FILE" ]; then
error "Manifest file '$MANIFEST_FILE' not found."
fi
echo "Parsing manifest file '$MANIFEST_FILE' to determine required Flatpak packages and ID..."
RUNTIME=$(yq e '.runtime' "$MANIFEST_FILE")
RUNTIME_VERSION=$(yq e '.["runtime-version"]' "$MANIFEST_FILE")
SDK=$(yq e '.sdk' "$MANIFEST_FILE")
SDK_EXTENSIONS=$(yq e '.["sdk-extensions"][]' "$MANIFEST_FILE" 2>/dev/null || echo "")
FLATPAK_ID=$(yq e '.id' "$MANIFEST_FILE")
if [ -z "$RUNTIME" ] || [ -z "$RUNTIME_VERSION" ] || [ -z "$SDK" ] || [ -z "$FLATPAK_ID" ]; then
error "Failed to extract required fields (runtime, runtime-version, sdk, id) from manifest."
fi
REQUIRED_FLATPAK_PACKAGES=(
"$RUNTIME//$RUNTIME_VERSION"
"$SDK//$RUNTIME_VERSION"
)
# Add SDK extensions if any
if [ -n "$SDK_EXTENSIONS" ]; then
while IFS= read -r EXT; do
REQUIRED_FLATPAK_PACKAGES+=("$EXT//$RUNTIME_VERSION")
done <<< "$SDK_EXTENSIONS"
fi
# Function to check if a Flatpak package is installed
is_flatpak_installed() {
local package="$1"
flatpak info "$package" &> /dev/null
}
# Install missing Flatpak packages
for package in "${REQUIRED_FLATPAK_PACKAGES[@]}"; do
if is_flatpak_installed "$package"; then
echo "Flatpak package '$package' is already installed."
else
echo "Flatpak package '$package' is not installed. Installing..."
flatpak install -y flathub "$package" || error "Failed to install $package"
fi
done
# Update Flatpak repositories
echo "Updating Flatpak repositories..."
flatpak update -y || error "Failed to update Flatpak repositories"
# Clean previous build artifacts
echo "Cleaning previous build artifacts..."
rm -f "${FLATPAK_ID}.flatpak"
rm -rf build-dir repo-dir
mkdir build-dir repo-dir
# Build the Flatpak
echo "Building the Flatpak..."
flatpak-builder --ccache --force-clean --default-branch="$BRANCH" build-dir "$MANIFEST_FILE" --repo=repo-dir || error "flatpak-builder failed"
# Bundle the Flatpak
echo "Bundling the Flatpak..."
flatpak build-bundle repo-dir "${FLATPAK_ID}.flatpak" "$FLATPAK_ID" "$BRANCH" || error "flatpak build-bundle failed"
echo "Flatpak build and bundle completed successfully."
# Optionally, install the Flatpak
echo "Installing the Flatpak..."
flatpak install --user --reinstall "${FLATPAK_ID}.flatpak"