Files
gentoo-pill/gentoo-sync.sh
2025-12-07 18:58:04 +06:00

49 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
PILL_REPO="$HOME/gentoo-pill"
HOSTNAME_TAG="${HOSTNAME:-$(hostname)}"
HOST_DIR="$PILL_REPO/hosts/$HOSTNAME_TAG"
echo "Syncing configuration for: $HOSTNAME_TAG"
if [[ -d "$PILL_REPO/.git" ]]; then
git -C "$PILL_REPO" pull --rebase --autostash
else
echo "Error: repo not found at $PILL_REPO"
exit 1
fi
mkdir -p "$HOST_DIR"
echo "Syncing World file component..."
cp /var/lib/portage/world "$HOST_DIR/world"
CONFIGS=(package.use package.accept_keywords package.license package.mask package.unmask package.env repos.conf)
echo "Syncing Portage components..."
for type in "${CONFIGS[@]}"; do
local_src="/etc/portage/$type"
repo_dest="$HOST_DIR/$type"
# rm -rf "$repo_dest"
if [[ -e "$local_src" ]]; then
rsync -a --delete --copy-links "$local_src" "$HOST_DIR/"
else
rm -rf "$repo_dest"
fi
done
echo "Pushing..."
cd "$PILL_REPO"
if [[ -n $(git status --porcelain) ]]; then
git add .
git commit -m "sync: $HOSTNAME_TAG $(date +'%Y-%m-%d %H:%M')"
git push
echo "Changes pushed successfully."
else
echo "No changes"
fi