-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmk-mpdconf.sh
executable file
·79 lines (62 loc) · 1.42 KB
/
mk-mpdconf.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env bash
set -e
if [[ $MPD_HOST =~ @ ]] ; then
# if MPD_HOST is set and has a password, then re-use that
password=${MPD_HOST%@*}
else
password=$(pwgen 8 1)
fi
prog=$0
configfile=$HOME/.config/mpd/mpd.conf
ask() {
local answer=n
read -s -n 1 -p "==> $* [y/N]" answer
echo
[[ $answer =~ [Yy] ]]
}
msg() {
echo ":: $*"
}
::() {
echo ":: $*"
"$@" || exit 1
}
print_config(){
cat <<EOF
# generated by $prog on $(date)
music_directory "~/musik"
playlist_directory "~/.config/mpd/playlists"
db_file "~/.config/mpd/database"
log_file "~/.config/mpd/log"
pid_file "~/.config/mpd/pid"
state_file "~/.config/mpd/state"
sticker_file "~/.config/mpd/sticker.sql"
#log_level "verbose"
default_permissions "read"
password "$password@read,add,control,admin"
# export MPD_HOST="$password@localhost"
port "6600"
bind_to_address "127.0.0.1"
gapless_mp3_playback "yes"
restore_paused "yes"
audio_output {
type "pulse"
name "MPD"
# server "localhost"
# mixer_type "null"
}
EOF
}
config_content=$( print_config )
echo "---- >8 ----"
cat <<< "$config_content"
echo "---- >8 ----"
if ! ask "Write above config to $configfile?" ; then
exit 0
fi
:: mkdir -p "${configfile%/*}"
msg "Writing $configfile"
cat <<< "$config_content" > "$configfile"
if [[ -n "$DISPLAY" ]] && ask "Set MPD_HOST via herbstclient?" ; then
:: herbstclient setenv MPD_HOST "$password@localhost"
fi