Skip to content

Commit 966810a

Browse files
committed
Update sample env; reorganize
Add PUID/GID support to Docker container Fixup rebase
1 parent 5e3793a commit 966810a

File tree

7 files changed

+70
-32
lines changed

7 files changed

+70
-32
lines changed

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,8 @@ RUN chmod +x /start.sh ./explo
3838
# Can be defined from compose as well
3939
ENV WEEKLY_EXPLORATION_SCHEDULE="15 0 * * 2"
4040

41+
# Default PUID and PGID
42+
ENV PUID=1000
43+
ENV PGID=1000
44+
4145
CMD ["/start.sh"]

docker-compose.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ services:
1212
# - /path/to/cookies.txt:/opt/explo/cookies.txt # Path to optional cookies file (for yt-dlp)
1313
environment:
1414
- TZ=UTC # Change this to the timezone set in ListenBrainz (default is UTC)
15+
- PUID=1000 # User ID for file permissions (optional, defaults to 1000)
16+
- PGID=1000 # Group ID for file permissions (optional, defaults to 1000)
1517

1618
- WEEKLY_EXPLORATION_SCHEDULE=15 00 * * 2 # Runs weekly, every Tuesday 15 minutes past midnight
1719
- WEEKLY_EXPLORATION_FLAGS= # Run weekly exploration with default settings

docker/start.sh

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,37 @@
11
#!/bin/sh
2+
3+
# Handle PUID/PGID
4+
if [ "$PUID" != "0" ] && [ "$PGID" != "0" ]; then
5+
echo "[setup] Setting up user with PUID=$PUID and PGID=$PGID"
6+
7+
# Create group if it doesn't exist
8+
if ! getent group explo > /dev/null 2>&1; then
9+
groupadd -g "$PGID" explo
10+
fi
11+
12+
# Create user if it doesn't exist
13+
if ! getent passwd explo > /dev/null 2>&1; then
14+
useradd -u "$PUID" -g "$PGID" -d /opt/explo -s /bin/sh explo
15+
fi
16+
17+
# Ensure explo user owns the working directory and data directory
18+
chown -R explo:explo /opt/explo
19+
[ -d /data ] && chown -R explo:explo /data
20+
21+
# If running as non-root, exec as the explo user
22+
if [ "$(id -u)" = "0" ]; then
23+
exec su-exec explo "$0" "$@"
24+
fi
25+
fi
26+
227
echo "[setup] Initializing cron jobs..."
328

429

530
# $CRON_SHCEDULE was deprecated in v0.11.0, keeping this block for backwards compatibility
631
if [ -n "$CRON_SCHEDULE" ]; then
7-
echo "$CRON_SCHEDULE apk add --upgrade yt-dlp && cd /opt/explo && ./explo >> /proc/1/fd/1 2>&1" > /etc/crontabs/root
8-
chmod 600 /etc/crontabs/root
32+
cmd="apk add --upgrade yt-dlp && cd /opt/explo && ./explo >> /proc/1/fd/1 2>&1"
33+
echo "$CRON_SCHEDULE $cmd" > "/var/spool/cron/crontabs/$CRON_USER"
34+
chmod 600 "/var/spool/cron/crontabs/$CRON_USER"
935
echo "[setup] Registered single CRON_SCHEDULE job: $CRON_SCHEDULE"
1036
crond -f -l 2
1137
fi
@@ -25,13 +51,13 @@ for var in $(env | grep "_SCHEDULE=" | cut -d= -f1); do
2551
# Default: just run explo if flags are empty
2652
cmd="apk add --upgrade yt-dlp && cd /opt/explo && ./explo $flags >> /proc/1/fd/1 2>&1"
2753

28-
echo "$schedule $cmd" >> /etc/crontabs/root
54+
echo "$schedule $cmd" >> "/var/spool/cron/crontabs/$CRON_USER"
2955
echo "[setup] Registered job: $job"
3056
echo " Schedule: $schedule"
3157
echo " Command : ./explo $flags"
3258
done
3359

34-
chmod 600 /etc/crontabs/root
60+
chmod 600 "/var/spool/cron/crontabs/$CRON_USER"
3561

3662
echo "[setup] Starting cron..."
3763

go.sum

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,14 @@ golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+o
5757
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
5858
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b h1:uwuIcX0g4Yl1NC5XAz37xsr2lTtcqevgzYNVt49waME=
5959
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
60-
golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
61-
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
60+
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
61+
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
6262
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
6363
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
6464
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
6565
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
6666
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
6767
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
68-
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
6968
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
7069
golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
7170
golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=

