forked from lwilletts/mpvc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpvc-installer
executable file
·207 lines (181 loc) · 5.99 KB
/
mpvc-installer
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/usr/bin/env sh
#
# @file mpvc-installer
# @version v1.0
# @description mpvc installer
# @author gmt4 <gmt4 at github.com> (c) Copyright 2022 GPLv2+
# @url github.com/gmt4/mpvc
# SPDX-License-Identifier: GPL-2.0-or-later
#
PROGNAME=${0##*/}
PROGVERSION="v1.6"
PROGAUTHOR=gmt4
PROGURL="https://github.com/gmt4/mpvc"
set -euf
SHELL="${SHELL:-/bin/sh}"
PREFIX="${PREFIX:-/usr/local}"
BINDIR="${BINDIR:-$PREFIX/bin}"
DOCDIR="${DOCDIR:-$PREFIX/docs}"
LICDIR="${LICDIR:-$PREFIX/licenses}"
MPV_CONFDIR="${CONFIGDIR:-$HOME/.config/mpv}"
DOCS="README.md docs/mpv.conf docs/logbook.html"
LICENSES="LICENSE.md"
SCRIPT="mpvc extras/mpvc-tui extras/mpvc-fzf extras/mpvc-cut extras/mpvc-chapter extras/mpvc-mpris extras/mpvc-equalizer extras/mpvc-web extras/mpvc-autostart extras/mpvc-installer"
CONFIG="docs/mpv.conf"
mpvc_config()
{
mkdir -p "$MPV_CONFDIR/scripts/"
echo "Fetching mpv.conf from $PROGURL"
for config in ${CONFIG};
do
file="$MPV_CONFDIR/${config##*/}"
url="$PROGURL/raw/master/$config"
echo "Fetch $file"
if [ -e "$file" ]; then
echo "$PROGNAME: $file exists. Not overwriting."
else
curl -fsSL -o "$file" "$url"
fi
done
for bin in "yt-dlp"
do
file="$BINDIR/$bin"
echo "Fetch $file"
curl -fsSL -o "$file" "https://github.com/$bin/$bin/releases/latest/download/$bin"
chmod a+rx "$file"
done
}
mpvc_fetch()
{
mkdir -p "$BINDIR"
echo "Fetching mpvc from $PROGURL"
for script in $SCRIPT;
do
file="$BINDIR/${script##*/}"
url="$PROGURL/raw/master/$script"
echo "Fetch $file"
curl -fsSL -o "$file" "$url"
chmod u+x "$file"
done
}
mpvc_docs()
{
mkdir -p "$DOCDIR"
for doc in ${DOCS};
do
install -Dvm640 "$(pwd)/$doc" "$DOCDIR";
done
}
mpvc_licenses()
{
mkdir -p "$LICDIR"
for license in ${LICENSES};
do
install -Dvm644 "$(pwd)/$license" "$LICDIR";
done
}
mpvc_link()
{
mkdir -p "$BINDIR"
for script in $SCRIPT;
do
ln -svfn "$(pwd)/$script" "$BINDIR";
done
}
mpvc_install()
{
echo 'Installing mpvc...'
mkdir -p "$BINDIR"
for script in $SCRIPT;
do
install -Dvm755 "$(pwd)/$script" "$BINDIR";
done
}
mpvc_uninstall()
{
echo 'Un-installing mpvc...'
for script in $SCRIPT;
do
rm -v "$BINDIR/${script##*/}";
done
}
mpvc_check_requirements()
{
# attempt at listing packages required by mpvc & extras/ to work
command -v "sh" || echo "$PROGNAME: Error: No sh found. Install to continue"
command -v "mpv" || echo "$PROGNAME: Error: No mpv found. Install to continue"
command -v "fzf" || echo "$PROGNAME: Error: No fzf found, Install to continue"
command -v "awk" || echo "$PROGNAME: Error: No awk found, Install to continue" # gawk ???
command -v "sed" || echo "$PROGNAME: Error: No sed found, Install to continue" # gsed ???
command -v "socat" || echo "$PROGNAME: Error: No socat found, Install to continue"
# recommened, and good to have, but not required
command -v "curl" || echo "$PROGNAME: Warning: No curl found, Install to search streaming services"
command -v "rlwrap" || echo "$PROGNAME: Warning: No rlwrap, Install to get history, filename & completion support!"
command -v "notify-send" || echo "$PROGNAME: Warning: No notify-send, Install to get mpv desktop notifications"
command -v "jq" || echo "$PROGNAME: Warning: No jq found, Install to parse JSON"
command -v "yt-dlp" || echo "$PROGNAME: Warning: No yt-dlp, Install to get youtube-dl support (*hint: check $PROGNAME config)"
}
mpvc_check_update()
{
master=$(curl -fsSL "$PROGURL/raw/master/extras/$PROGNAME" |
awk '/^PROGVERSION=/ { gsub("PROGVERSION=",""); gsub("\\x22",""); print}'
)
if [ "$PROGVERSION" = "$master" ]
then
echo "$PROGNAME: Not-Found new version at $PROGURL (latest: $master)"
else
echo "$PROGNAME: Found new version at $PROGURL (latest: $master)"
fi
}
mpvc_version()
{
echo "usage: $PROGNAME args # @version $PROGVERSION (c) $PROGAUTHOR $PROGURL"
}
usage()
{
cat <<EOF
usage: $PROGNAME args # @version $PROGVERSION (c) $PROGAUTHOR $PROGURL
check-update : Check for updates
check-reqs : Check for required packages
config : Fetch mpv config
config-user : Fetch mpv config to BINDIR=$HOME/bin
config-sys : Fetch mpv config to BINDIR=$PREFIX/bin
fetch-user : Fetch to BINDIR=$HOME/bin
link-user : Symlink to BINDIR=$HOME/bin
install-user : Install to BINDIR=$HOME/bin
install-sys : Install to BINDIR=$PREFIX/bin
uninstall-sys : Uninstall from BINDIR=$PREFIX/bin
uninstall-user : Uninstall from BINDIR=$HOME/bin
*tips: If unsure where to start, start with: $PROGNAME fetch-user
EOF
exit
}
main()
{
if [ $# -lt 1 ]; then usage; fi
# hack to force SHELL back to posix-sh in macOS
case "$SHELL" in *'zsh') SHELL="/bin/sh";; esac
case "$1" in
version) shift; mpvc_version;;
check-reqs) shift; mpvc_check_requirements;;
check-update) shift; mpvc_check_update;;
docs) shift; mpvc_docs "$@";;
licenses) shift; mpvc_licenses "$@";;
fetch) shift; mpvc_fetch "$@";;
link) shift; mpvc_link "$@";;
install) shift; mpvc_install "$@";;
uninstall) shift; mpvc_uninstall "$@";;
config) shift; mpvc_config "$@";;
config-user) shift; PREFIX=$HOME $SHELL "$0" config;;
config-sys) shift; PREFIX=/usr/local $SHELL "$0" config;;
fetch-user) shift; PREFIX=$HOME $SHELL "$0" fetch;;
fetch-sys) shift; PREFIX=/usr/local $SHELL "$0" fetch;;
link-user) shift; PREFIX=$HOME $SHELL "$0" link;;
install-user) shift; PREFIX=$HOME $SHELL "$0" install;;
install-sys) shift; PREFIX=/usr/local $SHELL "$0" install;;
uninstall-user) shift; PREFIX=$HOME $SHELL "$0" uninstall;;
uninstall-sys) shift; PREFIX=/usr/local $SHELL "$0" uninstall;;
*) usage;;
esac
}
main "$@"