Skip to content

Commit d2e42af

Browse files
authored
Update yams (#22)
- better user management - add sample config file for future dev activities
1 parent 0378265 commit d2e42af

4 files changed

Lines changed: 82 additions & 18 deletions

File tree

Dockerfile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,17 @@ VOLUME /data
5757

5858
ENV STARTUP_DELAY_SEC ""
5959

60-
ENV MPD_HOST ""
61-
ENV MPD_PORT ""
60+
ENV MPD_HOST=""
61+
ENV MPD_PORT=""
6262

63-
ENV USER_MODE ""
64-
ENV PUID ""
65-
ENV PGID ""
63+
ENV USER_MODE=""
64+
ENV PUID=""
65+
ENV PGID=""
6666

67-
ENV API_KEY ""
68-
ENV API_SECRET ""
67+
ENV API_KEY=""
68+
ENV API_SECRET=""
69+
70+
ENV SESSION_FILE=""
6971

7072
COPY app/bin/run-yams.sh /app/bin/run-yams.sh
7173
RUN chmod 755 /app/bin/run-yams.sh

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ See the following table.
134134

135135
Date|Description
136136
:---|:---
137+
2024-10-07|Use exec so we can get rid of bash processes
137138
2023-04-19|Routine build after updates to the upstream project
138139
2023-03-09|Support for `API_KEY` and `API_SECRET` ([#13](https://github.com/GioF71/yams-docker/issues/13))
139140
2023-03-04|Add apt proxy support ([#4](https://github.com/GioF71/yams-docker/issues/4))

app/bin/run-yams.sh

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,23 @@
77
DEFAULT_UID=1000
88
DEFAULT_GID=1000
99

10+
DEFAULT_RUNTIME_DIR=/data
11+
runtime_dir=$DEFAULT_RUNTIME_DIR
12+
13+
if [ ! -w "$runtime_dir" ]; then
14+
echo "Runtime dir [$runtime_dir] is not writable, switching to /tmp ..."
15+
runtime_dir=/tmp
16+
fi
17+
18+
echo "Creating config directory [$runtime_dir/.config/yams] ..."
19+
mkdir -p $runtime_dir/.config/yams
20+
echo "Creating state directory [$runtime_dir/.local/state/yams] ..."
21+
mkdir -p $runtime_dir/.local/state/yams
22+
echo "Finished creating directories."
23+
24+
#CMD_LINE="XDG_RUNTIME_DIR=$runtime_dir yams --keep-alive --no-daemon"
1025
CMD_LINE="yams --keep-alive --no-daemon"
26+
echo "CMD_LINE=[$CMD_LINE]"
1127

1228
if [[ -n "${MPD_HOST}" ]]; then
1329
CMD_LINE="$CMD_LINE -m $MPD_HOST"
@@ -40,6 +56,31 @@ if [[ -n "$STARTUP_DELAY_SEC" ]]; then
4056
fi
4157
fi
4258

59+
# add session file path?
60+
use_custom_session_file=0
61+
if [[ -n "${SESSION_FILE}" ]]; then
62+
echo "SESSION_FILE=[$SESSION_FILE]"
63+
if [ -f "$SESSION_FILE" ]; then
64+
echo "SESSION_FILE [$SESSION_FILE] exists"
65+
use_custom_session_file=1
66+
CMD_LINE="$CMD_LINE --session-file-path $SESSION_FILE"
67+
fi
68+
fi
69+
70+
if [ $use_custom_session_file -eq 0 ]; then
71+
echo "Creating directory for session file [$runtime_dir/.config/yams] ..."
72+
mkdir -p $runtime_dir/.config/yams
73+
echo "Setting default session file to [$runtime_dir/.config/yams/.lastfm_session] ..."
74+
CMD_LINE="$CMD_LINE --session-file-path $runtime_dir/.config/yams/.lastfm_session"
75+
fi
76+
77+
uid=$(id -u)
78+
if [[ $uid -ne 0 ]]; then
79+
echo "This container must be run as root."
80+
exit 1
81+
fi
82+
83+
echo "Running with uid=[$uid] ..."
4384
# Create user and group
4485
if [[ -n "{${PUID}" || -z "${USER_MODE}" || "${USER_MODE^^}" == "YES" ]]; then
4586
echo "User mode enabled"
@@ -72,22 +113,25 @@ if [[ -n "{${PUID}" || -z "${USER_MODE}" || "${USER_MODE^^}" == "YES" ]]; then
72113
echo "Created $USER_NAME (group: $GROUP_NAME)"
73114
cat /etc/passwd|grep $USER_NAME
74115
echo "Creating home directory ..."
75-
mkdir -p /data
116+
mkdir -p $runtime_dir
76117
echo "Setting ownership ..."
77118
chown -R yams-user:yams-group /app/log
78-
chown -R yams-user:yams-group /data
119+
chown -R yams-user:yams-group $runtime_dir
79120
echo "Setting home directory ..."
80-
usermod --home /data yams-user
81-
cat /etc/passwd|grep $USER_NAME
82-
# this should not be needed
83-
CMD_LINE="$CMD_LINE --session-file-path /data/.config/yams/.lastfm_session"
84-
if [ -f /data/.config/yams/yams.pid ]; then
121+
usermod --home $runtime_dir yams-user
122+
cat /etc/passwd | grep $USER_NAME
123+
if [ ! -f $runtime_dir/.config/yams/yams.yml ]; then
124+
echo "Configuration file not found, generating ..."
125+
exec su - $USER_NAME -c "XDG_RUNTIME_DIR=$runtime_dir yams --generate-config"
126+
fi
127+
if [ -f $runtime_dir/.config/yams/yams.pid ]; then
85128
echo "Removing pid ..."
86-
rm /data/.config/yams/yams.pid
129+
rm $runtime_dir/.config/yams/yams.pid
87130
echo "Removed pid"
88131
fi
89-
echo "Executing [$CMD_LINE]..."
90-
su - $USER_NAME -c "$CMD_LINE"
132+
echo "Executing [$CMD_LINE] with runtime_dir=[$runtime_dir] ..."
133+
exec su - $USER_NAME -c "XDG_RUNTIME_DIR=$runtime_dir $CMD_LINE"
91134
else
92-
eval "$CMD_LINE"
135+
echo "This container must be run in user mode."
136+
exit 1
93137
fi

app/conf/sample.yams.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
allow_same_track_scrobble_in_a_row: false
2+
api_key: xxxx
3+
api_secret: xxxx
4+
base_url: http://ws.audioscrobbler.com/2.0/
5+
cache_file: /data/.cache/yams/scrobbles.cache
6+
disable_log: false
7+
log_file: /data/.local/state/yams/yams.log
8+
mpd_host: 127.0.0.1
9+
mpd_port: '6600'
10+
no_daemon: false
11+
pid_file: /data/yams.pid
12+
real_time: true
13+
scrobble_min_time: 10
14+
scrobble_threshold: 50
15+
session_file: /data/.local/state/yams/.lastfm_session
16+
update_interval: 1
17+
watch_threshold: 5

0 commit comments

Comments
 (0)