Skip to content

Commit 1090b28

Browse files
committed
Corrections to pipefail triggers in setup and build scripts
1 parent 797bacd commit 1090b28

2 files changed

Lines changed: 20 additions & 19 deletions

File tree

bin/musiclib_build.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ if [ -f "$SCRIPT_DIR/musiclib_utils.sh" ]; then
2222
fi
2323

2424
# Fallback configuration
25-
MUSICDB="${MUSICDB:-$(get_data_dir)/data/musiclib.dsv}"
25+
_DATA_DIR_FB="${XDG_DATA_HOME:-$HOME/.local/share}/musiclib"
26+
MUSICDB="${MUSICDB:-$(get_data_dir 2>/dev/null || echo "$_DATA_DIR_FB")/data/musiclib.dsv}"
2627
MUSIC_ROOT_DIR="${MUSIC_ROOT_DIR:-/mnt/music}"
27-
ERROR_LOG="${ERROR_LOG:-${LOGFILE:-$(get_data_dir)/logs/musiclib.log}}"
28+
ERROR_LOG="${ERROR_LOG:-${LOGFILE:-${_DATA_DIR_FB}/logs/musiclib.log}}"
29+
unset _DATA_DIR_FB
2830

2931
# Default settings
3032
MIN_DEPTH=1