sample.env

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ YOUTUBE_API_KEY=
8181
# Comma-separated (without spaces) keywords to avoid, when filtering slskd results (default: live,remix,instrumental,extended,clean,acapella)
8282
# FILTER_LIST=live,remix,instrumental,extended,clean,acapella
8383

84+
# === Lidarr Configuration ===
85+
86+
# LIDARR_API_KEY=
87+
# LIDARR_RETRY=
88+
# LIDARR_DL_ATTEMPTS=
89+
# LIDARR_DIR=
90+
# MIGRATE_DOWNLOADS=
91+
# LIDARR_TIMEOUT=
92+
# LIDARR_SCHEME=
93+
# LIDARR_URL=
94+
8495
# === Metadata / Formatting ===
8596

8697
# Set to true to merge featured artists into title (recommended), false appends them to artist field (default: true)

src/config/config.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@ type Credentials struct {
5858
Salt string
5959
}
6060

61-
type DiscoveryConfig struct {
62-
Discovery string `env:"DISCOVERY_SERVICE" env-default:"listenbrainz"`
63-
Separator string `env:"FILENAME_SEPARATOR" env-default:" "`
64-
Listenbrainz Listenbrainz
65-
}
66-
6761
type Lidarr struct {
6862
APIKey string `env:"LIDARR_API_KEY"`
6963
Retry int `env:"LIDARR_RETRY" env-default:"5"` // Number of times to check search status before skipping the track
@@ -134,17 +128,19 @@ type SlskdMon struct {
134128
Duration time.Duration `env:"SLSKD_MONITOR_DURATION" env-default:"15m"`
135129
}
136130

131+
type DiscoveryConfig struct {
132+
Discovery string `env:"DISCOVERY_SERVICE" env-default:"listenbrainz"`
133+
Listenbrainz Listenbrainz
134+
}
135+
137136
type Listenbrainz struct {
138137
Discovery string `env:"LISTENBRAINZ_DISCOVERY" env-default:"playlist"`
139138
User string `env:"LISTENBRAINZ_USER"`
140139
ImportPlaylist string
141140
SingleArtist bool `env:"SINGLE_ARTIST" env-default:"true"`
142141
}
143142

144-
func (cfg *Config) ReadEnv() {
145-
}
146-
147-
func ReadEnv() Config {
143+
func ReadEnv() {
148144
var cfg Config
149145

150146
// Try to read from .env file first

src/downloader/lidarr.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,21 @@ func (c Lidarr) findBestAlbumMatch(track *models.Track) (*Album, error) {
301301
return &topMatch, nil
302302
}
303303

304+
func (c Lidarr) getDownloadStatus() (DownloadStatus, error) {
305+
reqParams := "/api/v0/transfers/downloads"
306+
307+
body, err := c.HttpClient.MakeRequest("GET", c.Cfg.URL+reqParams, nil, nil)
308+
if err != nil {
309+
return nil, err
310+
}
311+
312+
var status DownloadStatus
313+
if err := util.ParseResp(body, &status); err != nil {
314+
return nil, err
315+
}
316+
return status, nil
317+
}
318+
304319
func (c Lidarr) MonitorDownloads(tracks []*models.Track) error {
305320
monitorCfg := MonitorConfig{
306321
CheckInterval: 1 * time.Minute,
@@ -322,21 +337,6 @@ func (c Lidarr) MonitorDownloads(tracks []*models.Track) error {
322337
return nil
323338
}
324339

325-
func (c Lidarr) getDownloadStatus() (DownloadStatus, error) {
326-
reqParams := "/api/v0/transfers/downloads"
327-
328-
body, err := c.HttpClient.MakeRequest("GET", c.Cfg.URL+reqParams, nil, nil)
329-
if err != nil {
330-
return nil, err
331-
}
332-
333-
var status DownloadStatus
334-
if err := util.ParseResp(body, &status); err != nil {
335-
return nil, err
336-
}
337-
return status, nil
338-
}
339-
340340
func (c Lidarr) cleanupTrack(track *models.Track, fileID string) {
341341
if err := c.deleteSearch(track.ID); err != nil {
342342
debug.Debug(fmt.Sprintf("[slskd] failed to delete search request: %v", err))

0 commit comments

Comments
 (0)