-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
executable file
·106 lines (92 loc) · 3.11 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
# This script will install/upgrade/remove mpm (mpv-playlists-manager).
# version 2.2-3
# shellcheck disable=SC2154
red=$'\e[38;2;206;34;30m';
endColor=$'\e[0m';
_diffRc() {
# we execute this file as root so we need to provide the right username
# to give ownership back to the right user.
read -r -p ' Please enter your username: ' username
local CONF_DIR MPMRC usergroup
CONF_DIR="/home/$username/.config/mpm"
MPMRC="$CONF_DIR/mpmrc"
usergroup=$(
awk -F':' -v user="$username" '$0 ~ user { print $3":"$4 }' < /etc/passwd
)
if [[ -f $MPMRC ]]; then
diff -u "$MPMRC" doc/mpmrc > "$MPMRC".diff
patch -b "$MPMRC" < "$MPMRC".diff
printf '%s\n' " ${red}~/.config/mpm/mpmrc.diff created," \
" original file has been saved as mpmrc.orig.${endColor}"
printf '\n'
tail ./README_FIRST
printf '\n'
read -r -p " ${red}Edit $MPMRC now? [Y/n] enter editor name: ${endColor}" edit editor
case "$edit" in
Y|y)
cd "$CONF_DIR" && {
if [[ $editor == vim ]]; then
vim -d "$MPMRC" "$MPMRC".orig
else
"$editor" "$MPMRC" "$MPMRC".orig
fi
}
;;
n|N)
chown -R "$grpuser" "$CONF_DIR" && exit 0
;;
*)
printf '%s\n' \
" ${red}Ok don't forget to update it before first run.${endColor}"
;;
esac
else
mkdir --parents "$CONF_DIR"
cp doc/{mpmrc,themerc} "$CONF_DIR"
printf '%s\n' " ${red}~/.config/mpm/mpmrc created." \
" Please edit your mpmrc file before first run.${endColor}"
fi
chown -R "$usergroup" "$CONF_DIR"
}
_install() {
cp --verbose --force ./mpm /usr/local/bin
mkdir --verbose --parents /usr/local/lib/mpm && \
cp --verbose --recursive --force ./lib/* /usr/local/lib/mpm/
mkdir --verbose --parents /usr/local/share/doc/mpm && {
cp --verbose --force doc/* /usr/local/share/doc/mpm/
cp --verbose --force README.md /usr/local/share/doc/mpm
}
mkdir --verbose --parents /usr/share/licenses/mpm && \
cp --verbose --force ./LICENSE /usr/share/licenses/mpm/LICENSE
chmod 755 /usr/local/lib/mpm/*
chmod 755 /usr/local/bin/mpm
_diffRc
}
_uninstall() {
rm --verbose --recursive --force /usr/local/bin/mpm
rm --verbose --recursive --force /usr/local/lib/mpm
rm --verbose --recursive --force /usr/local/share/doc/mpm
rm --verbose --recursive --force /usr/share/licenses/mpm
}
date
printf '\n'
if [[ -x /usr/local/bin/mpm ]] && [[ -d /usr/local/lib/mpm ]]; then
read -rn 1 -p ' [R]emove or [U]pgrade mpm?: '
case "$REPLY" in
r|R)
_uninstall
printf '%s\n' "hope you liked it anyway..."
;;
u|U)
_uninstall
_install
printf '%s\n' "for usage run: mpm --help"
;;
*)
printf '%s\n' " Wrong option $REPLY, try again." && exit 1
;;
esac
else
_install
fi