feat: fix stepmania and organize downloads scripts

This commit is contained in:
Krzysztof kuhy Rudnicki 2026-01-23 22:13:50 +01:00
parent 6dbb73fe66
commit 3b71cf33ee
2 changed files with 548 additions and 302 deletions

143
scripts/fixes/fix_stepmania.sh Executable file
View File

@ -0,0 +1,143 @@
#!/usr/bin/env bash
# Fix StepMania AUR build failure due to missing vorbis libraries in linker
#
# Error addressed:
# /usr/bin/ld: /usr/local/lib/libavcodec.a(libvorbisenc.o): undefined reference to symbol 'vorbis_encode_setup_vbr'
# /usr/bin/ld: /usr/lib/libvorbisenc.so.2: error adding symbols: DSO missing from command line
#
# Cause:
# Static libavcodec.a depends on libvorbisenc but cmake doesn't add it to linker flags
#
# Solution:
# Add vorbis libraries to LDFLAGS before building
#
# Usage:
# ./fix_stepmania.sh
set -euo pipefail
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
# shellcheck source=../lib/common.sh
source "$SCRIPT_DIR/../lib/common.sh"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
log_info() { echo -e "${BLUE}[INFO]${NC} $*"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
log_error() { echo -e "${RED}[ERROR]${NC} $*"; }
log_success() { echo -e "${GREEN}[OK]${NC} $*"; }
check_dependencies() {
log_info "Checking dependencies..."
local missing=()
# Check for vorbis libraries
if ! pacman -Q libvorbis &>/dev/null; then
missing+=("libvorbis")
fi
# Check for yay or paru
if ! has_cmd yay && ! has_cmd paru; then
log_error "Neither yay nor paru found. Please install an AUR helper."
exit 1
fi
if [[ ${#missing[@]} -gt 0 ]]; then
log_warn "Missing packages: ${missing[*]}"
log_info "Installing missing dependencies..."
sudo pacman -S --needed "${missing[@]}"
else
log_success "All dependencies present"
fi
}
get_aur_helper() {
if has_cmd yay; then
echo "yay"
elif has_cmd paru; then
echo "paru"
fi
}
build_stepmania() {
local aur_helper
aur_helper=$(get_aur_helper)
log_info "Building StepMania with vorbis libraries in LDFLAGS..."
log_info "Using AUR helper: $aur_helper"
# Export LDFLAGS with vorbis libraries to fix the linking issue
# The static libavcodec.a needs these shared libraries
export LDFLAGS="${LDFLAGS:-} -lvorbis -lvorbisenc -lvorbisfile -logg"
log_info "LDFLAGS set to: $LDFLAGS"
# Clean any previous failed build
if [[ -d "$HOME/.cache/$aur_helper/stepmania" ]]; then
log_info "Cleaning previous build cache..."
rm -rf "$HOME/.cache/$aur_helper/stepmania"
fi
# Build with the modified LDFLAGS
# --noconfirm for non-interactive, --cleanafter to cleanup
"$aur_helper" -S --rebuild --noconfirm stepmania
log_success "StepMania built successfully!"
}
alternative_fix_info() {
cat <<'EOF'
If the automated fix doesn't work, try these alternatives:
1. Use system ffmpeg instead of static libavcodec:
- Edit the PKGBUILD to use shared ffmpeg libraries
- Remove any bundled/static ffmpeg references
2. Manually edit CMakeLists.txt:
- Find target_link_libraries for StepMania executable
- Add: vorbis vorbisenc vorbisfile ogg
3. Check if /usr/local/lib/libavcodec.a is from a custom ffmpeg build:
- If so, rebuild ffmpeg with --enable-shared or remove the static lib
- System ffmpeg in /usr/lib should be preferred
4. Use the stepmania-git package instead which may have different build config
EOF
}
main() {
echo "======================================"
echo " StepMania Build Fix"
echo "======================================"
echo ""
check_dependencies
echo ""
log_info "This fix adds vorbis libraries to LDFLAGS to resolve:"
log_info " 'undefined reference to symbol vorbis_encode_setup_vbr'"
echo ""
read -rp "Proceed with rebuild? [Y/n] " response
case "$response" in
[nN][oO] | [nN])
log_info "Aborted."
alternative_fix_info
exit 0
;;
*)
build_stepmania
;;
esac
}
main "$@"

View File

@ -10,6 +10,8 @@ set -euo pipefail
# Defaults / flags
DRY_RUN=false
SAMPLE_LIMIT=20
# Size threshold for "too big" files (in bytes) - default 100MB
SIZE_THRESHOLD=$((100 * 1024 * 1024))
# Simple usage helper
usage() {
@ -26,6 +28,7 @@ EOF
# Define directories to scan
DOWNLOADS_DIR="$HOME/Downloads"
HOME_DIR="$HOME"
TOO_BIG_DIR="$DOWNLOADS_DIR/too_big"
# Prefer a temp dir outside Downloads to avoid recursive re-inclusion; fall back to /tmp
TEMP_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/media_organize_$$"
@ -85,6 +88,59 @@ is_media_file() {
return 1
}
# Function to check if file is too big for archiving
is_too_big() {
local file="$1"
local size
size=$(stat -c%s "$file" 2>/dev/null || echo "0")
[[ $size -gt $SIZE_THRESHOLD ]]
}
# Function to move oversized files to too_big directory
move_big_files() {
local files=("$@")
local moved_count=0
if [[ ${#files[@]} -eq 0 ]]; then
return 0
fi
# Create too_big directory if it doesn't exist
mkdir -p "$TOO_BIG_DIR"
log "Moving ${#files[@]} oversized files to $TOO_BIG_DIR..."
for file in "${files[@]}"; do
if [[ -f $file ]]; then
local basename
basename=$(basename "$file")
local dest="$TOO_BIG_DIR/$basename"
# Handle filename collision
if [[ -f $dest ]]; then
local timestamp
timestamp=$(date '+%Y%m%d_%H%M%S')
local name="${basename%.*}"
local ext="${basename##*.}"
if [[ $name == "$ext" ]]; then
dest="$TOO_BIG_DIR/${name}_${timestamp}"
else
dest="$TOO_BIG_DIR/${name}_${timestamp}.${ext}"
fi
fi
if mv "$file" "$dest" 2>/dev/null; then
log "Moved (too big): $(basename "$file") -> $dest"
moved_count=$((moved_count + 1))
else
log "ERROR: Failed to move $(basename "$file")"
fi
fi
done
log "Successfully moved $moved_count oversized files."
}
# Function to find media files in a directory (non-recursive for home, avoid common system dirs)
find_media_files() {
local search_dir="$1"
@ -94,6 +150,8 @@ find_media_files() {
".git" ".hg" ".svn" ".cache" "node_modules" "dist" "build" "out" "target" "coverage" "__pycache__" "venv" ".venv"
# previous staging dirs created by this script
".media_organize_" "media_organize_"
# too_big folder for oversized files
"too_big"
)
if [[ $search_dir == "$HOME_DIR" ]]; then
@ -322,6 +380,17 @@ main() {
exit 0
fi
# Separate big files for dry-run reporting
local dry_regular_files=()
local dry_big_files=()
for f in "${all_files[@]}"; do
if is_too_big "$f"; then
dry_big_files+=("$f")
else
dry_regular_files+=("$f")
fi
done
# Count by extension
declare -A ext_counts=()
# Count by top-level directory under Downloads
@ -390,17 +459,51 @@ main() {
echo ""
fi
echo "Total files that would be archived: ${#all_files[@]}"
echo "Files to archive (regular size): ${#dry_regular_files[@]}"
echo "Files to move to too_big folder: ${#dry_big_files[@]}"
if [[ ${#dry_big_files[@]} -gt 0 ]]; then
echo ""
echo "Oversized files (> $((SIZE_THRESHOLD / 1024 / 1024))MB) that would be moved to too_big/:"
for f in "${dry_big_files[@]}"; do
local size
size=$(du -h "$f" 2>/dev/null | cut -f1)
echo " [$size] $f"
done | head -n "$SAMPLE_LIMIT"
if [[ ${#dry_big_files[@]} -gt $SAMPLE_LIMIT ]]; then
echo " ... and $((${#dry_big_files[@]} - SAMPLE_LIMIT)) more"
fi
fi
echo ""
echo "Total files that would be organized: ${#all_files[@]}"
echo "(Use: $(basename "$0") --dry-run --sample=50 to see more examples.)"
exit 0
fi
# Create archive if files found
if [[ ${#all_files[@]} -gt 0 ]]; then
create_media_archive "${all_files[@]}"
# Separate files into regular and too-big categories
local regular_files=()
local big_files=()
for file in "${all_files[@]}"; do
if is_too_big "$file"; then
big_files+=("$file")
else
regular_files+=("$file")
fi
done
log "Found ${#regular_files[@]} regular files and ${#big_files[@]} oversized files."
# Move oversized files to too_big directory
if [[ ${#big_files[@]} -gt 0 ]]; then
move_big_files "${big_files[@]}"
fi
# Create archive for regular-sized files
if [[ ${#regular_files[@]} -gt 0 ]]; then
create_media_archive "${regular_files[@]}"
log "Media organization completed successfully."
else
log "No media files found to organize."
log "No regular-sized media files found to archive."
fi
}