move config.ini and /models to /etc/howdy for better compatibility with immutable OSs

This commit is contained in:
Patrizio Bruno 2022-04-05 18:54:30 +01:00
parent 96767fe58e
commit 6151217466
No known key found for this signature in database
GPG key ID: 829581B9BB81D1C8
19 changed files with 41 additions and 31 deletions

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

@ -13,7 +13,7 @@ pkgbase = howdy
depends = python3 depends = python3
depends = python-dlib depends = python-dlib
depends = python-numpy 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 = 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/dlib_face_recognition_resnet_model_v1.dat.bz2
source = https://github.com/davisking/dlib-models/raw/master/mmod_human_face_detector.dat.bz2 source = https://github.com/davisking/dlib-models/raw/master/mmod_human_face_detector.dat.bz2

View file

@ -22,7 +22,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,7 +39,9 @@ package() {
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/lib/security/howdy"
mkdir -p "$pkgdir/etc/howdy"
cp -r src/* "$pkgdir/usr/lib/security/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}/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}/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/" cp "${srcdir}/shape_predictor_5_face_landmarks.dat" "$pkgdir/usr/lib/security/howdy/dlib-data/"

View file

@ -52,7 +52,7 @@ if not os.path.exists("/tmp/howdy_picked_device"):
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():
@ -98,7 +98,7 @@ if not os.path.exists("/tmp/howdy_picked_device"):
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)
# Install dlib data files if needed # Install dlib data files if needed
@ -200,7 +200,7 @@ handleStatus(subprocess.call(["pip3", "install", "--no-cache-dir", "opencv-pytho
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="")

View file

@ -14,7 +14,13 @@ if "upgrade" in sys.argv:
# 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
print("Backup of Howdy config file created in /tmp/howdy_config_backup_v" + sys.argv[2] + ".ini") print("Backup of Howdy config file created in /tmp/howdy_config_backup_v" + sys.argv[2] + ".ini")
except subprocess.CalledProcessError: 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 # Don't continue setup when we're just upgrading
sys.exit(0) sys.exit(0)

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

@ -28,6 +28,8 @@ import cv2
# Get the absolute path to the current directory # Get the absolute path to the current directory
path = os.path.abspath(__file__ + "/..") 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 # 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(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 # 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:
@ -51,14 +53,14 @@ face_encoder = dlib.face_recognition_model_v1(path + "/../dlib-data/dlib_face_re
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 = models_path + "/" + 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(models_path):
print(_("No face model folder found, creating one")) 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 # 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)
@ -34,5 +34,5 @@ if not builtins.howdy_args.y:
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

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)

View file

@ -16,7 +16,7 @@ path = os.path.dirname(os.path.abspath(__file__))
# Read config from disk # Read config from disk
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(path + "/../config.ini") config.read("/etc/howdy/config.ini")
if config.get("video", "recording_plugin") != "opencv": 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")) print(_("Howdy has been configured to use a recorder which doesn't support the test command yet, aborting"))

View file

@ -126,7 +126,7 @@ face_encoder = None
# Try to load the face model from the models folder # Try to load the face model from the models folder
try: try:
models = json.load(open(PATH + "/models/" + user + ".dat")) models = json.load(open("/etc/howdy/models/" + user + ".dat"))
for model in models: for model in models:
encodings += model["data"] encodings += model["data"]
@ -139,7 +139,7 @@ if len(models) < 1:
# Read config from disk # Read config from disk
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(PATH + "/config.ini") config.read("/etc/howdy/config.ini")
# Get all config values needed # Get all config values needed
use_cnn = config.getboolean("core", "use_cnn", fallback=False) use_cnn = config.getboolean("core", "use_cnn", fallback=False)

View file

@ -11,7 +11,7 @@ import ConfigParser
# Read config from disk # Read config from disk
config = ConfigParser.ConfigParser() 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): def doAuth(pamh):

View file

@ -126,7 +126,7 @@ int send_message(function<int(int, const struct pam_message **,
*/ */
int identify(pam_handle_t *pamh, int flags, int argc, const char **argv, int identify(pam_handle_t *pamh, int flags, int argc, const char **argv,
bool auth_tok) { bool auth_tok) {
INIReader reader("/lib/security/howdy/config.ini"); INIReader reader("/etc/howdy/config.ini");
// Open the system log so we can write to it // Open the system log so we can write to it
openlog("pam_howdy", 0, LOG_AUTHPRIV); openlog("pam_howdy", 0, LOG_AUTHPRIV);