blob: 77e2386a96852834d2168241f37ab8531d646823 (
plain)
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
|
#!/usr/bin/env bash
set -euo pipefail
SHARE_DIR="/usr/share/mpv-anime-build"
CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/mpv"
PROG_NAME="$(basename "$0")"
show_help() {
cat <<HELP
MPV Anime Build - Helper Tool & Launcher
Usage:
$PROG_NAME [OPTIONS]
$PROG_NAME [MPV_ARGUMENTS...]
mpv-anime [MPV_ARGUMENTS...]
Options:
-i, --install Copy mpv-anime-build configs to $CONFIG_DIR
(existing configs are backed up automatically)
-l, --link Symlink mpv-anime-build configs to $CONFIG_DIR
(stays automatically updated with package upgrades)
-s, --status Check current mpv configuration status
-r, --restore Restore the most recent mpv config backup
-h, --help Show this help message
If launched as 'mpv-anime' or passed video files directly, it starts MPV
using the anime build profile.
HELP
}
check_status() {
echo "==> MPV Anime Build Status:"
echo " System share dir: $SHARE_DIR"
echo " User config dir: $CONFIG_DIR"
if [ -L "$CONFIG_DIR" ]; then
echo " Current state: SYMLINKED to $(readlink "$CONFIG_DIR")"
elif [ -f "$CONFIG_DIR/mpv.conf" ]; then
echo " Current state: Installed (custom / copied)"
elif [ -d "$CONFIG_DIR" ]; then
echo " Current state: Empty directory (not installed in user directory)"
else
echo " Current state: Not installed in user directory"
fi
BACKUPS=($(ls -d "${CONFIG_DIR}.backup."* 2>/dev/null || true))
if [ ${#BACKUPS[@]} -gt 0 ]; then
echo " Available backups:"
for b in "${BACKUPS[@]}"; do
echo " - $b"
done
fi
}
backup_existing() {
if [ -e "$CONFIG_DIR" ] || [ -L "$CONFIG_DIR" ]; then
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_TARGET="${CONFIG_DIR}.backup.${TIMESTAMP}"
echo "==> Backing up existing config to $BACKUP_TARGET..."
mv "$CONFIG_DIR" "$BACKUP_TARGET"
fi
}
install_config() {
backup_existing
echo "==> Copying mpv-anime-build configuration to $CONFIG_DIR..."
mkdir -p "$CONFIG_DIR"
cp -r "$SHARE_DIR"/* "$CONFIG_DIR/"
echo "==> Installation complete! You can now launch 'mpv' normally."
}
link_config() {
backup_existing
echo "==> Symlinking mpv-anime-build configuration to $CONFIG_DIR..."
mkdir -p "$(dirname "$CONFIG_DIR")"
ln -sf "$SHARE_DIR" "$CONFIG_DIR"
echo "==> Symlink created! Your MPV config will update automatically on package upgrades."
}
restore_config() {
LATEST_BACKUP=$(ls -d "${CONFIG_DIR}.backup."* 2>/dev/null | sort -r | head -n 1 || true)
if [ -z "$LATEST_BACKUP" ]; then
echo ":: Error: No backups found matching ${CONFIG_DIR}.backup.*"
exit 1
fi
echo "==> Restoring from $LATEST_BACKUP..."
rm -rf "$CONFIG_DIR"
mv "$LATEST_BACKUP" "$CONFIG_DIR"
echo "==> Restored successfully to $CONFIG_DIR."
}
case "${1:-}" in
-i|--install)
install_config
;;
-l|--link)
link_config
;;
-s|--status)
check_status
;;
-r|--restore)
restore_config
;;
-h|--help)
show_help
;;
*)
if [ "$PROG_NAME" = "mpv-anime" ] || [ $# -gt 0 ]; then
CONFIG_ARGS=()
if [ ! -L "$CONFIG_DIR" ] && [ ! -f "$CONFIG_DIR/mpv.conf" ]; then
CONFIG_ARGS=(--config-dir="$SHARE_DIR")
fi
if [ $# -eq 0 ]; then
exec mpv "${CONFIG_ARGS[@]}" --player-operation-mode=pseudo-gui
else
exec mpv "${CONFIG_ARGS[@]}" "$@"
fi
else
show_help
fi
;;
esac
|