From 61512174660bf0769c994f0b8772da384f5bf9ec Mon Sep 17 00:00:00 2001 From: Patrizio Bruno Date: Tue, 5 Apr 2022 18:54:30 +0100 Subject: [PATCH] move config.ini and /models to /etc/howdy for better compatibility with immutable OSs --- howdy-gtk/src/tab_video.py | 2 +- howdy-gtk/src/window.py | 4 ++-- howdy/archlinux/howdy/.SRCINFO | 2 +- howdy/archlinux/howdy/PKGBUILD | 4 +++- howdy/debian/postinst | 6 +++--- howdy/debian/preinst | 8 +++++++- howdy/src/autocomplete/howdy | 2 +- howdy/src/cli/add.py | 10 ++++++---- howdy/src/cli/clear.py | 8 ++++---- howdy/src/cli/config.py | 3 ++- howdy/src/cli/disable.py | 2 +- howdy/src/cli/list.py | 2 +- howdy/src/cli/remove.py | 2 +- howdy/src/cli/set.py | 2 +- howdy/src/cli/snap.py | 5 ++--- howdy/src/cli/test.py | 2 +- howdy/src/compare.py | 4 ++-- howdy/src/pam.py | 2 +- howdy/src/pam/main.cc | 2 +- 19 files changed, 41 insertions(+), 31 deletions(-) diff --git a/howdy-gtk/src/tab_video.py b/howdy-gtk/src/tab_video.py index cd67740..d694fba 100644 --- a/howdy-gtk/src/tab_video.py +++ b/howdy-gtk/src/tab_video.py @@ -17,7 +17,7 @@ def on_page_switch(self, notebook, page, page_num): try: self.config = configparser.ConfigParser() - self.config.read("/lib/security/howdy/config.ini") + self.config.read("/etc/howdy/config.ini") except Exception: print(_("Can't open camera")) diff --git a/howdy-gtk/src/window.py b/howdy-gtk/src/window.py index 1bd58ff..125f44e 100644 --- a/howdy-gtk/src/window.py +++ b/howdy-gtk/src/window.py @@ -49,7 +49,7 @@ class MainWindow(gtk.Window): # Add the treeview self.modellistbox.add(self.treeview) - filelist = os.listdir("/lib/security/howdy/models") + filelist = os.listdir("/etc/howdy/models") self.active_user = "" self.userlist.items = 0 @@ -117,7 +117,7 @@ signal.signal(signal.SIGINT, signal.SIG_DFL) elevate.elevate() # If no models have been created yet or when it is forced, start the onboarding -if "--force-onboarding" in sys.argv or not os.path.exists("/lib/security/howdy/models"): +if "--force-onboarding" in sys.argv or not os.path.exists("/etc/howdy/models"): import onboarding onboarding.OnboardingWindow() diff --git a/howdy/archlinux/howdy/.SRCINFO b/howdy/archlinux/howdy/.SRCINFO index cf7022d..28479d0 100644 --- a/howdy/archlinux/howdy/.SRCINFO +++ b/howdy/archlinux/howdy/.SRCINFO @@ -13,7 +13,7 @@ pkgbase = howdy depends = python3 depends = python-dlib depends = python-numpy - backup = usr/lib/security/howdy/config.ini + backup = etc/howdy/config.ini source = howdy-2.6.1.tar.gz::https://github.com/boltgolt/howdy/archive/v2.6.1.tar.gz source = https://github.com/davisking/dlib-models/raw/master/dlib_face_recognition_resnet_model_v1.dat.bz2 source = https://github.com/davisking/dlib-models/raw/master/mmod_human_face_detector.dat.bz2 diff --git a/howdy/archlinux/howdy/PKGBUILD b/howdy/archlinux/howdy/PKGBUILD index 1740ccb..4c5d32a 100644 --- a/howdy/archlinux/howdy/PKGBUILD +++ b/howdy/archlinux/howdy/PKGBUILD @@ -22,7 +22,7 @@ makedepends=( 'cmake' 'pkgfile' ) -backup=('usr/lib/security/howdy/config.ini') +backup=('etc/howdy/config.ini') source=( "$pkgname-$pkgver.tar.gz::https://github.com/boltgolt/howdy/archive/v${pkgver}.tar.gz" "https://github.com/davisking/dlib-models/raw/master/dlib_face_recognition_resnet_model_v1.dat.bz2" @@ -39,7 +39,9 @@ package() { cd howdy-$pkgver install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE" mkdir -p "$pkgdir/usr/lib/security/howdy" + mkdir -p "$pkgdir/etc/howdy" cp -r src/* "$pkgdir/usr/lib/security/howdy" + cp -r src/config.ini "$pkgdir/etc/howdy" cp "${srcdir}/dlib_face_recognition_resnet_model_v1.dat" "$pkgdir/usr/lib/security/howdy/dlib-data/" cp "${srcdir}/mmod_human_face_detector.dat" "$pkgdir/usr/lib/security/howdy/dlib-data/" cp "${srcdir}/shape_predictor_5_face_landmarks.dat" "$pkgdir/usr/lib/security/howdy/dlib-data/" diff --git a/howdy/debian/postinst b/howdy/debian/postinst index 0a31c74..1cf7ab0 100755 --- a/howdy/debian/postinst +++ b/howdy/debian/postinst @@ -52,7 +52,7 @@ if not os.path.exists("/tmp/howdy_picked_device"): oldConf = configparser.ConfigParser() oldConf.read("/tmp/howdy_config_backup_v" + sys.argv[2] + ".ini") newConf = configparser.ConfigParser() - newConf.read("/lib/security/howdy/config.ini") + newConf.read("/etc/howdy/config.ini") # Go through every setting in the old config and apply it to the new file for section in oldConf.sections(): @@ -98,7 +98,7 @@ if not os.path.exists("/tmp/howdy_picked_device"): newConf.set(section, key, value) # Write it all to file - with open("/lib/security/howdy/config.ini", "w") as configfile: + with open("/etc/howdy/config.ini", "w") as configfile: newConf.write(configfile) # Install dlib data files if needed @@ -200,7 +200,7 @@ handleStatus(subprocess.call(["pip3", "install", "--no-cache-dir", "opencv-pytho log("Configuring howdy") # Manually change the camera id to the one picked -for line in fileinput.input(["/lib/security/howdy/config.ini"], inplace=1): +for line in fileinput.input(["/etc/howdy/config.ini"], inplace=1): line = line.replace("use_cnn = false", "use_cnn = " + str(cuda_used).lower()) print(line, end="") diff --git a/howdy/debian/preinst b/howdy/debian/preinst index 329438c..a01628b 100755 --- a/howdy/debian/preinst +++ b/howdy/debian/preinst @@ -14,7 +14,13 @@ if "upgrade" in sys.argv: # Let the user know so he knows where to look on a failed install print("Backup of Howdy config file created in /tmp/howdy_config_backup_v" + sys.argv[2] + ".ini") except subprocess.CalledProcessError: - print("Could not make an backup of old Howdy config file") + try: + subprocess.call(["cp /etc/howdy/config.ini /tmp/howdy_config_backup_v" + sys.argv[2] + ".ini"], shell=True) + + # Let the user know so he knows where to look on a failed install + print("Backup of Howdy config file created in /tmp/howdy_config_backup_v" + sys.argv[2] + ".ini") + except subprocess.CalledProcessError: + print("Could not make an backup of old Howdy config file") # Don't continue setup when we're just upgrading sys.exit(0) diff --git a/howdy/src/autocomplete/howdy b/howdy/src/autocomplete/howdy index d633f22..fcfceb8 100755 --- a/howdy/src/autocomplete/howdy +++ b/howdy/src/autocomplete/howdy @@ -20,7 +20,7 @@ _howdy() { ;; # For disable, grab the current "disabled" config option and give the reverse "disable") - local status=$(cut -d'=' -f2 <<< $(cat /lib/security/howdy/config.ini | grep 'disabled =') | xargs echo -n) + local status=$(cut -d'=' -f2 <<< $(cat /etc/howdy/config.ini | grep 'disabled =') | xargs echo -n) [ "$status" == "false" ] && COMPREPLY="true" || COMPREPLY="false" return 0 diff --git a/howdy/src/cli/add.py b/howdy/src/cli/add.py index 1cab2e9..3dcd9ff 100644 --- a/howdy/src/cli/add.py +++ b/howdy/src/cli/add.py @@ -28,6 +28,8 @@ import cv2 # Get the absolute path to the current directory path = os.path.abspath(__file__ + "/..") +config_path = "/etc/howdy" +models_path = "/etc/howdy/models" # Test if at lest 1 of the data files is there and abort if it's not if not os.path.isfile(path + "/../dlib-data/shape_predictor_5_face_landmarks.dat"): @@ -38,7 +40,7 @@ if not os.path.isfile(path + "/../dlib-data/shape_predictor_5_face_landmarks.dat # Read config from disk config = configparser.ConfigParser() -config.read(path + "/../config.ini") +config.read(config_path + "/config.ini") use_cnn = config.getboolean("core", "use_cnn", fallback=False) if use_cnn: @@ -51,14 +53,14 @@ face_encoder = dlib.face_recognition_model_v1(path + "/../dlib-data/dlib_face_re user = builtins.howdy_user # The permanent file to store the encoded model in -enc_file = path + "/../models/" + user + ".dat" +enc_file = models_path + "/" + user + ".dat" # Known encodings encodings = [] # Make the ./models folder if it doesn't already exist -if not os.path.exists(path + "/../models"): +if not os.path.exists(models_path): print(_("No face model folder found, creating one")) - os.makedirs(path + "/../models") + os.makedirs(models_path) # To try read a premade encodings file if it exists try: diff --git a/howdy/src/cli/clear.py b/howdy/src/cli/clear.py index 22b6579..686e84a 100644 --- a/howdy/src/cli/clear.py +++ b/howdy/src/cli/clear.py @@ -8,17 +8,17 @@ import builtins from i18n import _ # Get the full path to this file -path = os.path.dirname(os.path.abspath(__file__)) +path = "/etc/howdy/models" # Get the passed user user = builtins.howdy_user # Check if the models folder is there -if not os.path.exists(path + "/../models"): +if not os.path.exists(path): print(_("No models created yet, can't clear them if they don't exist")) sys.exit(1) # Check if the user has a models file to delete -if not os.path.isfile(path + "/../models/" + user + ".dat"): +if not os.path.isfile(path + "/" + user + ".dat"): print(_("{} has no models or they have been cleared already").format(user)) sys.exit(1) @@ -34,5 +34,5 @@ if not builtins.howdy_args.y: sys.exit(1) # Delete otherwise -os.remove(path + "/../models/" + user + ".dat") +os.remove(path + "/" + user + ".dat") print(_("\nModels cleared")) diff --git a/howdy/src/cli/config.py b/howdy/src/cli/config.py index e2b0b0f..1582e8c 100644 --- a/howdy/src/cli/config.py +++ b/howdy/src/cli/config.py @@ -18,5 +18,6 @@ if "EDITOR" in os.environ: elif os.path.isfile("/etc/alternatives/editor"): editor = "/etc/alternatives/editor" +config_path = "/etc/howdy" # Open the editor as a subprocess and fork it -subprocess.call([editor, os.path.dirname(os.path.realpath(__file__)) + "/../config.ini"]) +subprocess.call([editor, os.path.dirname(config_path) + "/config.ini"]) diff --git a/howdy/src/cli/disable.py b/howdy/src/cli/disable.py index 485fe1a..1600d52 100644 --- a/howdy/src/cli/disable.py +++ b/howdy/src/cli/disable.py @@ -10,7 +10,7 @@ import configparser from i18n import _ # Get the absolute filepath -config_path = os.path.dirname(os.path.abspath(__file__)) + "/../config.ini" +config_path = os.path.dirname("/etc/howdy") + "/config.ini" # Read config from disk config = configparser.ConfigParser() diff --git a/howdy/src/cli/list.py b/howdy/src/cli/list.py index a098498..ab26c4d 100644 --- a/howdy/src/cli/list.py +++ b/howdy/src/cli/list.py @@ -10,7 +10,7 @@ import builtins from i18n import _ # Get the absolute path and the username -path = os.path.dirname(os.path.realpath(__file__)) + "/.." +path = "/etc/howdy" user = builtins.howdy_user # Check if the models file has been created yet diff --git a/howdy/src/cli/remove.py b/howdy/src/cli/remove.py index f9c29a4..6321e0b 100644 --- a/howdy/src/cli/remove.py +++ b/howdy/src/cli/remove.py @@ -9,7 +9,7 @@ import builtins from i18n import _ # Get the absolute path and the username -path = os.path.dirname(os.path.realpath(__file__)) + "/.." +path = "/etc/howdy" user = builtins.howdy_user # Check if enough arguments have been passed diff --git a/howdy/src/cli/set.py b/howdy/src/cli/set.py index 72c5c8e..14d15c2 100644 --- a/howdy/src/cli/set.py +++ b/howdy/src/cli/set.py @@ -9,7 +9,7 @@ import fileinput from i18n import _ # Get the absolute filepath -config_path = os.path.dirname(os.path.abspath(__file__)) + "/../config.ini" +config_path = os.path.dirname("/etc/howdy") + "/config.ini" # Check if enough arguments have been passed if len(builtins.howdy_args.arguments) < 2: diff --git a/howdy/src/cli/snap.py b/howdy/src/cli/snap.py index 8dbc49a..9db2281 100644 --- a/howdy/src/cli/snap.py +++ b/howdy/src/cli/snap.py @@ -9,12 +9,11 @@ from recorders.video_capture import VideoCapture from i18n import _ -# Get the absolute path to the current directory -path = os.path.abspath(__file__ + "/..") +path = "/etc/howdy" # Read the config config = configparser.ConfigParser() -config.read(path + "/../config.ini") +config.read(path + "/config.ini") # Start video capture video_capture = VideoCapture(config) diff --git a/howdy/src/cli/test.py b/howdy/src/cli/test.py index 8933797..66a18f6 100644 --- a/howdy/src/cli/test.py +++ b/howdy/src/cli/test.py @@ -16,7 +16,7 @@ path = os.path.dirname(os.path.abspath(__file__)) # Read config from disk config = configparser.ConfigParser() -config.read(path + "/../config.ini") +config.read("/etc/howdy/config.ini") if config.get("video", "recording_plugin") != "opencv": print(_("Howdy has been configured to use a recorder which doesn't support the test command yet, aborting")) diff --git a/howdy/src/compare.py b/howdy/src/compare.py index 3fd7f35..1e6e936 100644 --- a/howdy/src/compare.py +++ b/howdy/src/compare.py @@ -126,7 +126,7 @@ face_encoder = None # Try to load the face model from the models folder try: - models = json.load(open(PATH + "/models/" + user + ".dat")) + models = json.load(open("/etc/howdy/models/" + user + ".dat")) for model in models: encodings += model["data"] @@ -139,7 +139,7 @@ if len(models) < 1: # Read config from disk config = configparser.ConfigParser() -config.read(PATH + "/config.ini") +config.read("/etc/howdy/config.ini") # Get all config values needed use_cnn = config.getboolean("core", "use_cnn", fallback=False) diff --git a/howdy/src/pam.py b/howdy/src/pam.py index 5e72f76..e7b598b 100644 --- a/howdy/src/pam.py +++ b/howdy/src/pam.py @@ -11,7 +11,7 @@ import ConfigParser # Read config from disk config = ConfigParser.ConfigParser() -config.read(os.path.dirname(os.path.abspath(__file__)) + "/config.ini") +config.read(os.path.dirname("/etc/howdy") + "/config.ini") def doAuth(pamh): diff --git a/howdy/src/pam/main.cc b/howdy/src/pam/main.cc index 2595c61..66c750b 100644 --- a/howdy/src/pam/main.cc +++ b/howdy/src/pam/main.cc @@ -126,7 +126,7 @@ int send_message(function