-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·182 lines (155 loc) · 4.19 KB
/
start.sh
File metadata and controls
executable file
·182 lines (155 loc) · 4.19 KB
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
#!/usr/bin/env bash
# CloudMusic TUI 启动脚本(支持 Fancy / ASCII 两种模式)
set -euo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
BOLD='\033[1m'
NC='\033[0m'
print_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[OK]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
print_error() {
echo -e "${RED}[ERR]${NC} $1"
}
print_header() {
echo -e "${BOLD}$1${NC}"
}
command_exists() {
command -v "$1" >/dev/null 2>&1
}
usage() {
cat <<'EOHELP'
CloudMusic 启动脚本
用法:
./start.sh 交互选择 Fancy / ASCII
./start.sh fancy 直接启动美观版 TUI
./start.sh ascii 直接启动纯 ASCII Retro CLI
./start.sh menu 显示模式菜单
./start.sh help 显示本帮助
EOHELP
}
choose_mode() {
local choice=""
echo
print_header "请选择要启动的界面"
echo " 1) Fancy TUI (美观版 / 默认)"
echo " 2) ASCII CLI (纯字符复古版)"
echo " 3) 退出"
echo
read -r -p "请输入选项 [1-3,默认 1]: " choice
case "${choice:-1}" in
1)
echo "fancy"
;;
2)
echo "ascii"
;;
3)
echo "quit"
;;
*)
print_warning "无效选项,已使用默认 Fancy 模式" >&2
echo "fancy"
;;
esac
}
resolve_mode() {
local raw="${1:-}"
case "${raw,,}" in
""|menu)
choose_mode
;;
fancy|pretty|themed)
echo "fancy"
;;
ascii|plain)
echo "ascii"
;;
help|-h|--help)
usage
exit 0
;;
*)
print_error "未知模式: $raw" >&2
usage
exit 1
;;
esac
}
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
RAW_MODE="${1:-}"
if [[ "${RAW_MODE,,}" == "help" || "${RAW_MODE,,}" == "-h" || "${RAW_MODE,,}" == "--help" ]]; then
usage
exit 0
fi
MODE="$(resolve_mode "$RAW_MODE")"
if [[ "$MODE" == "quit" ]]; then
print_info "已取消启动"
exit 0
fi
print_header "🎵 CloudMusic 启动器"
print_info "目标模式: $MODE"
REPO_MODE="false"
if [[ -f "$SCRIPT_DIR/run_tui.py" && -f "$SCRIPT_DIR/cli/musicctl.py" ]]; then
REPO_MODE="true"
fi
if [[ "$REPO_MODE" == "true" ]]; then
if [[ -x "$SCRIPT_DIR/.venv/bin/python" ]]; then
PYTHON_BIN="$SCRIPT_DIR/.venv/bin/python"
VENV_NAME=".venv"
elif [[ -x "$SCRIPT_DIR/venv/bin/python" ]]; then
PYTHON_BIN="$SCRIPT_DIR/venv/bin/python"
VENV_NAME="venv"
elif command_exists python3; then
PYTHON_BIN="python3"
VENV_NAME=""
elif command_exists python; then
PYTHON_BIN="python"
VENV_NAME=""
else
print_error "未找到 Python,请先安装 Python 3.10+"
exit 1
fi
print_success "Python: $($PYTHON_BIN --version 2>&1)"
if [[ -z "$VENV_NAME" ]]; then
print_warning "未发现项目虚拟环境,将使用系统 Python"
print_info "如需更稳妥,建议先执行: python3 -m venv .venv && .venv/bin/pip install -e ."
else
print_success "使用虚拟环境: $VENV_NAME"
fi
print_info "检查项目依赖..."
if ! "$PYTHON_BIN" -c 'import cloudmusic, requests' >/dev/null 2>&1; then
print_warning "依赖未就绪,正在安装项目..."
"$PYTHON_BIN" -m pip install -e . >/dev/null
fi
print_success "依赖检查完成"
if [[ "$MODE" == "ascii" ]]; then
print_info "启动 ASCII Retro CLI..."
exec "$PYTHON_BIN" cli/musicctl.py tui-full --retro
fi
print_info "启动 Fancy TUI..."
exec "$PYTHON_BIN" run_tui.py --fancy
fi
if [[ "$MODE" == "ascii" ]]; then
if command_exists cloudmusic-ascii; then
print_info "启动 ASCII Retro CLI..."
exec cloudmusic-ascii
fi
print_error "未找到 cloudmusic-ascii,请先安装 CloudMusic"
exit 1
fi
if command_exists cloudmusic; then
print_info "启动 Fancy TUI..."
exec cloudmusic --fancy
fi
print_error "未找到 cloudmusic,请先安装 CloudMusic"
exit 1