Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve mpv launching + make /stop work
- Loading branch information
1 parent
6f0dfad
commit 33e3132
Showing
4 changed files
with
218 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
#!/bin/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 | ||
# | ||
|
||
PROGNAME=${0##*/} | ||
PROGVERSION="v1.5" | ||
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-now 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 | ||
echo "Fetch $bin" | ||
curl -fsSL -o "$BINDIR/$bin" "https://github.com/$bin/$bin/releases/latest/download/$bin" | ||
chmod a+rx "$BINDIR/$bin" | ||
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 "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/mpvc-installer" | | ||
sed -n '/^PROGVERSION/ { s/"//g; s/PROGVERSION=//p }') | ||
|
||
if [ "$PROGVERSION" = "$master" ] | ||
then | ||
echo "$PROGNAME: Up-to-date, no new version > $PROGVERSION available at $PROGURL" | ||
else | ||
echo "$PROGNAME: Found new version $master available at $PROGURL" | ||
fi | ||
} | ||
|
||
usage() | ||
{ | ||
echo "usage: $PROGNAME args # @version $PROGVERSION (c) $PROGAUTHOR $PROGURL" | ||
echo " check-update : Check for updates" | ||
echo " check-reqs : Check for required packages" | ||
echo " config : Fetch mpv config" | ||
echo " fetch-user : Fetch to BINDIR=$HOME/bin" | ||
echo " link-user : Symlink to BINDIR=$HOME/bin" | ||
echo " install-user : Install to BINDIR=$HOME/bin" | ||
echo " install-sys : Install to BINDIR=$PREFIX/bin" | ||
echo " uninstall-sys : Uninstall from BINDIR=$PREFIX/bin" | ||
echo " uninstall-user : Uninstall from BINDIR=$HOME/bin}" | ||
echo "*tips: If unsure where to start, start with: $PROGNAME link-user" | ||
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 | ||
check-reqs) shift; mpvc_check_requirements;; | ||
check-update) shift; mpvc_check_update;; | ||
config) shift; mpvc_config "$@";; | ||
docs) shift; mpvc_docs "$@";; | ||
licenses) shift; mpvc_licenses "$@";; | ||
fetch) shift; mpvc_fetch "$@";; | ||
link) shift; mpvc_link "$@";; | ||
install) shift; mpvc_install "$@";; | ||
uninstall) shift; mpvc_uninstall "$@";; | ||
|
||
fetch-config) shift; PREFIX=$HOME $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 "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters