diff --git a/howdy-gtk/src/onboarding.py b/howdy-gtk/src/onboarding.py index 4ed3406..d0f0e9c 100644 --- a/howdy-gtk/src/onboarding.py +++ b/howdy-gtk/src/onboarding.py @@ -64,6 +64,8 @@ class OnboardingWindow(gtk.Window): self.execute_slide5() def execute_slide1(self): + conf_path = "/etc/howdy" + self.downloadoutputlabel = self.builder.get_object("downloadoutputlabel") eventbox = self.builder.get_object("downloadeventbox") eventbox.modify_bg(gtk.StateType.NORMAL, gdk.Color(red=0, green=0, blue=0)) @@ -73,17 +75,18 @@ class OnboardingWindow(gtk.Window): break else: lib_site = None - + if lib_site is None: self.downloadoutputlabel.set_text(_("Unable to find Howdy's installation location")) return - if os.path.exists(lib_site + "/security/howdy/dlib-data/shape_predictor_5_face_landmarks.dat"): + + if os.path.exists(conf_path + "/dlib-data/shape_predictor_5_face_landmarks.dat"): self.downloadoutputlabel.set_text(_("Datafiles have already been downloaded!\nClick Next to continue")) self.enable_next() return - self.proc = subprocess.Popen("./install.sh", stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True, cwd=lib_site + "/security/howdy/dlib-data") + self.proc = subprocess.Popen("./install.sh", stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True, cwd=conf_path + "/howdy/dlib-data") self.download_lines = [] self.read_download_line() 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/PKGBUILD b/howdy/archlinux/howdy/PKGBUILD index b02dd63..dc66290 100644 --- a/howdy/archlinux/howdy/PKGBUILD +++ b/howdy/archlinux/howdy/PKGBUILD @@ -23,7 +23,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,15 +39,17 @@ package() { # Installing the proper license files and the rest of howdy cd howdy-$pkgver install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE" - mkdir -p "$pkgdir/usr/lib/security/howdy" - cp -r src/* "$pkgdir/usr/lib/security/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/" - chmod 600 -R "$pkgdir/usr/lib/security/howdy" + mkdir -p "$pkgdir/usr/etc/howdy" + mkdir -p "$pkgdir/etc/howdy" + cp -r src/* "$pkgdir/usr/etc/howdy" + cp -r src/config.ini "$pkgdir/etc/howdy" + cp "${srcdir}/dlib_face_recognition_resnet_model_v1.dat" "$pkgdir/usr/etc/howdy/dlib-data/" + cp "${srcdir}/mmod_human_face_detector.dat" "$pkgdir/usr/etc/howdy/dlib-data/" + cp "${srcdir}/shape_predictor_5_face_landmarks.dat" "$pkgdir/usr/etc/howdy/dlib-data/" + chmod 600 -R "$pkgdir/usr/etc/howdy" mkdir -p "$pkgdir/usr/bin" - ln -s /lib/security/howdy/cli.py "$pkgdir/usr/bin/howdy" - chmod +x "$pkgdir/usr/lib/security/howdy/cli.py" + ln -s /etc/howdy/cli.py "$pkgdir/usr/bin/howdy" + chmod +x "$pkgdir/etc/howdy/cli.py" mkdir -p "$pkgdir/usr/share/bash-completion/completions" cp autocomplete/howdy "$pkgdir/usr/share/bash-completion/completions/howdy" } diff --git a/howdy/debian/postinst b/howdy/debian/postinst index b8090e1..ebfdfdd 100755 --- a/howdy/debian/postinst +++ b/howdy/debian/postinst @@ -51,7 +51,7 @@ if "upgrade" in sys.argv: 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(): @@ -101,16 +101,11 @@ if "upgrade" in sys.argv: 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) sys.exit(0) -log("Downloading and unpacking data files") - -# Run the bash script to download and unpack the .dat files needed -handleStatus(subprocess.call(["./install.sh"], shell=True, cwd="/lib/security/howdy/dlib-data")) - log("Downloading dlib") dlib_archive = "/tmp/v19.16.tar.gz" @@ -184,7 +179,7 @@ print("Temporary dlib files removed") 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="") @@ -192,6 +187,7 @@ print("Camera ID saved") # Secure the howdy folder handleStatus(sc(["chmod 744 -R /lib/security/howdy/"], shell=True)) +handleStatus(sc(["chmod 744 -R /etc/howdy/"], shell=True)) # Allow anyone to execute the python CLI os.chmod("/lib/security/howdy", 0o755) diff --git a/howdy/debian/preinst b/howdy/debian/preinst index 329438c..1171e99 100755 --- a/howdy/debian/preinst +++ b/howdy/debian/preinst @@ -9,7 +9,12 @@ import sys if "upgrade" in sys.argv: # Try to copy the config file as a backup try: - subprocess.call(["cp /lib/security/howdy/config.ini /tmp/howdy_config_backup_v" + sys.argv[2] + ".ini"], shell=True) + # Try to copy the new location first + if os.path.exists("/etc/howdy/config.ini"): + subprocess.call(["cp /etc/howdy/config.ini /tmp/howdy_config_backup_v" + sys.argv[2] + ".ini"], shell=True) + # If that does not exist, try copying the old location + else: + subprocess.call(["cp /lib/security/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") 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 8e117f4..99104c6 100644 --- a/howdy/src/cli/add.py +++ b/howdy/src/cli/add.py @@ -26,39 +26,39 @@ except ImportError as err: # OpenCV needs to be imported after dlib import cv2 -# Get the absolute path to the current directory -path = os.path.abspath(__file__ + "/..") +# Define the absolute path to the config directory +config_path = "/etc/howdy" # 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"): +if not os.path.isfile(config_path + "/dlib-data/shape_predictor_5_face_landmarks.dat"): print(_("Data files have not been downloaded, please run the following commands:")) - print("\n\tcd " + os.path.realpath(path + "/../dlib-data")) + print("\n\tcd " + config_path + "/dlib-data") print("\tsudo ./install.sh\n") sys.exit(1) # 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: - face_detector = dlib.cnn_face_detection_model_v1(path + "/../dlib-data/mmod_human_face_detector.dat") + face_detector = dlib.cnn_face_detection_model_v1(config_path + "/dlib-data/mmod_human_face_detector.dat") else: face_detector = dlib.get_frontal_face_detector() -pose_predictor = dlib.shape_predictor(path + "/../dlib-data/shape_predictor_5_face_landmarks.dat") -face_encoder = dlib.face_recognition_model_v1(path + "/../dlib-data/dlib_face_recognition_resnet_model_v1.dat") +pose_predictor = dlib.shape_predictor(config_path + "/dlib-data/shape_predictor_5_face_landmarks.dat") +face_encoder = dlib.face_recognition_model_v1(config_path + "/dlib-data/dlib_face_recognition_resnet_model_v1.dat") user = builtins.howdy_user # The permanent file to store the encoded model in -enc_file = path + "/../models/" + user + ".dat" +enc_file = config_path + "/models/" + 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(config_path + "/models"): print(_("No face model folder found, creating one")) - os.makedirs(path + "/../models") + os.makedirs(config_path + "/models") # 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..6fa5f3e 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) @@ -30,9 +30,9 @@ if not builtins.howdy_args.y: # Abort if they don't answer y or Y if (ans.lower() != "y"): - print(_('\nInerpeting as a "NO", aborting')) + print(_('\nInterpreting as a "NO", aborting')) 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..b079580 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 @@ -50,7 +50,7 @@ for enc in encodings: # Format the time as ISO in the local timezone print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(enc["time"])), end="") - # Seperate with commas again for machines, spaces otherwise + # Separate with commas again for machines, spaces otherwise print("," if builtins.howdy_args.plain else " ", end="") # End with the label 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)