0
0
Fork 0
mirror of https://github.com/boltgolt/howdy.git synced 2024-09-19 09:51:19 +02:00

Merge pull request #649 from patriziobruno/beta

move config.ini and /models to /etc/howdy
This commit is contained in:
boltgolt 2023-02-19 10:47:15 +01:00 committed by GitHub
commit 2d77431a56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 56 additions and 50 deletions

View file

@ -64,6 +64,8 @@ class OnboardingWindow(gtk.Window):
self.execute_slide5() self.execute_slide5()
def execute_slide1(self): def execute_slide1(self):
conf_path = "/etc/howdy"
self.downloadoutputlabel = self.builder.get_object("downloadoutputlabel") self.downloadoutputlabel = self.builder.get_object("downloadoutputlabel")
eventbox = self.builder.get_object("downloadeventbox") eventbox = self.builder.get_object("downloadeventbox")
eventbox.modify_bg(gtk.StateType.NORMAL, gdk.Color(red=0, green=0, blue=0)) eventbox.modify_bg(gtk.StateType.NORMAL, gdk.Color(red=0, green=0, blue=0))
@ -78,12 +80,13 @@ class OnboardingWindow(gtk.Window):
self.downloadoutputlabel.set_text(_("Unable to find Howdy's installation location")) self.downloadoutputlabel.set_text(_("Unable to find Howdy's installation location"))
return 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.downloadoutputlabel.set_text(_("Datafiles have already been downloaded!\nClick Next to continue"))
self.enable_next() self.enable_next()
return 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.download_lines = []
self.read_download_line() self.read_download_line()

View file

@ -17,7 +17,7 @@ def on_page_switch(self, notebook, page, page_num):
try: try:
self.config = configparser.ConfigParser() self.config = configparser.ConfigParser()
self.config.read("/lib/security/howdy/config.ini") self.config.read("/etc/howdy/config.ini")
except Exception: except Exception:
print(_("Can't open camera")) print(_("Can't open camera"))

View file

@ -49,7 +49,7 @@ class MainWindow(gtk.Window):
# Add the treeview # Add the treeview
self.modellistbox.add(self.treeview) self.modellistbox.add(self.treeview)
filelist = os.listdir("/lib/security/howdy/models") filelist = os.listdir("/etc/howdy/models")
self.active_user = "" self.active_user = ""
self.userlist.items = 0 self.userlist.items = 0
@ -117,7 +117,7 @@ signal.signal(signal.SIGINT, signal.SIG_DFL)
elevate.elevate() elevate.elevate()
# If no models have been created yet or when it is forced, start the onboarding # 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 import onboarding
onboarding.OnboardingWindow() onboarding.OnboardingWindow()

View file

