Skip to content

Commit

Permalink
[Enhancement] Create and store random player mac address #247 (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
GioF71 authored Dec 18, 2023
1 parent a3aa0d9 commit 2d2e2dd
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ RUN chmod +x /app/bin/*.sh
VOLUME '/app/assets/additional-presets.conf'
VOLUME '/app/assets/binaries'

VOLUME '/config'

COPY README.md /app/doc/
COPY doc/* /app/doc/
COPY app/assets/builtin-presets.conf /app/assets/
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ SQUEEZELITE_PRIORITY|-p|Please refer to the squeezelite's man page for `-p`.
SQUEEZELITE_DELAY|-D|Set it to maybe something like `500,dop` if your DAC supports DoP. Defaults to `500`
SQUEEZELITE_NAME|-n|Name of the SqueezeLite player.
SQUEEZELITE_MODEL_NAME|-M|Name of the SqueezeLite model name.
SQUEEZELITE_MAC_ADDRESS|-m|Mac Address of the SqueezeLite player. The format must be colon-delimited hexadecimal, for example: `ab:cd:ef:12:34:56`.
SQUEEZELITE_MAC_ADDRESS|-m|Mac Address of the SqueezeLite player. The format must be colon-delimited hexadecimal, for example: `ab:cd:ef:12:34:56`. See note below.
SQUEEZELITE_TIMEOUT|-C|Device timeout in seconds, defaults to `2`
SQUEEZELITE_SERVER_PORT|-s|Server and port of the server, for example: `squeezebox-server.local:3483` or `192.168.1.10:3483`. Do not specify the variable if you want to use the auto discovery feature. If you don't specify this variable, you will probably need to use host network mode. See the examples for some hints. The port can be omitted if not different from the default `3483`. So other possible valid values are `squeezebox-server.local` or `192.168.1.10`.
SQUEEZELITE_RATES|-r|From squeezelite's man page for `-r`: Specify sample rates supported by the output device; this is required if the output device is switched off when squeezelite is started. The format is either a single maximum sample rate, a range of sample rates in the format `<min>-<max>`, or a comma-separated list of available rates. Delay is an optional time to wait when switching sample rates between tracks, in milliseconds. Switch back to the author of this repository: it is recommended to specify sample rates that are effectively supported by your audio device.
Expand All @@ -125,12 +125,18 @@ It is possible to add and additional preset configuration file using the volume

Possible values for variables `SQUEEZELITE_LOG_CATEGORY_*` are `info`, `debug` or `sdebug`.

### Automatic MAC address creation

If you don't provide a value to `SQUEEZELITE_MAC_ADDRESS`, a random mac address will be generated and stored (if possible) under `/config/mac-address.txt`, so it will be reloaded on next restart.
Use a persistent volume in order to preserve the functionality in the event of container recreation (such as when you update to a newer image).

## Volumes

Volume|Description
:---|:---
/app/assets/additional-presets.conf|Additional preset file
/app/assets/binaries|Custom binaries should be placed here
/config|Container configuration will be stored here

### Additional preset file

Expand Down
31 changes: 31 additions & 0 deletions app/bin/cmd-line-builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,35 @@ function cmdline-rates() {
echo "Variable SQUEEZELITE_RATES specified: ${SQUEEZELITE_RATES}"
CMD_LINE="$CMD_LINE -r "$(quote_if_needed "${SQUEEZELITE_RATES}")
fi
}

function handle_mac_address() {
if [[ -z "${SQUEEZELITE_MAC_ADDRESS}" ]]; then
echo "No mac address, specified, try loading ..."
if [ -f "/config/mac-address.txt" ]; then
echo "Found file with mac address ..."
mac=`cat /config/mac-address.txt`
echo "Mac address is ${mac}"
SQUEEZELITE_MAC_ADDRESS="${mac}"
else
echo "Mac address not found, generating ..."
for i in $(seq 1 6); do
portion=$[RANDOM%10]$[RANDOM%10]
if [ $i -eq 1 ]; then
mac="${portion}"
else
mac="${mac}:${portion}"
fi
done
echo "Generated mac address is [$mac]"
SQUEEZELITE_MAC_ADDRESS="${mac}"
# write if possible
if [ -w /config ]; then
echo "${mac}" > /config/mac-address.txt
echo "Written generated [${mac}] mac address."
else
echo "Config directory is not writable"
fi
fi
fi
}
18 changes: 15 additions & 3 deletions app/bin/run-squeezelite-alsa.sh
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ cmdline-server-port
cmdline-player-name
cmdline-model-name
cmdline-timeout
cmdline-mac-address
cmdline-audio-device
cmdline-mixer-device
cmdline-delay
Expand Down Expand Up @@ -244,8 +243,17 @@ USER_NAME=$DEFAULT_USER_NAME
GROUP_NAME=$DEFAULT_GROUP_NAME
HOME_DIR=$DEFAULT_HOME_DIR

current_user_id=$(id -u)
echo "Current user id is [$current_user_id], requested USER_MODE=[${USER_MODE}]"
actual_user_mode=0
if [[ $curret_user_id -eq 0 ]] && [[ "${USER_MODE^^}" == "YES" || "${USER_MODE^^}" == "Y" ]]; then
actual_user_mode=1
fi

echo "Resulting actual_user_mode: [$actual_user_mode]"

## User mode support
if [[ "${USER_MODE^^}" == "YES" || "${USER_MODE^^}" == "Y" ]]; then
if [[ $actual_user_mode -eq 1 ]]; then
USE_USER_MODE="Y"
echo "User mode enabled"
echo "Creating user ...";
Expand Down Expand Up @@ -303,9 +311,13 @@ else
echo "User mode disabled"
fi

handle_mac_address
cmdline-mac-address

echo "Command Line: ["$CMD_LINE"]"

if [[ ${USE_USER_MODE} == "Y" ]]; then
if [[ $actual_user_mode -eq 1 ]]; then
chown -R $USER_NAME:$GROUP_NAME /config
su - $USER_NAME -c "$CMD_LINE"
else
eval $CMD_LINE
Expand Down
12 changes: 11 additions & 1 deletion app/bin/run-squeezelite-pulse.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

echo "Running in pulse mode"

current_user_id=$(id -u)
echo "Current user id is [$current_user_id], requested USER_MODE=[${USER_MODE}]"
if [[ $current_user_id -ne 0 ]]; then
echo "Cannot run in Pulse Mode using docker user mode, you need to run as root and specify PUID/PGID"
exit 1
fi

DEFAULT_UID=1000
DEFAULT_GID=1000

Expand Down Expand Up @@ -87,7 +94,6 @@ cmdline-server-port
cmdline-player-name
cmdline-model-name
cmdline-timeout
cmdline-mac-address
cmdline-audio-device
cmdline-params
cmdline-codecs
Expand All @@ -108,7 +114,11 @@ source logging.sh

add_log_categories

handle_mac_address
cmdline-mac-address

echo "Command Line: ["$CMD_LINE"]"

chown -R $USER_NAME:$GROUP_NAME /config
su - $USER_NAME -c "$CMD_LINE"

1 change: 1 addition & 0 deletions doc/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Older build might be dropped in order to save space on docker-hub and incur in l

Date|Type|Description
:---|:---|:---
2023-12-18|Improvement|Autogen mac address (see [#247](https://github.com/GioF71/squeezelite-docker/issues/247))
2023-12-18|Improvement|Arguments in quotes (see [#245](https://github.com/GioF71/squeezelite-docker/issues/245))
2023-12-17|Improvement|Support output device `-o` also with PulseAudio (see [#243](https://github.com/GioF71/squeezelite-docker/issues/243))
2023-09-23|Improvement|Add presets (Topping D10s/D10 Balanced), updated Yulong D200 (see [#239](https://github.com/GioF71/squeezelite-docker/issues/239))
Expand Down

0 comments on commit 2d2e2dd

Please sign in to comment.