romtal-sistem-dondurma/debian/tmp/bin/romtalsd
2025-03-29 23:00:00 +03:00

172 lines
6 KiB
Python
Executable file
Raw 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.

#!/usr/bin/env python3
import os
import subprocess
import sys
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk
def run_as_root(cmd_list):
"""
Verilen komut listesini pkexec ile root olarak çalıştırır.
"""
try:
subprocess.run(["pkexec"] + cmd_list, check=True)
except subprocess.CalledProcessError as e:
raise RuntimeError(f"Komut hatası: {e.cmd}, Çıkış kodu: {e.returncode}")
def get_mount_device(mount_point):
"""
/proc/mounts dosyasını okuyarak, verilen mount noktasının bağlı olduğu cihazı döner.
Args:
mount_point (str): İncelenecek mount noktası, örneğin "/media/root-ro".
Returns:
str veya None: Mount edilmiş aygıtın adı (örneğin, "/dev/sda1")
veya belirtilen mount noktası bulunamazsa None.
"""
try:
with open("/proc/mounts", "r") as f:
for line in f:
parts = line.split()
if parts[1] == mount_point:
return parts[0]
except Exception:
pass
return None
def overlay_status():
"""
/etc/overlayroot.conf dosyasını ve /media/root-rw mount noktasını kontrol eder:
- Eğer /media/root-rw mount edilmişse, overlay aktif kabul edilir.
- Aksi halde, /etc/overlayroot.conf dosyasını açar; içeriğinde "tmpfs" ifadesi varsa overlay aktif,
yoksa overlay pasif olarak belirlenir.
"""
# İlk olarak /media/root-rw mount edilip edilmediğini kontrol et
if get_mount_device("/media/root-rw"):
return True
# /etc/overlayroot.conf kontrolü
conf_path = "/etc/overlayroot.conf"
if os.path.exists(conf_path):
try:
with open(conf_path, "r") as f:
content = f.read()
return "tmpfs" in content
except Exception:
return False
else:
# Dosya yoksa paket kontrolü yapılabilir
try:
result = subprocess.run(["dpkg", "-l", "romtal-sistem-dondurma"], capture_output=True, text=True)
return "overlayroot" in result.stdout
except Exception:
return False
class OverlayrootGUI(Gtk.Window):
def __init__(self):
super().__init__(title="R.O.M.T.A.L Sistem Dondurma")
self.set_default_size(400, 250)
self.set_border_width(20)
# Stil ayarları
css = b"""
button {
font: 15px Arial;
padding: 10px;
margin: 5px;
}
"""
style_provider = Gtk.CssProvider()
style_provider.load_from_data(css)
Gtk.StyleContext.add_provider_for_screen(
Gdk.Screen.get_default(),
style_provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
)
self.overlay_enabled = overlay_status()
self.create_ui()
def create_ui(self):
grid = Gtk.Grid(column_spacing=10, row_spacing=10)
self.enable_btn = Gtk.Button(label="Sistem Dondurma Aktif Et")
self.disable_btn = Gtk.Button(label="Sistem Dondurma Devre Dışı Bırak")
self.enable_btn.connect("clicked", self.enable_overlayroot)
self.disable_btn.connect("clicked", self.disable_overlayroot)
self.status_label = Gtk.Label()
self.update_status()
# Footer label ekliyoruz
self.footer_label = Gtk.Label(label="Made By R.O.M.T.A.L | https://rasimoneltml.meb.k12.tr/")
grid.attach(self.status_label, 0, 0, 2, 1)
grid.attach(self.enable_btn, 0, 1, 1, 1)
grid.attach(self.disable_btn, 1, 1, 1, 1)
grid.attach(self.footer_label, 0, 2, 2, 1)
self.add(grid)
def update_status(self):
status_text = "Şuanki Durum: " + ("Aktif" if self.overlay_enabled else "Devre Dışı")
self.status_label.set_markup(f"<b>{status_text}</b>")
self.enable_btn.set_sensitive(not self.overlay_enabled)
self.disable_btn.set_sensitive(self.overlay_enabled)
def show_dialog(self, message, is_error=False):
dialog = Gtk.MessageDialog(
parent=self,
flags=0,
message_type=Gtk.MessageType.ERROR if is_error else Gtk.MessageType.INFO,
buttons=Gtk.ButtonsType.OK,
text=message
)
dialog.run()
dialog.destroy()
def enable_overlayroot(self, widget):
try:
cmd = [
"sh", "-c",
("rm -f /etc/overlayroot.conf && "
"echo 'overlayroot_cfgdisk=\"disable\"' > /etc/overlayroot.conf && "
"echo 'overlayroot=\"tmpfs\"' >> /etc/overlayroot.conf")
]
run_as_root(cmd)
self.overlay_enabled = True
self.update_status()
self.show_dialog("Overlayroot aktif edildi!\nDeğişikliklerin geçerli olması için yeniden başlatın.")
except Exception as e:
self.show_dialog(f"Hata oluştu: {str(e)}", is_error=True)
def disable_overlayroot(self, widget):
try:
device = get_mount_device("/media/root-ro")
if not device:
raise RuntimeError("'/media/root-ro' mount edilen cihaz bulunamadı.")
cmd = [
"sh", "-c",
(f"mount -o remount,rw {device} && "
"rm -f /media/root-ro/etc/overlayroot.conf && "
"echo 'overlayroot_cfgdisk=\"disable\"' > /media/root-ro/etc/overlayroot.conf && "
"echo 'overlayroot=\"\"' >> /media/root-ro/etc/overlayroot.conf")
]
run_as_root(cmd)
self.overlay_enabled = False
self.update_status()
self.show_dialog("Overlayroot devre dışı bırakıldı!\nDeğişikliklerin geçerli olması için yeniden başlatın.")
except Exception as e:
self.show_dialog(f"Hata oluştu: {str(e)}", is_error=True)
if __name__ == "__main__":
win = OverlayrootGUI()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()