WUT_Computer_Science/Programming/EOPSY/lab1/modify_examples.sh
Krzysztof kuhy Rudnicki 50263f075a Add pre-commit and fix everything it found
`pre-commit run --all-files` is green. The config only carries hooks whose
subject is already clean, so it stays green at every commit -- file-length,
ruff/mypy and dependency-freshness are listed as blocked, each on its own
cleanup, and the file-REWRITING hooks (trailing-whitespace, end-of-file-fixer)
are held back for their own reviewed commit.

Turning it on found four real things:

1. A committed private key: ERSMS-project/nginx/ssl/nginx.key. It is a
   self-signed CN=localhost cert that had already expired (notAfter
   2025-06-16), so the risk is nil -- but it is regenerable in one openssl
   call, so it is replaced by generate-cert.sh rather than excluded from the
   hook. The script says plainly that removing it from HEAD does NOT
   unpublish it: history is deliberately not rewritten, which is acceptable
   only because nothing ever trusted this key.

2. Four files with unresolved merge conflict markers committed, left over
   from the subtree merges. EARIN/.gitignore and .vscode/extensions.json are
   resolved as the union of both sides. The two Unity folder .meta files each
   had two candidate GUIDs; grepping showed neither is referenced anywhere
   (folder GUIDs rarely are), so either is safe and the HEAD side is kept --
   an arbitrary choice, but a checked one rather than a guess.

3. 62 shellcheck findings across 11 scripts, all fixed, no disables added.
   The interesting pattern was `cd X; cmd &; PID=$!; cd ..`, which trips both
   SC2164 and SC2103 and cannot use a plain subshell without losing the PID.
   `( cd X && exec cmd ) &` keeps the directory, the PID and the semantics.
   EOPSY lab1's submitted solution was verified by RUNNING it afterwards:
   a->A, B->b, foldera->FOLDERA, FOLDERB->folderb, exactly as before.

4. check-json failing on 11 files, which was the wrong parser rather than a
   defect -- tsconfig*.json and .vscode/*.json are JSONC, where TypeScript
   and VS Code both allow comments. Those two path classes are excluded and
   every other .json is still checked. Excluding them is what surfaced the
   merge conflict in (2) as the one genuine failure.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0172dj34FDpao6wsix8ZuCzE
2026-08-28 18:21:22 +02:00

75 lines
2.7 KiB
Bash
Executable File

#!/bin/bash
touch a
touch B
touch SED
mkdir foldera
mkdir FOLDERB
mkdir FOLDERSED
# Build the fixture tree with paths rather than cd/cd .., so a failed cd
# cannot silently create the next level in the wrong directory.
mkdir -p upperfoldermain/upperfoldersub
touch upperfoldermain/upperfilesub
touch upperfoldermain/upperfoldersub/upperfilesubsub
mkdir -p LOWERCASEFOLDERMAIN/LOWERFOLDERSUB
touch LOWERCASEFOLDERMAIN/LOWERFILESUB
touch LOWERCASEFOLDERMAIN/LOWERFOLDERSUB/LOWERFILESUBSUB
mkdir -p SEDLOWERCASEFOLDERMAIN/SEDLOWERFOLDERSUB
touch SEDLOWERCASEFOLDERMAIN/SEDLOWERFILESUB
touch SEDLOWERCASEFOLDERMAIN/SEDLOWERFOLDERSUB/SEDLOWERFILESUBSUB
touch recursefile
touch RECURSELOWERFILE
touch SEDRECURSEFILE
echo "Typical scenarios"
echo "Uppercasing file with filename a"
bash ./modify.sh -u a
echo "Lowercasing file with filename B"
bash ./modify.sh -l B
echo "Using sed pattern for lowercasing of file with filename SED"
bash ./modify.sh "-r -e s/.*/\L&/" SED
echo "Uppercasing folder with name foldera non recursively"
bash ./modify.sh -u foldera
echo "Lowercasing folder with name FOLDERB non recursively"
bash ./modify.sh -l FOLDERB
echo "Using sed pattern for lowercasing of folder with name FOLDERSED non recursively"
bash ./modify.sh "-l -e s/.*/\L&/" FOLDERSED
echo "Uppercasing folder recursively"
echo "Main folder name: upperfoldermain"
echo "folder contains: folder named upperfoldersub , file named upperfilesub"
echo "subfolder upperfoldersub contains file named upperfilesubsub"
bash ./modify.sh -r -u upperfoldermain
echo "Lowercasing folder recursively"
echo "Main folder name: LOWERFOLDERMAIN"
echo "folder contains: folder named LOWERFOLDERSUB , file named LOWERFILESUB"
echo "subfolder LOWERFOLDERSUB contains file named LOWERFILESUBSUB"
bash ./modify.sh -r -l SEDLOWERCASEFOLDERMAIN
echo "using sed pattern for Lowercasing folder recursively"
echo "Main folder name: SEDLOWERFOLDERMAIN"
echo "folder contains: folder named SEDLOWERFOLDERSUB , file named SEDLOWERFILESUB"
echo "subfolder SEDLOWERFOLDERSUB contains file named SEDLOWERFILESUBSUB"
bash ./modify.sh -r "-r -e s/.*/\L&/" SEDLOWERFOLDERMAIN
echo "Uncommon scenarios"
echo "uppercasing recursively normal file recursefile"
bash ./modify.sh -r -u recursefile
echo "lowercasing recursively normal file RECURSELOWERFILE"
bash ./modify.sh -r -l RECURSELOWERFILE
echo "using sed pattern recursively for normal file to lowercase it SEDRECURSEFILE"
bash ./modify.sh -r "-r -e s/.*/\L&/" SEDRECURSEFILE
echo "Incorrect scenarios"
echo "not providing enough arguments"
bash ./modify.sh
echo "not providing file"
bash ./modify.sh -l
echo "not providing argument for recursion"
bash ./modify.sh -r filename
echo "provding filename/foldername for file/folder which does not exist"
bash ./modify.sh -l thisfiledoesnotexist