/
/
/
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# Function to parse repository reference and return owner/repo@ref
15parse_repo_ref() {
16 local input="$1"
17 local default_owner="$2"
18 local default_repo="$3"
19
20 # If input starts with "pr-", convert to pull request reference
21 if echo "$input" | grep -q "^pr-"; then
22 pr_number=$(echo "$input" | sed 's/pr-//')
23 echo "${default_owner}/${default_repo}@refs/pull/${pr_number}/head"
24 return
25 fi
26
27 # If input contains "/" (fork reference)
28 if echo "$input" | grep -q "/"; then
29 # Check if it already has @ for branch
30 if echo "$input" | grep -q "@"; then
31 echo "$input"
32 else
33 # It's just owner/repo, use default branch
34 echo "${input}@main"
35 fi
36 return
37 fi
38
39 # Otherwise, it's just a branch/commit reference
40 echo "${default_owner}/${default_repo}@${input}"
41}
42
43# Function to build git URL from parsed reference
44build_git_url() {
45 local parsed="$1"
46 echo "git+https://github.com/${parsed}"
47}
48
49# Parse server repository reference
50server_ref=$(parse_repo_ref "$server_repo" "music-assistant" "server")
51server_url=$(build_git_url "$server_ref")
52
53echo "Server repository: $server_ref"
54echo "Server URL: $server_url"
55echo ""
56
57# Activate virtual environment
58. $VIRTUAL_ENV/bin/activate
59
60echo "-----------------------------------------------------------"
61echo "Step 1: Installing Music Assistant Server"
62echo "-----------------------------------------------------------"
63echo ""
64
65# Install server from specified repository
66uv pip install \
67 --no-cache \
68 --link-mode=copy \
69 "$server_url"
70
71echo ""
72echo "â Server installation complete"
73echo ""
74
75# Parse frontend repository reference
76frontend_ref=$(parse_repo_ref "$frontend_repo" "music-assistant" "frontend")
77
78echo "-----------------------------------------------------------"
79echo "Step 2: Building and Installing Music Assistant Frontend"
80echo "-----------------------------------------------------------"
81echo ""
82echo "Frontend repository: $frontend_ref"
83echo ""
84
85# Extract owner, repo, and ref from parsed reference
86frontend_owner=$(echo "$frontend_ref" | cut -d'/' -f1)
87frontend_repo_name=$(echo "$frontend_ref" | cut -d'/' -f2 | cut -d'@' -f1)
88frontend_branch=$(echo "$frontend_ref" | cut -d'@' -f2)
89
90# Create temporary directory for frontend build
91frontend_dir="/tmp/frontend-build"
92rm -rf "$frontend_dir"
93mkdir -p "$frontend_dir"
94
95echo "Cloning frontend repository..."
96cd "$frontend_dir"
97
98# Clone the repository
99git clone --depth 1 --branch "$frontend_branch" \
100 "https://github.com/${frontend_owner}/${frontend_repo_name}.git" . 2>/dev/null || \
101 git clone "https://github.com/${frontend_owner}/${frontend_repo_name}.git" . && \
102 git checkout "$frontend_branch"
103
104echo "â Frontend cloned"
105echo ""
106
107# Check if package.json exists (verify it's a valid frontend repo)
108if [ ! -f "package.json" ]; then
109 echo "ERROR: package.json not found in frontend repository!"
110 echo "This doesn't appear to be a valid Music Assistant frontend repository."
111 exit 1
112fi
113
114echo "Installing frontend dependencies...1"
115# Try to remount /tmp with exec if it's mounted noexec
116if mount | grep -q "on /tmp.*noexec"; then
117 echo "Detected /tmp mounted with noexec, attempting to remount..."
118 mount -o remount,exec /tmp 2>/dev/null || echo "Warning: Could not remount /tmp"
119fi
120yarn install --frozen-lockfile --prefer-offline
121
122echo "â Dependencies installed"
123echo ""
124
125echo "Building frontend..."
126yarn build
127
128echo "â Frontend build complete"
129echo ""
130
131# Check if the Python package structure exists
132if [ ! -f "setup.py" ] && [ ! -f "pyproject.toml" ]; then
133 echo "ERROR: No Python package configuration found!"
134 echo "Frontend repository must be installable as a Python package."
135 exit 1
136fi
137
138echo "Installing frontend as Python package..."
139cd "$frontend_dir"
140uv pip install --no-cache --link-mode=copy .
141
142echo "â Frontend installation complete"
143echo ""
144
145# Cleanup
146cd /
147rm -rf "$frontend_dir"
148
149echo "-----------------------------------------------------------"
150echo "Starting Music Assistant"
151echo "-----------------------------------------------------------"
152echo ""
153
154# Start Music Assistant
155exec mass --data-dir /data --cache-dir /data/.cache
156
157