/
/
/
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
118build_frontend=false
119if [ "$build_from_source" = true ]; then
120 # Building server from source - check if frontend_repo is specified
121 if [ -n "$frontend_repo" ] && [ "$frontend_repo" != "null" ]; then
122 build_frontend=true
123 # Parse frontend repository reference
124 frontend_ref=$(parse_repo_ref "$frontend_repo" "music-assistant" "frontend")
125
126 echo "-----------------------------------------------------------"
127 echo "Step 2: Building and Installing Music Assistant Frontend"
128 echo "-----------------------------------------------------------"
129 echo ""
130 echo "Frontend repository: $frontend_ref"
131 echo ""
132 else
133 echo "-----------------------------------------------------------"
134 echo "Step 2: Skipping Frontend Build"
135 echo "-----------------------------------------------------------"
136 echo ""
137 echo "No frontend_repo specified - using frontend bundled with server"
138 echo ""
139 fi
140else
141 echo "-----------------------------------------------------------"
142 echo "Step 2: Skipping Frontend Build"
143 echo "-----------------------------------------------------------"
144 echo ""
145 echo "Frontend build skipped - using frontend bundled with PyPI release"
146 echo ""
147fi
148
149if [ "$build_frontend" = true ]; then
150
151# Extract owner, repo, and ref from parsed reference
152frontend_owner=$(echo "$frontend_ref" | cut -d'/' -f1)
153frontend_repo_name=$(echo "$frontend_ref" | cut -d'/' -f2 | cut -d'@' -f1)
154frontend_branch=$(echo "$frontend_ref" | cut -d'@' -f2)
155
156# Create temporary directory for frontend build
157frontend_dir="/tmp/frontend-build"
158rm -rf "$frontend_dir"
159mkdir -p "$frontend_dir"
160
161echo "Cloning frontend repository..."
162cd "$frontend_dir"
163
164# Clone the repository
165git clone --depth 1 --branch "$frontend_branch" \
166 "https://github.com/${frontend_owner}/${frontend_repo_name}.git" . 2>/dev/null || \
167 git clone "https://github.com/${frontend_owner}/${frontend_repo_name}.git" . && \
168 git checkout "$frontend_branch"
169
170echo "â Frontend cloned"
171echo ""
172
173# Check if package.json exists (verify it's a valid frontend repo)
174if [ ! -f "package.json" ]; then
175 echo "ERROR: package.json not found in frontend repository!"
176 echo "This doesn't appear to be a valid Music Assistant frontend repository."
177 exit 1
178fi
179
180echo "Installing frontend dependencies...1"
181# Try to remount /tmp with exec if it's mounted noexec
182if mount | grep -q "on /tmp.*noexec"; then
183 echo "Detected /tmp mounted with noexec, attempting to remount..."
184 mount -o remount,exec /tmp 2>/dev/null || echo "Warning: Could not remount /tmp"
185fi
186yarn install --frozen-lockfile --prefer-offline
187
188echo "â Dependencies installed"
189echo ""
190
191echo "Building frontend..."
192yarn build
193
194echo "â Frontend build complete"
195echo ""
196
197# Check if the Python package structure exists
198if [ ! -f "setup.py" ] && [ ! -f "pyproject.toml" ]; then
199 echo "ERROR: No Python package configuration found!"
200 echo "Frontend repository must be installable as a Python package."
201 exit 1
202fi
203
204echo "Installing frontend as Python package..."
205cd "$frontend_dir"
206uv pip install --no-cache --link-mode=copy .
207
208echo "â Frontend installation complete"
209echo ""
210
211# Cleanup
212cd /
213rm -rf "$frontend_dir"
214
215fi # End of build_frontend check
216
217echo "-----------------------------------------------------------"
218echo "Starting Music Assistant"
219echo "-----------------------------------------------------------"
220echo ""
221
222# Start Music Assistant
223exec mass --data-dir /data --cache-dir /data/.cache
224
225