Simple Bash script setup-environment.sh automates creating a starter folder layout with logs, configs, and scripts, adds sample content, and sets permissions. Includes idempotent directory creation and a fallback when tree is unavailable (e.g., Git Bash on Windows).
- Creates directories:
logs/,configs/,scripts/(skips if they already exist). - Creates files with starter content:
logs/system.log,configs/app.conf,scripts/backup.sh. - Ensures
configs/app.confis writable before rewriting on reruns, then sets permissions:logs/system.log->644configs/app.conf->444scripts/backup.sh->755
- Shows structure with
tree .or falls back tofind . -maxdepth 4 -print. - Lists permissions with
ls -lR ..
chmod +x setup-environment.sh
./setup-environment.sh- Full-screen run showing date/time:
screenshots/full-run.png(replace with your capture).
- A rerun showiwing the idempotency of the script and robust error handling :
screenshots/rerun.png
treenot found in Git Bash on Windows → added a check: usetree .when available, otherwise fall back tofind . -maxdepth 4 -print.- Re-running after setting
configs/app.confto read-only (444) caused “Permission denied” → addedchmod u+w configs/app.conf 2>/dev/null || truebefore rewriting so reruns succeed without breaking onset -e.