-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlxc-rofi.sh
78 lines (65 loc) · 2.43 KB
/
lxc-rofi.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
# sudo yetkisi iste
echo "Lütfen sudo parolanızı girin:" | rofi -dmenu -password | sudo -S echo "Yetkilendirildi"
# LXC konteyner listesini al
output=$(sudo lxc-ls -f)
# Eğer konteyner yoksa bildirim göster ve çık
if [[ -z "$output" ]]; then
notify-send "LXC Hata" "Hiçbir konteyner bulunamadı!"
exit 1
fi
# İlk Rofi menüsünde konteyner listesini göster
while true; do
# Yenileme satırını da ekle
updated_output=$(echo -e "Yenile\n$(echo "$output")")
# Konteyner listesini göster
selection=$(echo "$updated_output" | rofi -dmenu -markup-rows -scroll-method 1 -p "Konteyner Seç" -wrap-mode 0)
# ESC tuşuna basılırsa uygulamadan çık
if [[ -z "$selection" ]]; then
exit 1
fi
# Eğer "Yenile" seçilirse konteyner listesini yeniden al
if [[ "$selection" == "Yenile" ]]; then
output=$(sudo lxc-ls -f)
continue
fi
# Seçimden sadece konteyner ismini al (ilk sütun)
container_name=$(echo "$selection" | awk '{print $1}')
# Seçilen konteynerin durumu
state=$(echo "$selection" | awk '{print $2}')
# Start / Stop seçeneklerini sun
while true; do
if [[ "$state" == "STOPPED" ]]; then
action=$(echo -e "Start\nEsc - Geri" | rofi -dmenu -p "İşlem Seç")
elif [[ "$state" == "RUNNING" ]]; then
action=$(echo -e "Stop\nEsc - Geri" | rofi -dmenu -p "İşlem Seç")
else
notify-send "Hata" "Bilinmeyen durum: $state"
exit 1
fi
# Eğer ESC tuşuna basılırsa, üst menüye dön
if [[ -z "$action" || "$action" == "Esc - Geri" ]]; then
break
fi
# Seçime göre işlemi gerçekleştir
case "$action" in
Start)
sudo lxc-start -n "$container_name"
notify-send "Konteyner Başlatıldı" "$container_name başarıyla başlatıldı!"
# Konteyner listesini güncelle
output=$(sudo lxc-ls -f)
break
;;
Stop)
sudo lxc-stop -n "$container_name"
notify-send "Konteyner Durduruldu" "$container_name başarıyla durduruldu!"
# Konteyner listesini güncelle
output=$(sudo lxc-ls -f)
break
;;
*)
notify-send "Hata" "Geçersiz seçim yapıldı!"
;;
esac
done
done