Files
2026-07-09 02:59:53 +03:00

105 lines
2.9 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# lock.sh — Crate'i hcie-guard kullanıcısına vererek kilitler
# Kullanım: ./lock.sh hcie-blend
# ./lock.sh all
GROUP="ortak"
GUARD_USER="hcie-guard"
# Betik sudo altında çalışmalı; aksi halde hcie-guard dışındaki sahipleri değiştiremeyiz.
if [ "$EUID" -ne 0 ]; then
echo "⚠️ Bu betik root yetkisi gerektirir. Lütfen şunu çalıştırın:"
echo " sudo $0 $*"
exit 1
fi
# SCRIPT_DIR: Betiğin bulunduğu dizinin tam yolu
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
#BASE_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
BASE_DIR=$SCRIPT_DIR
echo $SCRIPT_DIR
echo $BASE_DIR
# Kilitlenecek crate'ler (all seçeneği için)
# Bu liste unlock.sh ile senkronize tutulmalıdır.
LOCKED_CRATES=(
"hcie-protocol"
"hcie-color"
"hcie-blend"
"hcie-history"
"hcie-brush-engine"
"hcie-draw"
"hcie-composite"
"hcie-filter"
"hcie-selection"
"hcie-text"
"hcie-vector"
"hcie-tile"
"hcie-io"
"hcie-document"
"hcie-engine-api"
"hcie-ai"
"hcie-vision"
"hcie-fx"
"hcie-psd"
"hcie-kra"
"hcie-native"
"hcie-egui-app"
"hcie-engine-api-orig"
"hcie-psd-saver"
"hcie-qt-app"
)
lock_crate() {
local crate="$1"
local path="$BASE_DIR/$crate"
if [ ! -d "$path" ]; then
echo "❌ Bulunamadı: $path"
return 1
fi
# Crate'in tamamını (tüm dosya ve dizinleri) kilitler.
# Dosyalara sadece okuma (444), dizinlere sadece okuma+gezinme (555) izni verilir.
# Böylece AI sadece açılan crate'lere müdahale edebilir.
sudo chown -R "$GUARD_USER:$GROUP" "$path"
sudo find "$path" -type f -exec chmod 444 {} \;
sudo find "$path" -type d -exec chmod 555 {} \;
sudo find "$path" -exec setfacl -b {} + 2>/dev/null || true
# Doğrulama: klasik izinler ve ACL'ler üzerinden yazma hakkı kalmış mı?
local writable
writable=$(find "$path" \( -type f -perm /u+w,g+w,o+w \) -o \( -type d -perm /u+w,g+w,o+w \) 2>/dev/null)
local acl_entries
acl_entries=$(find "$path" -type f -exec getfacl -c {} + 2>/dev/null | grep -E "^user:[^:]+:.*w" || true)
if [ -n "$writable" ] || [ -n "$acl_entries" ]; then
echo "⚠️ Uyarı: $crate içinde hâlâ yazma hakkı olan öğeler var:"
[ -n "$writable" ] && echo "$writable"
[ -n "$acl_entries" ] && echo "ACL yazma girdileri:" && echo "$acl_entries"
else
echo "🔒 Kilitlendi: $crate (tüm dosya/dizinler sadece okunabilir, ACL temiz)"
fi
}
if [ -z "$1" ]; then
echo "Kullanım: $0 <crate-adı> | all"
echo "Örnek: $0 hcie-blend"
echo " $0 all"
exit 1
fi
# hcie-guard kullanıcısı var mı kontrol et
if ! id "$GUARD_USER" &>/dev/null; then
echo "⚠️ '$GUARD_USER' kullanıcısı yok, oluşturuluyor..."
useradd -r -s /bin/false "$GUARD_USER"
echo "✅ '$GUARD_USER' oluşturuldu"
fi
if [ "$1" = "all" ]; then
echo "🔒 Tüm kilitli crate'ler kilitleniyor..."
for crate in "${LOCKED_CRATES[@]}"; do
lock_crate "$crate"
done
echo "✅ Tümü kilitlendi"
else
lock_crate "$1"
fi