adding bin & gitea

This commit is contained in:
2025-10-07 23:06:52 -05:00
parent ba010b3fbb
commit 3e1ac1c1c7
3 changed files with 211 additions and 0 deletions

77
bin/perms.sh Executable file
View File

@@ -0,0 +1,77 @@
#!/usr/bin/env bash
# Usage: fix-perms.sh [-o owner[:group]] <directory>
# Example: fix-perms.sh -o vaultwarden /srv/vaultwarden
# fix-perms.sh -o vaultwarden:vaultwarden /srv/vaultwarden
set -euo pipefail
# require root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root." >&2
exit 1
fi
OWNER=""
TARGET=""
# Parse arguments
while [[ $# -gt 0 ]]; do
case "$1" in
-o|--owner)
OWNER="$2"
shift 2
;;
-*)
echo "unknown option: $1"
exit 1
;;
*)
TARGET="$1"
shift
;;
esac
done
if [[ -z "$TARGET" ]]; then
echo "usage: $0 [-o owner[:group]] <directory>"
exit 1
fi
if [[ ! -d "$TARGET" ]]; then
echo "error: '$TARGET' is not a directory"
exit 1
fi
echo "======================================"
echo "Target directory: $TARGET"
if [[ -n "$OWNER" ]]; then
echo "Ownership change: $OWNER"
else
echo "Ownership change: (none)"
fi
echo "Directory perms: 2770 (setgid)"
echo "File perms: 660"
echo "======================================"
read -rp "Proceed with these changes? [y/N]: " CONFIRM
if [[ ! "$CONFIRM" =~ ^[Yy]$ ]]; then
echo "Aborted."
exit 0
fi
echo "setting permissions under: $TARGET"
# optionally change ownership
if [[ -n "$OWNER" ]]; then
echo "changing ownership to: $OWNER"
sudo chown -R "$OWNER" "$TARGET"
fi
# Set permissions for directories (with setgid)
find "$TARGET" -type d -exec chmod 2770 {} +
# Set permissions for files
find "$TARGET" -type f -exec chmod 660 {} +
echo "fin"

26
bin/rebuild.sh Executable file
View File

@@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -e
pushd ~/.nix
# nvim flake.nix
# alejandra . &>/dev/null
# git diff -U0 *.nix
# add generation comment to flake.nix
gen=$(nixos-rebuild list-generations | grep current)
if sed -n '3p' flake.nix | grep -q '^# generation:'; then
# replace the comment on line 3
sed -i "3s/^# generation:.*/# generation: $gen/" flake.nix
else
# insert comment on line 3
sed -i "3i# generation: $gen" flake.nix
fi
git diff -U0 $(find . -name '*.nix')
echo "nixos rebuilding..."
#sudo nixos-rebuild switch --flake ~/.nix#snowbelle &>.nixos-switch-log || (
# cat .nixos-switch-log | grep --color error && false)
sudo nixos-rebuild switch --flake ~/.nix#snowbelle 2>&1 | tee .nixos-switch-log | grep --color=always -E "error|$" && true
git commit -am "$gen"
popd