#!/usr/bin/env bash # Quick installer script for Computer Graphics Lab Programs # Usage: # curl -sL /all.sh | bash # or # wget -qO- /all.sh | bash set -e DIR="cg_lab" mkdir -p "$DIR" cd "$DIR" echo "==================================================" echo " Computer Graphics Lab Programs Downloader " echo "==================================================" echo "Downloading programs p1.c to p9.c into ./$DIR ..." SERVER="${1:-}" if [ -z "$SERVER" ]; then SERVER="." fi for i in 1 2 3 4 5 6 7 8 9; do echo " -> Downloading p${i}.c ..." if command -v curl >/dev/null 2>&1; then curl -sL "${SERVER}/p${i}" -o "p${i}.c" 2>/dev/null || curl -sL "${SERVER}/p${i}.c" -o "p${i}.c" elif command -v wget >/dev/null 2>&1; then wget -q "${SERVER}/p${i}" -O "p${i}.c" 2>/dev/null || wget -q "${SERVER}/p${i}.c" -O "p${i}.c" fi done cat << 'EOF' > build.sh #!/bin/bash if [ -z "$1" ]; then echo "Usage: ./build.sh " echo "Example: ./build.sh p1" exit 1 fi if [ "$1" = "all" ]; then for i in 1 2 3 4 5 6 7 8 9; do echo "Compiling p${i}.c..." gcc "p${i}.c" -lGL -lGLU -lglut -lm -o "p${i}" && echo " -> p${i} compiled successfully!" done else NAME="${1%.c}" echo "Compiling ${NAME}.c -> ${NAME} ..." gcc "${NAME}.c" -lGL -lGLU -lglut -lm -o "${NAME}" && echo "Done! Run with: ./${NAME}" fi EOF chmod +x build.sh echo "==================================================" echo "SUCCESS: All 9 programs downloaded into ./$DIR" echo "" echo "Ubuntu Prerequisites (run once if needed):" echo " sudo apt update && sudo apt install -y freeglut3-dev build-essential" echo "" echo "Compilation Examples:" echo " gcc p1.c -lGL -lGLU -lglut -lm -o p1 && ./p1" echo " ./build.sh p1" echo " ./build.sh all" echo "=================================================="