/
/
/
1#!/bin/sh
2set -e
3
4# Parse configuration
5server_repo=$(cat /data/options.json | jq -r .server_repo)
6frontend_repo=$(cat /data/options.json | jq -r .frontend_repo)
7
8echo ""
9echo "-----------------------------------------------------------"
10echo "Music Assistant Developer Add-on"
11echo "-----------------------------------------------------------"
12echo ""
13
14# Check if server_repo is empty or null
15if [ -z "$server_repo" ] || [ "$server_repo" = "null" ]; then
16 build_from_source=false
17 echo "No server_repo specified - using latest nightly release from GitHub"
18else
19 build_from_source=true
20 echo "Building from source using server_repo: $server_repo"
21fi
22echo ""
23
24# Function to parse repository reference and return owner/repo@ref
25parse_repo_ref() {
26 local input="$1"
27 local default_owner="$2"
28 local default_repo="$3"
29
30 # If input starts with "pr-", convert to pull request reference
31 if echo "$input" | grep -q "^pr-"; then
32 pr_number=$(echo "$input" | sed 's/pr-//')
33 echo "${default_owner}/${default_repo}@refs/pull/${pr_number}/head"
34 return
35 fi
36
37 # If input contains "/" (fork reference)
38 if echo "$input" | grep -q "/"; then
39 # Check if it already has @ for branch
40 if echo "$input" | grep -q "@"; then
41 echo "$input"
42 else
43 # It's just owner/repo, use default branch
44 echo "${input}@main"
45 fi
46 return
47 fi
48
49 # Otherwise, it's just a branch/commit reference
50 echo "${default_owner}/${default_repo}@${input}"
51}
52
53# Function to build git URL from parsed reference
54build_git_url() {
55 local parsed="$1"
56 echo "git+https://github.com/${parsed}"
57}
58
59# Activate virtual environment
60. $VIRTUAL_ENV/bin/activate
61
62echo "-----------------------------------------------------------"
63echo "Step 1: Installing Music Assistant Server"
64echo "-----------------------------------------------------------"
65echo ""
66
67if [ "$build_from_source" = true ]; then
68 # Parse server repository reference
69 server_ref=$(parse_repo_ref "$server_repo" "music-assistant" "server")
70 server_url=$(build_git_url "$server_ref")
71
72 echo "Server repository: $server_ref"
73 echo "Server URL: $server_url"
74 echo ""
75
76 # Install server from specified repository
77 uv pip install \
78 --no-cache \
79 --link-mode=copy \
80 "$server_url"
81else
82 # Install latest nightly wheel from GitHub releases
83 echo "Fetching latest nightly release from GitHub..."
84 echo ""
85
86 # Get the latest pre-release info from GitHub API
87 # Write to temp file to avoid control character issues when passing through shell variables
88 tmp_releases="/tmp/releases.json"
89 curl -s "https://api.github.com/repos/music-assistant/server/releases?per_page=10" > "$tmp_releases"
90 release_tag=$(jq -r '[.[] | select(.prerelease == true)] | first | .tag_name' < "$tmp_releases")
91 wheel_url=$(jq -r '[.[] | select(.prerelease == true)] | first | .assets[] | select(.name | endswith(".whl")) | .browser_download_url' < "$tmp_releases")
92 rm -f "$tmp_releases"
93
94 if [ -z "$wheel_url" ] || [ "$wheel_url" = "null" ]; then
95 echo "ERROR: Could not find wheel in latest nightly release"
96 echo "Falling back to stable PyPI release..."
97 uv pip install \
98 --no-cache \
99 --link-mode=copy \
100 music-assistant
101 else
102 echo "Found nightly release: $release_tag"
103 echo "Wheel URL: $wheel_url"
104 echo ""
105 echo "Downloading and installing nightly wheel..."
106 uv pip install \
107 --no-cache \
108 --link-mode=copy \
109 "$wheel_url"
110 fi
111fi
112
113echo ""
114echo "â Server installation complete"
115echo ""
116
117# Check if we should build frontend - this is independent of server source
118build_frontend=false
119if [ -n "$frontend_repo" ] && [ "$frontend_repo" != "null" ]; then
120 build_frontend=true
121 # Parse frontend repository reference
122 frontend_ref=$(parse_repo_ref "$frontend_repo" "music-assistant" "frontend")
123
124 echo "-----------------------------------------------------------"
125 echo "Step 2: Building and Installing Music Assistant Frontend"
126 echo "-----------------------------------------------------------"
127 echo ""
128 echo "Frontend repository: $frontend_ref"
129 echo ""
130else
131 echo "-----------------------------------------------------------"
132 echo "Step 2: Skipping Frontend Build"
133 echo "-----------------------------------------------------------"
134 echo ""
135 echo "No frontend_repo specified - using frontend bundled with server"
136 echo ""
137fi
138
139if [ "$build_frontend" = true ]; then
140
141# Extract owner, repo, and ref from parsed reference
142frontend_owner=$(echo "$frontend_ref" | cut -d'/' -f1)
143frontend_repo_name=$(echo "$frontend_ref" | cut -d'/' -f2 | cut -d'@' -f1)
144frontend_branch=$(echo "$frontend_ref" | cut -d'@' -f2)
145
146# Create temporary directory for frontend build
147frontend_dir="/tmp/frontend-build"
148rm -rf "$frontend_dir"
149mkdir -p "$frontend_dir"
150
151echo "Cloning frontend repository..."
152cd "$frontend_dir"
153
154# Clone the repository
155git clone --depth 1 --branch "$frontend_branch" \
156 "https://github.com/${frontend_owner}/${frontend_repo_name}.git" . 2>/dev/null || \
157 git clone "https://github.com/${frontend_owner}/${frontend_repo_name}.git" . && \
158 git checkout "$frontend_branch"
159
160echo "â Frontend cloned"
161echo ""
162
163# Check if package.json exists (verify it's a valid frontend repo)
164if [ ! -f "package.json" ]; then
165 echo "ERROR: package.json not found in frontend repository!"
166 echo "This doesn't appear to be a valid Music Assistant frontend repository."
167 exit 1
168fi
169
170echo "Installing frontend dependencies...1"
171# Try to remount /tmp with exec if it's mounted noexec
172if mount | grep -q "on /tmp.*noexec"; then
173 echo "Detected /tmp mounted with noexec, attempting to remount..."
174 mount -o remount,exec /tmp 2>/dev/null || echo "Warning: Could not remount /tmp"
175fi
176yarn install --frozen-lockfile --prefer-offline
177
178echo "â Dependencies installed"
179echo ""
180
181echo "Building frontend..."
182yarn build
183
184echo "â Frontend build complete"
185echo ""
186
187# Check if the Python package structure exists
188if [ ! -f "setup.py" ] && [ ! -f "pyproject.toml" ]; then
189 echo "ERROR: No Python package configuration found!"
190 echo "Frontend repository must be installable as a Python package."
191 exit 1
192fi
193
194echo "Installing frontend as Python package..."
195cd "$frontend_dir"
196uv pip install --no-cache --link-mode=copy .
197
198echo "â Frontend installation complete"
199echo ""
200
201# Cleanup
202cd /
203rm -rf "$frontend_dir"
204
205fi # End of build_frontend check
206
207echo "-----------------------------------------------------------"
208echo "Starting Music Assistant"
209echo "-----------------------------------------------------------"
210echo ""
211
212# Start Music Assistant
213exec mass --data-dir /data --cache-dir /data/.cache
214
215