From 6aed53997023cda267a0ae86db4386a8df3f15e6 Mon Sep 17 00:00:00 2001 From: Corewala Date: Mon, 16 Nov 2020 19:47:36 -0500 Subject: [PATCH] Streamlined installation process and fixed python runtime error --- README.md | 4 +--- build.sh | 2 +- install.sh | 46 ++++++++++++++++++++++++++++++++++++++++++---- smother.py | 26 +++++++++++++------------- uninstall.sh | 7 ------- 5 files changed, 57 insertions(+), 28 deletions(-) delete mode 100644 uninstall.sh diff --git a/README.md b/README.md index ee5cf8b..3a51376 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,7 @@ sh build.sh ``` ## Install or uninstall Smother -This software comes with install and uninstall scripts. - - Run `install.sh` to install - - Run `uninstall.sh` to uninstall +Run `install.sh` to access installation options. ## Notice This software uses ufw, and will screw up your config. Do not use this software if you use ufw for anything else. \ No newline at end of file diff --git a/build.sh b/build.sh index af9a70b..ee4471a 100644 --- a/build.sh +++ b/build.sh @@ -1,5 +1,5 @@ mkdir build -nuitka3 ./smother.py -o build/smother +nuitka3 ./smother.py -o build/smother &> /dev/null echo '[Desktop Entry] Type=Application Name=Smother diff --git a/install.sh b/install.sh index ace7e4b..76a2cf2 100644 --- a/install.sh +++ b/install.sh @@ -1,4 +1,42 @@ -sudo systemctl enable ufw &> /dev/null -sudo ufw enable &> /dev/null -cp build/smother ~/.local/bin -cp build/Smother.desktop ~/.local/share/applications \ No newline at end of file +printf "Please select\n"; +printf "1: Install or update Smother\n"; +printf "2: Uninstall Smother\n"; +printf "> "; + +#Repeat only if the user hasn't entered an integer... +while ! [[ $selection =~ ^[1-2]+$ ]]; +do + read selection; + #if the entered value was not an integer, show this + if ! [[ $selection =~ ^[1-2]+$ ]]; then + sleep 1; + printf "$(tput setaf 9)Please try again$(tput sgr0)\n"; + printf "1: Install or update Smother\n"; + printf "2: Uninstall Smother\n"; + printf "> "; + fi +done + +case $selection in + 1) + sudo systemctl enable ufw &> /dev/null + sudo ufw enable &> /dev/null + cp build/smother ~/.local/bin + cp build/Smother.desktop ~/.local/share/applications + ;; + + 2) + #Uninstall + sudo /usr/bin/ufw --force reset &> /dev/null + sudo /usr/bin/ufw enable &> /dev/null + sudo /usr/bin/rm /etc/ufw/*.rules.* &> /dev/null + sudo /usr/bin/ufw default deny incoming &> /dev/null + sudo /usr/bin/ufw default allow outgoing &> /dev/null + rm ~/.local/bin/smother + rm ~/.local/share/applications/Smother.desktop + ;; + + *) + printf "[$(tput setaf 12 && tput blink)INFO$(tput sgr0)] $(tput setaf 12)Exiting script$(tput sgr0)\n"; + ;; +esac diff --git a/smother.py b/smother.py index 841df47..5aecec9 100644 --- a/smother.py +++ b/smother.py @@ -1,31 +1,31 @@ import gi import os -from gi.repository import gtk +from gi.repository import Gtk +gi.require_version('Gtk', '3.0') - -class Smother(gtk.Window): +class Smother(Gtk.Window): def __init__(self): - gtk.Window.__init__(self, title ="Smother") - gtk.Window.set_resizable(self, False); + Gtk.Window.__init__(self, title ="Smother") + Gtk.Window.set_resizable(self, False); self.set_border_width(10) - vbox = gtk.Box(orientation = gtk.Orientation.VERTICAL, spacing = 20) + vbox = Gtk.Box(orientation = Gtk.Orientation.VERTICAL, spacing = 20) self.add(vbox) - stack = gtk.Stack() - stack.set_transition_type(gtk.StackTransitionType.SLIDE_LEFT_RIGHT) + stack = Gtk.Stack() + stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT) stack.set_transition_duration(1000) - self.killbutton = gtk.Button(label ="Enable Killswitch") + self.killbutton = Gtk.Button(label ="Enable Killswitch") self.killbutton.connect("clicked", self.on_enable_clicked) stack.add_titled(self.killbutton, "kill", "Enable") - self.unkillbutton = gtk.Button(label ="Disable Killswitch") + self.unkillbutton = Gtk.Button(label ="Disable Killswitch") self.unkillbutton.connect("clicked", self.on_disable_clicked) stack.add_titled(self.unkillbutton, "unkill", "Disable") - stack_switcher = gtk.StackSwitcher() + stack_switcher = Gtk.StackSwitcher() stack_switcher.set_stack(stack) vbox.pack_start(stack_switcher, True, True, 0) vbox.pack_start(stack, True, True, 0) @@ -37,6 +37,6 @@ def on_disable_clicked(self, widget): os.system("gksu bash -c \'/usr/bin/ufw --force reset \n /usr/bin/ufw enable \n /usr/bin/rm /etc/ufw/*.rules.* \n /usr/bin/ufw default deny incoming \n /usr/bin/ufw default allow outgoing\'") win = Smother() -win.connect("destroy", gtk.main_quit) +win.connect("destroy", Gtk.main_quit) win.show_all() -gtk.main() \ No newline at end of file +Gtk.main() \ No newline at end of file diff --git a/uninstall.sh b/uninstall.sh deleted file mode 100644 index c66d885..0000000 --- a/uninstall.sh +++ /dev/null @@ -1,7 +0,0 @@ -sudo /usr/bin/ufw --force reset &> /dev/null -sudo /usr/bin/ufw enable &> /dev/null -sudo /usr/bin/rm /etc/ufw/*.rules.* &> /dev/null -sudo /usr/bin/ufw default deny incoming &> /dev/null -sudo /usr/bin/ufw default allow outgoing &> /dev/null -rm ~/.local/bin/smother -rm ~/.local/share/applications/Smother.desktop \ No newline at end of file