-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·99 lines (74 loc) · 1.95 KB
/
build.sh
File metadata and controls
executable file
·99 lines (74 loc) · 1.95 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
#!/bin/bash
# build.sh - Generate the typeout amalgamation from CPU and GPU scripts
set -e
TYPEOUT="typeout"
TYPEOUT_CPU="typeout-cpu.py"
TYPEOUT_GPU="typeout-gpu.py"
VERSION="${VERSION:-dev}"
echo "Building $TYPEOUT..."
cat > "$TYPEOUT" << 'HEADER'
#!/bin/bash
# typeout - Transcribe audio/video to text
# Amalgamation: contains both CPU and GPU versions, selects automatically
HEADER
echo "# Version $VERSION" >> "$TYPEOUT"
echo "# https://github.com/miku/typeout" >> "$TYPEOUT"
echo "" >> "$TYPEOUT"
cat >> "$TYPEOUT" << 'EOM'
set -o pipefail
# Check for uv
if ! command -v uv &>/dev/null; then
echo "error: uv is required but not installed" >&2
echo "install: cargo install uv # or: pip install uv" >&2
echo " https://docs.astral.sh/uv/" >&2
exit 1
fi
# Detect GPU
has_gpu() {
[[ -d /proc/driver/nvidia ]] && command -v nvidia-smi &>/dev/null
}
# Get cache directory for extracted scripts
get_script_dir() {
local base="${XDG_CACHE_HOME:-$HOME/.cache}/typeout"
mkdir -p "$base"
printf '%s' "$base"
}
# Extract and run the appropriate script
main() {
local script_dir
local script_file
local backend
script_dir=$(get_script_dir)
if has_gpu; then
backend="gpu"
script_file="$script_dir/typeout-gpu.py"
else
backend="cpu"
script_file="$script_dir/typeout-cpu.py"
fi
extract_"$backend"_script "$script_file"
export TYPEOUT_VERSION="__VERSION__"
exec uv run "$script_file" "$@"
}
# Extract CPU version of the script
extract_cpu_script() {
cat > "$1" << 'CPUSCRIPT'
EOM
cat "$TYPEOUT_CPU" >> "$TYPEOUT"
cat >> "$TYPEOUT" << 'FOOTER1'
CPUSCRIPT
}
# Extract GPU version of the script
extract_gpu_script() {
cat > "$1" << 'GPUSCRIPT'
FOOTER1
cat "$TYPEOUT_GPU" >> "$TYPEOUT"
cat >> "$TYPEOUT" << 'FOOTER2'
GPUSCRIPT
}
main "$@"
FOOTER2
# Stamp version into assembled output
sed -i -e "s/__VERSION__/$VERSION/g" "$TYPEOUT"
chmod +x "$TYPEOUT"
echo "Done: $TYPEOUT"