-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
85 lines (62 loc) · 2.52 KB
/
install.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
77
78
79
80
81
82
83
84
#!/bin/bash
# This script installs and configures the MPDIgnore system.
# It sets up the necessary dependencies, copies the scripts to the appropriate directories,
# configures the systemd service and path units, and ensures everything is properly initialized.
# Define user and group variables
mpdignore_user="root"
mpdignore_group="root"
# User editable variables
MPDIGNORE_FILE=""
MPDIGNORE_PLAYLIST=""
mpdconf="/etc/mpd.conf"
installdir="/usr/local/sbin"
# Function to parse config.ini and retrieve the value of MPDIGNORE_PLAYLIST
parse_config_ini() {
awk -F '=' '/\[MPDIGNORE\]/{f=1} f && /MPDIGNORE_PLAYLIST/{print $2; exit}' "$HOME/.config/config.ini" | tr -d '[:space:]'
}
# Function to get PLDIR from mpd.conf
get_pldir() {
awk -F '=' '/\[MPD\]/{f=1} f && /PLDIR/{print $2; exit}' "$mpdconf" | tr -d '[:space:]'
}
# Function to create MPDIGNORE_FILE
create_mpdignore_file() {
touch "$MPDIGNORE_FILE"
}
# Update mpdignore.service
sed -i "s|/path/to/|$installdir|" mpdignore.service
# Update mpdignore.path
pldir=$(get_pldir)
sed -i "s|/path/to/|$pldir|" mpdignore.path
cp config.ini "$HOME/.config/"
cp ./ignore.sh ./skip.sh ./mpdignore.py ./ignore-skip.py "$installdir"
chown "$mpdignore_user:$mpdignore_group" "$installdir/ignore.sh" "$installdir/skip.sh" "$installdir/mpdignore.py" "$installdir/ignore-skip.py"
chmod +x "$installdir/ignore.sh" "$installdir/skip.sh" "$installdir/mpdignore.py" "$installdir/ignore-skip.py"
# Parse config.ini to get MPDIGNORE_PLAYLIST
MPDIGNORE_PLAYLIST=$(parse_config_ini)
if [[ -f "$mpdconf" ]]; then
# If mpd.conf exists in the specified location
found_conf="$mpdconf"
mpdpass="$(grep -v "^#" "$mpdconf" | grep -v "^$" | grep password | grep control | head -n 1)"
mpdpass="${mpdpass%*\"}"
mpdpass="${mpdpass#*\"}"
mpdpass="${mpdpass%\@*}"
fi
# Get PLDIR
pldir=$(get_pldir)
# Create MPDIGNORE_FILE path
MPDIGNORE_FILE="$pldir/$MPDIGNORE_PLAYLIST"
# Create MPDIGNORE_FILE
create_mpdignore_file
# Print MPDIGNORE_FILE path
echo "MPDIGNORE_FILE: $MPDIGNORE_FILE"
if [[ ! -L "$installdir/skip" ]]; then
ln -s "$installdir/skip.sh" "$installdir/skip"
fi
if [[ ! -L "$installdir/ignore" ]]; then
ln -s "$installdir/ignore.sh" "$installdir/ignore"
fi
sudo cp mpdignore.service /etc/systemd/system/
sudo cp mpdignore.path /etc/systemd/system/
sudo chown root:root /etc/systemd/system/mpdignore.path /etc/systemd/system/mpdignore.service
sudo systemctl daemon-reload
sudo systemctl enable mpdignore.path && sudo systemctl start mpdignore.path && sudo systemctl status mpdignore.path