diff --git a/autocompile.sh b/autocompile.sh new file mode 100644 index 0000000..f44f7c1 --- /dev/null +++ b/autocompile.sh @@ -0,0 +1,127 @@ +#!/bin/bash +TEX_DOSYASI="${1:-test.tex}" +PDF_DOSYASI="${TEX_DOSYASI%.tex}.pdf" +export DISPLAY=:0 + +# 1. OTOMATİK GÖNDERME (PUSH) FONKSİYONU +cleanup_and_push() { + echo -e '\n🛑 İzleme durduruldu.' + # Eğer bir Git deposunun içindeysek (örneğin nonmarkov klasörü), otomatik push yap + if git rev-parse --is-inside-work-tree > /dev/null 2>&1; then + echo "☁️ Değişiklikler Forgejo'ya gönderiliyor..." + # Hem kodu hem de PDF'i ekle ki arkadaşların site üzerinden PDF okuyabilsin + git add *.tex "$PDF_DOSYASI" 2>/dev/null + # O anki tarih ve saat ile otomatik commit mesajı oluştur + git commit -m "Oto-Kayıt: $(date '+%Y-%m-%d %H:%M:%S')" + if timeout 10 git push origin main; then + echo "✅ Kodlar ve PDF sunucuya başarıyla işlendi!" + else + echo "⚠️ Push başarısız — internet yok ya da firewall engelliyor." + echo " Değişiklikler yerelde commit edildi, bağlantı düzelince 'git push origin main' ile gönderebilirsin." + fi + fi + echo 'X11 arka planda sessizce bekliyor. Görüşmek üzere!' + exit 0 +} +# Ctrl+C'ye basıldığında doğrudan çıkmak yerine yukarıdaki fonksiyonu çalıştır +trap cleanup_and_push SIGINT + +# 2. OTOMATİK ÇEKME (PULL) - Sen yokken web'den veya arkadaştan gelenleri al +if git rev-parse --is-inside-work-tree > /dev/null 2>&1; then + echo "🔄 Sunucudaki son değişiklikler kontrol ediliyor (Auto-pull)..." + if ! timeout 10 git pull origin main; then + echo "⚠️ Sunucuya ulaşılamadı (internet/firewall sorunu olabilir). Yerel dosyalarla devam ediliyor..." + fi +fi + +# 3. Eski evince pencerelerini temizle +pkill -f evince 2>/dev/null + +# 4. X11 CHECK +if ! pgrep -f "termux-x11" > /dev/null; then + echo "🖥️ Starting X11..." + pkill -f fluxbox 2>/dev/null + termux-x11 :0 > /dev/null 2>&1 & + sleep 3 + if ! pgrep -f "termux-x11" > /dev/null; then + echo "❌ ERROR: X11 failed to start." + exit 1 + fi + echo "✅ X11 started." +else + echo "🔄 X11 is already active." +fi + +# 5. FLUXBOX CHECK +if ! pgrep -f "fluxbox" > /dev/null; then + echo "🪟 Starting window manager..." + fluxbox > /dev/null 2>&1 & + sleep 1 +fi + +# 6. TEMPLATE CREATOR +if [ ! -f "$TEX_DOSYASI" ]; then + echo "📄 '$TEX_DOSYASI' not found. Creating template..." + cat << 'TEMPLATE' > "$TEX_DOSYASI" +\documentclass{article} +\usepackage{amsmath} +\usepackage{physics} +\begin{document} +author:Demircan +\end{document} +TEMPLATE +fi + +# 7. INITIAL COMPILE +echo "⚙️ Compiling..." +pdflatex -interaction=nonstopmode "$TEX_DOSYASI" > compile_log.txt 2>&1 +if [ ! -f "$PDF_DOSYASI" ]; then + echo "❌ ERROR: LaTeX compilation crashed!" + grep -A 3 "^!" compile_log.txt + exit 1 +fi + +# 8. OPEN PDF AND MAXIMIZE +evince "$PWD/$PDF_DOSYASI" > /dev/null 2>&1 & +sleep 2 +if command -v wmctrl > /dev/null; then + wmctrl -r "evince" -b add,maximized_vert,maximized_horz +elif command -v xdotool > /dev/null; then + xdotool search --name "evince" windowsize --sync 100% 100% +fi + +# 9. TRIGGER ACODE +termux-open --content-type "text/x-tex" "$TEX_DOSYASI" + +echo "==============================================" +echo "👀 Watching: '$TEX_DOSYASI'" +echo "📂 Working Directory: $PWD" +echo "==============================================" + +# 10. WATCH LOOP (Aynı bıraktık) +while inotifywait -q -e close_write --include '.*\.tex$' -r .; do + echo "⏳ Saved. Compiling..." + pdflatex -interaction=nonstopmode "$TEX_DOSYASI" > compile_log.txt 2>&1 + if grep -q "^!" compile_log.txt; then + echo "⚠️ ERRORS IN CODE! (Evince is showing the last working PDF)" + python3 - << 'EOF' +import re +with open("compile_log.txt") as f: + lines = f.readlines() +i = 0 +while i < len(lines): + if lines[i].startswith("!"): + error = lines[i].strip() + lineno = "?" + for j in range(i+1, min(i+10, len(lines))): + m = re.match(r'^l\.(\d+)', lines[j]) + if m: + lineno = m.group(1) + break + print(f" Line {lineno:<6} {error}") + i += 1 +EOF + else + echo "✅ Updated." + fi +done \ No newline at end of file