Skip to content

Commit

Permalink
Update yams (#22)
Browse files Browse the repository at this point in the history
- better user management
- add sample config file for future dev activities
  • Loading branch information
GioF71 authored Oct 7, 2024
1 parent 0378265 commit d2e42af
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 18 deletions.
16 changes: 9 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,17 @@ VOLUME /data

ENV STARTUP_DELAY_SEC ""

ENV MPD_HOST ""
ENV MPD_PORT ""
ENV MPD_HOST=""
ENV MPD_PORT=""

ENV USER_MODE ""
ENV PUID ""
ENV PGID ""
ENV USER_MODE=""
ENV PUID=""
ENV PGID=""

ENV API_KEY ""
ENV API_SECRET ""
ENV API_KEY=""
ENV API_SECRET=""

ENV SESSION_FILE=""

COPY app/bin/run-yams.sh /app/bin/run-yams.sh
RUN chmod 755 /app/bin/run-yams.sh
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ See the following table.

Date|Description
:---|:---
2024-10-07|Use exec so we can get rid of bash processes
2023-04-19|Routine build after updates to the upstream project
2023-03-09|Support for `API_KEY` and `API_SECRET` ([#13](https://github.com/GioF71/yams-docker/issues/13))
2023-03-04|Add apt proxy support ([#4](https://github.com/GioF71/yams-docker/issues/4))
Expand Down
66 changes: 55 additions & 11 deletions app/bin/run-yams.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,23 @@
DEFAULT_UID=1000
DEFAULT_GID=1000

DEFAULT_RUNTIME_DIR=/data
runtime_dir=$DEFAULT_RUNTIME_DIR

if [ ! -w "$runtime_dir" ]; then
echo "Runtime dir [$runtime_dir] is not writable, switching to /tmp ..."
runtime_dir=/tmp
fi

echo "Creating config directory [$runtime_dir/.config/yams] ..."
mkdir -p $runtime_dir/.config/yams
echo "Creating state directory [$runtime_dir/.local/state/yams] ..."
mkdir -p $runtime_dir/.local/state/yams
echo "Finished creating directories."

#CMD_LINE="XDG_RUNTIME_DIR=$runtime_dir yams --keep-alive --no-daemon"
CMD_LINE="yams --keep-alive --no-daemon"
echo "CMD_LINE=[$CMD_LINE]"

if [[ -n "${MPD_HOST}" ]]; then
CMD_LINE="$CMD_LINE -m $MPD_HOST"
Expand Down Expand Up @@ -40,6 +56,31 @@ if [[ -n "$STARTUP_DELAY_SEC" ]]; then
fi
fi

# add session file path?
use_custom_session_file=0
if [[ -n "${SESSION_FILE}" ]]; then
echo "SESSION_FILE=[$SESSION_FILE]"
if [ -f "$SESSION_FILE" ]; then
echo "SESSION_FILE [$SESSION_FILE] exists"
use_custom_session_file=1
CMD_LINE="$CMD_LINE --session-file-path $SESSION_FILE"
fi
fi

if [ $use_custom_session_file -eq 0 ]; then
echo "Creating directory for session file [$runtime_dir/.config/yams] ..."
mkdir -p $runtime_dir/.config/yams
echo "Setting default session file to [$runtime_dir/.config/yams/.lastfm_session] ..."
CMD_LINE="$CMD_LINE --session-file-path $runtime_dir/.config/yams/.lastfm_session"
fi

uid=$(id -u)
if [[ $uid -ne 0 ]]; then
echo "This container must be run as root."
exit 1
fi

echo "Running with uid=[$uid] ..."
# Create user and group
if [[ -n "{${PUID}" || -z "${USER_MODE}" || "${USER_MODE^^}" == "YES" ]]; then
echo "User mode enabled"
Expand Down Expand Up @@ -72,22 +113,25 @@ if [[ -n "{${PUID}" || -z "${USER_MODE}" || "${USER_MODE^^}" == "YES" ]]; then
echo "Created $USER_NAME (group: $GROUP_NAME)"
cat /etc/passwd|grep $USER_NAME
echo "Creating home directory ..."
mkdir -p /data
mkdir -p $runtime_dir
echo "Setting ownership ..."
chown -R yams-user:yams-group /app/log
chown -R yams-user:yams-group /data
chown -R yams-user:yams-group $runtime_dir
echo "Setting home directory ..."
usermod --home /data yams-user
cat /etc/passwd|grep $USER_NAME
# this should not be needed
CMD_LINE="$CMD_LINE --session-file-path /data/.config/yams/.lastfm_session"
if [ -f /data/.config/yams/yams.pid ]; then
usermod --home $runtime_dir yams-user
cat /etc/passwd | grep $USER_NAME
if [ ! -f $runtime_dir/.config/yams/yams.yml ]; then
echo "Configuration file not found, generating ..."
exec su - $USER_NAME -c "XDG_RUNTIME_DIR=$runtime_dir yams --generate-config"
fi
if [ -f $runtime_dir/.config/yams/yams.pid ]; then
echo "Removing pid ..."
rm /data/.config/yams/yams.pid
rm $runtime_dir/.config/yams/yams.pid
echo "Removed pid"
fi
echo "Executing [$CMD_LINE]..."
su - $USER_NAME -c "$CMD_LINE"
echo "Executing [$CMD_LINE] with runtime_dir=[$runtime_dir] ..."
exec su - $USER_NAME -c "XDG_RUNTIME_DIR=$runtime_dir $CMD_LINE"
else
eval "$CMD_LINE"
echo "This container must be run in user mode."
exit 1
fi
17 changes: 17 additions & 0 deletions app/conf/sample.yams.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
allow_same_track_scrobble_in_a_row: false
api_key: xxxx
api_secret: xxxx
base_url: http://ws.audioscrobbler.com/2.0/
cache_file: /data/.cache/yams/scrobbles.cache
disable_log: false
log_file: /data/.local/state/yams/yams.log
mpd_host: 127.0.0.1
mpd_port: '6600'
no_daemon: false
pid_file: /data/yams.pid
real_time: true
scrobble_min_time: 10
scrobble_threshold: 50
session_file: /data/.local/state/yams/.lastfm_session
update_interval: 1
watch_threshold: 5

0 comments on commit d2e42af

Please sign in to comment.