mirror of
https://github.com/kuhyx/scripts.git
synced 2026-07-04 15:23:11 +02:00
feat: fix stepmania and organize downloads scripts
This commit is contained in:
parent
6dbb73fe66
commit
3b71cf33ee
143
scripts/fixes/fix_stepmania.sh
Executable file
143
scripts/fixes/fix_stepmania.sh
Executable 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 "$@"
|
||||||
@ -10,10 +10,12 @@ set -euo pipefail
|
|||||||
# Defaults / flags
|
# Defaults / flags
|
||||||
DRY_RUN=false
|
DRY_RUN=false
|
||||||
SAMPLE_LIMIT=20
|
SAMPLE_LIMIT=20
|
||||||
|
# Size threshold for "too big" files (in bytes) - default 100MB
|
||||||
|
SIZE_THRESHOLD=$((100 * 1024 * 1024))
|
||||||
|
|
||||||
# Simple usage helper
|
# Simple usage helper
|
||||||
usage() {
|
usage() {
|
||||||
cat << EOF
|
cat <<EOF
|
||||||
Usage: $(basename "$0") [--dry-run|-n] [--sample=N]
|
Usage: $(basename "$0") [--dry-run|-n] [--sample=N]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
@ -26,6 +28,7 @@ EOF
|
|||||||
# Define directories to scan
|
# Define directories to scan
|
||||||
DOWNLOADS_DIR="$HOME/Downloads"
|
DOWNLOADS_DIR="$HOME/Downloads"
|
||||||
HOME_DIR="$HOME"
|
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
|
# Prefer a temp dir outside Downloads to avoid recursive re-inclusion; fall back to /tmp
|
||||||
TEMP_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/media_organize_$$"
|
TEMP_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/media_organize_$$"
|
||||||
|
|
||||||
@ -85,6 +88,59 @@ is_media_file() {
|
|||||||
return 1
|
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)
|
# Function to find media files in a directory (non-recursive for home, avoid common system dirs)
|
||||||
find_media_files() {
|
find_media_files() {
|
||||||
local search_dir="$1"
|
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"
|
".git" ".hg" ".svn" ".cache" "node_modules" "dist" "build" "out" "target" "coverage" "__pycache__" "venv" ".venv"
|
||||||
# previous staging dirs created by this script
|
# previous staging dirs created by this script
|
||||||
".media_organize_" "media_organize_"
|
".media_organize_" "media_organize_"
|
||||||
|
# too_big folder for oversized files
|
||||||
|
"too_big"
|
||||||
)
|
)
|
||||||
|
|
||||||
if [[ $search_dir == "$HOME_DIR" ]]; then
|
if [[ $search_dir == "$HOME_DIR" ]]; then
|
||||||
@ -108,7 +166,7 @@ find_media_files() {
|
|||||||
files+=("$file")
|
files+=("$file")
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done < <(find "$search_dir" -maxdepth 1 -type f -print0 2> /dev/null)
|
done < <(find "$search_dir" -maxdepth 1 -type f -print0 2>/dev/null)
|
||||||
else
|
else
|
||||||
# For Downloads, search recursively, pruning excluded directories
|
# For Downloads, search recursively, pruning excluded directories
|
||||||
# Build prune expression
|
# Build prune expression
|
||||||
@ -123,7 +181,7 @@ find_media_files() {
|
|||||||
if is_media_file "$file"; then
|
if is_media_file "$file"; then
|
||||||
files+=("$file")
|
files+=("$file")
|
||||||
fi
|
fi
|
||||||
done < <(find "$search_dir" \( -type d \( "${prune_expr[@]}" \) -prune \) -o -type f -print0 2> /dev/null)
|
done < <(find "$search_dir" \( -type d \( "${prune_expr[@]}" \) -prune \) -o -type f -print0 2>/dev/null)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf '%s\n' "${files[@]}"
|
printf '%s\n' "${files[@]}"
|
||||||
@ -145,7 +203,7 @@ create_media_archive() {
|
|||||||
local archive_path="$DOWNLOADS_DIR/$archive_name"
|
local archive_path="$DOWNLOADS_DIR/$archive_name"
|
||||||
|
|
||||||
# Create temporary directory (fallback to /tmp if needed)
|
# Create temporary directory (fallback to /tmp if needed)
|
||||||
if ! mkdir -p "$TEMP_DIR" 2> /dev/null; then
|
if ! mkdir -p "$TEMP_DIR" 2>/dev/null; then
|
||||||
TEMP_DIR="/tmp/media_organize_$$"
|
TEMP_DIR="/tmp/media_organize_$$"
|
||||||
mkdir -p "$TEMP_DIR"
|
mkdir -p "$TEMP_DIR"
|
||||||
fi
|
fi
|
||||||
@ -221,7 +279,7 @@ create_media_archive() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
local archive_size
|
local archive_size
|
||||||
archive_size=$(stat -c%s "$archive_path" 2> /dev/null || echo "0")
|
archive_size=$(stat -c%s "$archive_path" 2>/dev/null || echo "0")
|
||||||
if [[ $archive_size -eq 0 ]]; then
|
if [[ $archive_size -eq 0 ]]; then
|
||||||
log "ERROR: Archive file is empty"
|
log "ERROR: Archive file is empty"
|
||||||
rm -rf "$TEMP_DIR"
|
rm -rf "$TEMP_DIR"
|
||||||
@ -239,7 +297,7 @@ create_media_archive() {
|
|||||||
|
|
||||||
for file in "${successfully_copied[@]}"; do
|
for file in "${successfully_copied[@]}"; do
|
||||||
if [[ -f $file ]]; then
|
if [[ -f $file ]]; then
|
||||||
if rm "$file" 2> /dev/null; then
|
if rm "$file" 2>/dev/null; then
|
||||||
removed_count=$((removed_count + 1))
|
removed_count=$((removed_count + 1))
|
||||||
log "Removed: $(basename "$file")"
|
log "Removed: $(basename "$file")"
|
||||||
else
|
else
|
||||||
@ -294,7 +352,7 @@ main() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if zip command is available
|
# Check if zip command is available
|
||||||
if ! command -v zip > /dev/null 2>&1; then
|
if ! command -v zip >/dev/null 2>&1; then
|
||||||
log "ERROR: zip command not found. Please install zip package."
|
log "ERROR: zip command not found. Please install zip package."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@ -322,6 +380,17 @@ main() {
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
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
|
# Count by extension
|
||||||
declare -A ext_counts=()
|
declare -A ext_counts=()
|
||||||
# Count by top-level directory under Downloads
|
# Count by top-level directory under Downloads
|
||||||
@ -390,17 +459,51 @@ main() {
|
|||||||
echo ""
|
echo ""
|
||||||
fi
|
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.)"
|
echo "(Use: $(basename "$0") --dry-run --sample=50 to see more examples.)"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create archive if files found
|
# Separate files into regular and too-big categories
|
||||||
if [[ ${#all_files[@]} -gt 0 ]]; then
|
local regular_files=()
|
||||||
create_media_archive "${all_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."
|
log "Media organization completed successfully."
|
||||||
else
|
else
|
||||||
log "No media files found to organize."
|
log "No regular-sized media files found to archive."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user