diff --git a/src/disk.sh b/src/disk.sh index 47bedff..f35a53a 100644 --- a/src/disk.sh +++ b/src/disk.sh @@ -634,7 +634,6 @@ addDisk () { if [ -f "$DISK_FILE" ]; then if ! setOwner "$DISK_FILE"; then error "Failed to set the owner for \"$DISK_FILE\" !" - exit 77 fi fi diff --git a/src/network.sh b/src/network.sh index 4705bcc..4422b07 100644 --- a/src/network.sh +++ b/src/network.sh @@ -1495,23 +1495,26 @@ configureMAC() { container=$(containerID) if [ -z "$MAC" ]; then + file="$STORAGE/dsm.mac" - [ -s "$file" ] && MAC=$(<"$file") - MAC="${MAC//[![:print:]]/}" + + if [ -s "$file" ]; then + if ! MAC=$(readFile "$file"); then + error "Failed to read MAC address from \"$file\" !" + exit 28 + fi + fi if [ -z "$MAC" ]; then + # Generate a Synology-style MAC address based on a stable container identifier when possible. MAC=$(echo "$container" | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:11:32:\3:\4:\5/') - if ! echo "${MAC^^}" > "$file"; then + if ! writeFile "${MAC^^}" "$file"; then error "Failed to write MAC address to \"$file\" !" exit 28 fi - if ! setOwner "$file"; then - error "Failed to set the owner for \"$file\" !" - exit 28 - fi fi fi diff --git a/src/utils.sh b/src/utils.sh index 8bf06b4..8e4ac4e 100644 --- a/src/utils.sh +++ b/src/utils.sh @@ -248,14 +248,13 @@ writeFile() { local txt="$1" local path="$2" - if ! printf '%s\n' "$txt" >"$path"; then + if ! printf '%s\n' "$txt" > "$path"; then error "Failed to write file \"$path\" !" return 1 fi if ! setOwner "$path"; then - error "Failed to set the owner for \"$path\" !" - return 1 + warn "failed to set the owner for \"$path\"." fi return 0