@ -23,7 +23,7 @@ makedepends=(
'cmake' 'cmake'
'pkgfile' 'pkgfile'
) )
backup=('usr/lib/security/howdy/config.ini') backup=('etc/howdy/config.ini')
source=( source=(
"$pkgname-$pkgver.tar.gz::https://github.com/boltgolt/howdy/archive/v${pkgver}.tar.gz" "$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" "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 # Installing the proper license files and the rest of howdy
cd howdy-$pkgver cd howdy-$pkgver
install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE" install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
mkdir -p "$pkgdir/usr/lib/security/howdy" mkdir -p "$pkgdir/usr/etc/howdy"
cp -r src/* "$pkgdir/usr/lib/security/howdy" mkdir -p "$pkgdir/etc/howdy"
cp "${srcdir}/dlib_face_recognition_resnet_model_v1.dat" "$pkgdir/usr/lib/security/howdy/dlib-data/" cp -r src/* "$pkgdir/usr/etc/howdy"
cp "${srcdir}/mmod_human_face_detector.dat" "$pkgdir/usr/lib/security/howdy/dlib-data/" cp -r src/config.ini "$pkgdir/etc/howdy"
cp "${srcdir}/shape_predictor_5_face_landmarks.dat" "$pkgdir/usr/lib/security/howdy/dlib-data/" cp "${srcdir}/dlib_face_recognition_resnet_model_v1.dat" "$pkgdir/usr/etc/howdy/dlib-data/"
chmod 600 -R "$pkgdir/usr/lib/security/howdy" 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" mkdir -p "$pkgdir/usr/bin"
ln -s /lib/security/howdy/cli.py "$pkgdir/usr/bin/howdy" ln -s /etc/howdy/cli.py "$pkgdir/usr/bin/howdy"
chmod +x "$pkgdir/usr/lib/security/howdy/cli.py" chmod +x "$pkgdir/etc/howdy/cli.py"
mkdir -p "$pkgdir/usr/share/bash-completion/completions" mkdir -p "$pkgdir/usr/share/bash-completion/completions"
cp autocomplete/howdy "$pkgdir/usr/share/bash-completion/completions/howdy" cp autocomplete/howdy "$pkgdir/usr/share/bash-completion/completions/howdy"
} }

View file

@ -51,7 +51,7 @@ if "upgrade" in sys.argv:
oldConf = configparser.ConfigParser() oldConf = configparser.ConfigParser()
oldConf.read("/tmp/howdy_config_backup_v" + sys.argv[2] + ".ini") oldConf.read("/tmp/howdy_config_backup_v" + sys.argv[2] + ".ini")
newConf = configparser.ConfigParser() 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 # Go through every setting in the old config and apply it to the new file
for section in oldConf.sections(): for section in oldConf.sections():
@ -101,16 +101,11 @@ if "upgrade" in sys.argv:
newConf.set(section, key, value) newConf.set(section, key, value)
# Write it all to file # 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) newConf.write(configfile)
sys.exit(0) 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") log("Downloading dlib")
dlib_archive = "/tmp/v19.16.tar.gz" dlib_archive = "/tmp/v19.16.tar.gz"
@ -184,7 +179,7 @@ print("Temporary dlib files removed")
log("Configuring howdy") log("Configuring howdy")
# Manually change the camera id to the one picked # 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()) line = line.replace("use_cnn = false", "use_cnn = " + str(cuda_used).lower())
print(line, end="") print(line, end="")
@ -192,6 +187,7 @@ print("Camera ID saved")
# Secure the howdy folder # Secure the howdy folder
handleStatus(sc(["chmod 744 -R /lib/security/howdy/"], shell=True)) 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 # Allow anyone to execute the python CLI
os.chmod("/lib/security/howdy", 0o755) os.chmod("/lib/security/howdy", 0o755)

View file

@ -9,6 +9,11 @@ import sys
if "upgrade" in sys.argv: if "upgrade" in sys.argv:
# Try to copy the config file as a backup # Try to copy the config file as a backup
try: try:
# 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) 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 # Let the user know so he knows where to look on a failed install

View file

@ -20,7 +20,7 @@ _howdy() {
;; ;;
# For disable, grab the current "disabled" config option and give the reverse # For disable, grab the current "disabled" config option and give the reverse
"disable") "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" [ "$status" == "false" ] && COMPREPLY="true" || COMPREPLY="false"
return 0 return 0

View file

@ -26,39 +26,39 @@ except ImportError as err:
# OpenCV needs to be imported after dlib # OpenCV needs to be imported after dlib
import cv2 import cv2
# Get the absolute path to the current directory # Define the absolute path to the config directory
path = os.path.abspath(__file__ + "/..") config_path = "/etc/howdy"
# Test if at lest 1 of the data files is there and abort if it's not # 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(_("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") print("\tsudo ./install.sh\n")
sys.exit(1) sys.exit(1)
# Read config from disk # Read config from disk
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(path + "/../config.ini") config.read(config_path + "/config.ini")
use_cnn = config.getboolean("core", "use_cnn", fallback=False) use_cnn = config.getboolean("core", "use_cnn", fallback=False)
if use_cnn: 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: else:
face_detector = dlib.get_frontal_face_detector() face_detector = dlib.get_frontal_face_detector()
pose_predictor = dlib.shape_predictor(path + "/../dlib-data/shape_predictor_5_face_landmarks.dat") pose_predictor = dlib.shape_predictor(config_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") face_encoder = dlib.face_recognition_model_v1(config_path + "/dlib-data/dlib_face_recognition_resnet_model_v1.dat")
user = builtins.howdy_user user = builtins.howdy_user
# The permanent file to store the encoded model in # The permanent file to store the encoded model in
enc_file = path + "/../models/" + user + ".dat" enc_file = config_path + "/models/" + user + ".dat"
# Known encodings # Known encodings
encodings = [] encodings = []
# Make the ./models folder if it doesn't already exist # 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")) 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 # To try read a premade encodings file if it exists
try: try:

View file

@ -8,17 +8,17 @@ import builtins
from i18n import _ from i18n import _
# Get the full path to this file # Get the full path to this file
path = os.path.dirname(os.path.abspath(__file__)) path = "/etc/howdy/models"
# Get the passed user # Get the passed user
user = builtins.howdy_user user = builtins.howdy_user
# Check if the models folder is there # 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")) print(_("No models created yet, can't clear them if they don't exist"))
sys.exit(1) sys.exit(1)
# Check if the user has a models file to delete # 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)) print(_("{} has no models or they have been cleared already").format(user))
sys.exit(1) sys.exit(1)
@ -30,9 +30,9 @@ if not builtins.howdy_args.y:
# Abort if they don't answer y or Y # Abort if they don't answer y or Y
if (ans.lower() != "y"): if (ans.lower() != "y"):
print(_('\nInerpeting as a "NO", aborting')) print(_('\nInterpreting as a "NO", aborting'))
sys.exit(1) sys.exit(1)
# Delete otherwise # Delete otherwise
os.remove(path + "/../models/" + user + ".dat") os.remove(path + "/" + user + ".dat")
print(_("\nModels cleared")) print(_("\nModels cleared"))

View file

@ -18,5 +18,6 @@ if "EDITOR" in os.environ:
elif os.path.isfile("/etc/alternatives/editor"): elif os.path.isfile("/etc/alternatives/editor"):
editor = "/etc/alternatives/editor" editor = "/etc/alternatives/editor"
config_path = "/etc/howdy"
# Open the editor as a subprocess and fork it # 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"])

View file

@ -10,7 +10,7 @@ import configparser
from i18n import _ from i18n import _
# Get the absolute filepath # 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 # Read config from disk
config = configparser.ConfigParser() config = configparser.ConfigParser()

View file

@ -10,7 +10,7 @@ import builtins
from i18n import _ from i18n import _
# Get the absolute path and the username # Get the absolute path and the username
path = os.path.dirname(os.path.realpath(__file__)) + "/.." path = "/etc/howdy"
user = builtins.howdy_user user = builtins.howdy_user
# Check if the models file has been created yet # 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 # Format the time as ISO in the local timezone
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(enc["time"])), end="") 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="") print("," if builtins.howdy_args.plain else " ", end="")
# End with the label # End with the label

View file

@ -9,7 +9,7 @@ import builtins
from i18n import _ from i18n import _
# Get the absolute path and the username # Get the absolute path and the username
path = os.path.dirname(os.path.realpath(__file__)) + "/.." path = "/etc/howdy"
user = builtins.howdy_user user = builtins.howdy_user
# Check if enough arguments have been passed # Check if enough arguments have been passed

View file

@ -9,7 +9,7 @@ import fileinput
from i18n import _ from i18n import _
# Get the absolute filepath # 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 # Check if enough arguments have been passed
if len(builtins.howdy_args.arguments) < 2: if len(builtins.howdy_args.arguments) < 2:

View file

@ -9,12 +9,11 @@ from recorders.video_capture import VideoCapture
from i18n import _ from i18n import _
# Get the absolute path to the current directory path = "/etc/howdy"
path = os.path.abspath(__file__ + "/..")
# Read the config # Read the config
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(path + "/../config.ini") config.read(path + "/config.ini")
# Start video capture # Start video capture
video_capture = VideoCapture(config) video_capture = VideoCapture(config)