bin/musiclib_init_config.sh

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ count_audio_files() {
140140
read_conf_key() {
141141
local key="$1"
142142
local file="$2"
143-
grep "^${key}=" "$file" 2>/dev/null | head -1 | cut -d'=' -f2- | tr -d '"'
143+
# '|| true' on grep: under 'set -o pipefail' a no-match (exit 1) would
144+
# otherwise propagate as the pipeline's exit status and abort the script.
145+
{ grep "^${key}=" "$file" 2>/dev/null || true; } | head -1 | cut -d'=' -f2- | tr -d '"'
144146
}
145147

146148
# Return the predominant K3b-supported format (mp3/ogg/flac) found in MUSIC_REPO.
@@ -544,7 +546,7 @@ print_step "1/3" "Locating music repository"
544546
# Note: EXISTING_MUSIC_REPO may already be pre-set from Audacious detection above;
545547
# musiclib config takes priority if present, otherwise the Audacious-detected value is kept.
546548
if [ -n "$EXISTING_CONFIG_FILE" ]; then
547-
_conf_repo=$(grep '^MUSIC_REPO=' "$EXISTING_CONFIG_FILE" 2>/dev/null | head -1 | cut -d'=' -f2- | tr -d '"')
549+
_conf_repo=$(read_conf_key MUSIC_REPO "$EXISTING_CONFIG_FILE")
548550
_conf_repo=$(eval echo "$_conf_repo" 2>/dev/null || echo "$_conf_repo")
549551
[ -n "$_conf_repo" ] && EXISTING_MUSIC_REPO="$_conf_repo"
550552
fi
@@ -607,7 +609,7 @@ print_step "2/3" "Configuring download directory"
607609
# Read existing setting
608610
EXISTING_DOWNLOAD_DIR=""
609611
if [ -n "$EXISTING_CONFIG_FILE" ]; then
610-
EXISTING_DOWNLOAD_DIR=$(grep '^NEW_DOWNLOAD_DIR=' "$EXISTING_CONFIG_FILE" 2>/dev/null | head -1 | cut -d'=' -f2- | tr -d '"')
612+
EXISTING_DOWNLOAD_DIR=$(read_conf_key NEW_DOWNLOAD_DIR "$EXISTING_CONFIG_FILE")
611613
EXISTING_DOWNLOAD_DIR=$(eval echo "$EXISTING_DOWNLOAD_DIR" 2>/dev/null || echo "$EXISTING_DOWNLOAD_DIR")
612614
fi
613615

@@ -657,7 +659,7 @@ DEVICE_ID=""
657659
# Read existing setting
658660
EXISTING_DEVICE_ID=""
659661
if [ -n "$EXISTING_CONFIG_FILE" ]; then
660-
EXISTING_DEVICE_ID=$(grep '^DEVICE_ID=' "$EXISTING_CONFIG_FILE" 2>/dev/null | head -1 | cut -d'=' -f2- | tr -d '"')
662+
EXISTING_DEVICE_ID=$(read_conf_key DEVICE_ID "$EXISTING_CONFIG_FILE")
661663
fi
662664

663665
if command -v kdeconnect-cli &>/dev/null; then
@@ -822,20 +824,17 @@ EOF
822824
# This runs once at install time; runtime drift is caught by sync_external_tool_config()
823825
# in musiclib_utils_tag_functions.sh on each subsequent script invocation.
824826
if command -v kid3-cli &>/dev/null; then
825-
# Read POPM_STAR values from system config; fall back to kid3 defaults
827+
# Read POPM_STAR values from system config; fall back to kid3 defaults.
828+
# Uses read_conf_key() (pipeline starts with 'head -1' so it never
829+
# triggers set -o pipefail when the key is absent).
826830
_sys_conf="/usr/lib/musiclib/config/musiclib.conf"
827831
_p1=1; _p2=64; _p3=128; _p4=196; _p5=255
828832
if [ -f "$_sys_conf" ]; then
829-
_v=$(grep -E '^POPM_STAR1=' "$_sys_conf" | cut -d= -f2 | tr -d '"' 2>/dev/null)
830-
[ -n "$_v" ] && _p1=$_v
831-
_v=$(grep -E '^POPM_STAR2=' "$_sys_conf" | cut -d= -f2 | tr -d '"' 2>/dev/null)
832-
[ -n "$_v" ] && _p2=$_v
833-
_v=$(grep -E '^POPM_STAR3=' "$_sys_conf" | cut -d= -f2 | tr -d '"' 2>/dev/null)
834-
[ -n "$_v" ] && _p3=$_v
835-
_v=$(grep -E '^POPM_STAR4=' "$_sys_conf" | cut -d= -f2 | tr -d '"' 2>/dev/null)
836-
[ -n "$_v" ] && _p4=$_v
837-
_v=$(grep -E '^POPM_STAR5=' "$_sys_conf" | cut -d= -f2 | tr -d '"' 2>/dev/null)
838-
[ -n "$_v" ] && _p5=$_v
833+
_v=$(read_conf_key POPM_STAR1 "$_sys_conf"); [ -n "$_v" ] && _p1=$_v || true
834+
_v=$(read_conf_key POPM_STAR2 "$_sys_conf"); [ -n "$_v" ] && _p2=$_v || true
835+
_v=$(read_conf_key POPM_STAR3 "$_sys_conf"); [ -n "$_v" ] && _p3=$_v || true
836+
_v=$(read_conf_key POPM_STAR4 "$_sys_conf"); [ -n "$_v" ] && _p4=$_v || true
837+
_v=$(read_conf_key POPM_STAR5 "$_sys_conf"); [ -n "$_v" ] && _p5=$_v || true
839838
fi
840839
# Point kid3-cli at the shared GUI config file (same as KID3_CONFIG_FILE in musiclib.conf)
841840
export KID3_CONFIG_FILE="$HOME/.config/kid3rc"
@@ -1039,13 +1038,13 @@ DB_FILE="${DATA_DIR}/data/musiclib.dsv"
10391038
if [ -f "$DB_FILE" ]; then
10401039
print_success "Database found"
10411040
else
1042-
echo "Looks like this is a first time install - no database found at: $MUSIC_REPO"
1041+
echo "Looks like this is a first time install - no database found at: $DB_FILE"
10431042
echo ""
10441043

10451044
if prompt_yn "Build it now?" "n"; then
10461045
echo ""
10471046
if command -v musiclib-cli &>/dev/null; then
1048-
musiclib-cli build || print_error "Database build failed"
1047+
musiclib-cli build "$MUSIC_REPO" || print_error "Database build failed"
10491048
else
10501049
print_error "musiclib-cli not found - install the musiclib package first"
10511050
print_info "When ready just run 'musiclib-cli build' in the terminal."

0 commit comments

Comments
 (0)