Added auto config backup and restore for upgarades
This does remove all comments from the config file
This commit is contained in:
parent
5ac5070d11
commit
22cc108e87
5 changed files with 46 additions and 3 deletions
|
|
@ -42,4 +42,5 @@ _howdy() {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Register the autocomplete function
|
||||||
complete -F _howdy howdy
|
complete -F _howdy howdy
|
||||||
|
|
|
||||||
30
debian/postinst
vendored
30
debian/postinst
vendored
|
|
@ -36,8 +36,34 @@ def handleStatus(status):
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
# We're not in fresh configuration mode (probably an upgrade), so exit
|
# We're not in fresh configuration mode so don't continue the setup
|
||||||
if not os.path.exists("/tmp/howdy_picked_device"):
|
if not os.path.exists("/tmp/howdy_picked_device"):
|
||||||
|
# Check if we have an older config we can restore
|
||||||
|
if len(sys.argv) > 2:
|
||||||
|
if os.path.exists("/tmp/howdy_config_backup_v" + sys.argv[2] + ".ini"):
|
||||||
|
# Get the config parser
|
||||||
|
import configparser
|
||||||
|
|
||||||
|
# Load th old and new config files
|
||||||
|
oldConf = configparser.ConfigParser()
|
||||||
|
oldConf.read("/tmp/howdy_config_backup_v" + sys.argv[2] + ".ini")
|
||||||
|
newConf = configparser.ConfigParser()
|
||||||
|
newConf.read("/lib/security/howdy/config.ini")
|
||||||
|
|
||||||
|
# Go through every setting in the old config and apply it to the new file
|
||||||
|
for section in oldConf.sections():
|
||||||
|
for (key, value) in oldConf.items(section):
|
||||||
|
try:
|
||||||
|
newConf.set(section, key, value)
|
||||||
|
# Add a new section where needed
|
||||||
|
except configparser.NoSectionError as e:
|
||||||
|
newConf.add_section(section)
|
||||||
|
newConf.set(section, key, value)
|
||||||
|
|
||||||
|
# Write it all to file
|
||||||
|
with open("/lib/security/howdy/config.ini", "w") as configfile:
|
||||||
|
newConf.write(configfile)
|
||||||
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
# Open the temporary file containing the device ID
|
# Open the temporary file containing the device ID
|
||||||
|
|
@ -162,7 +188,7 @@ if "HOWDY_NO_PROMPT" not in os.environ:
|
||||||
|
|
||||||
# Abort the whole thing if it's not
|
# Abort the whole thing if it's not
|
||||||
if (ans.lower() != "y"):
|
if (ans.lower() != "y"):
|
||||||
print("Inerpeting as a \"NO\", aborting")
|
print("Interpreting as a \"NO\", aborting")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
print("Adding lines to PAM\n")
|
print("Adding lines to PAM\n")
|
||||||
|
|
|
||||||
14
debian/preinst
vendored
14
debian/preinst
vendored
|
|
@ -16,6 +16,20 @@ import os
|
||||||
import re
|
import re
|
||||||
import signal
|
import signal
|
||||||
|
|
||||||
|
# Backup the config file if we're upgrading
|
||||||
|
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)
|
||||||
|
|
||||||
|
# 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 e:
|
||||||
|
print("Could not make an backup of old Howdy config file")
|
||||||
|
|
||||||
|
# Don't continue setup when we're just upgrading
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
# Don't run if we're not trying to install fresh
|
# Don't run if we're not trying to install fresh
|
||||||
if "install" not in sys.argv:
|
if "install" not in sys.argv:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ timings.append(time.time())
|
||||||
video_capture = cv2.VideoCapture(int(config.get("video", "device_id")))
|
video_capture = cv2.VideoCapture(int(config.get("video", "device_id")))
|
||||||
|
|
||||||
# Force MJPEG decoding if true
|
# Force MJPEG decoding if true
|
||||||
if config.get("debug", "force_mjpeg") == "true":
|
if config.get("video", "force_mjpeg") == "true":
|
||||||
video_capture.set(cv2.CAP_PROP_FOURCC, 1196444237)
|
video_capture.set(cv2.CAP_PROP_FOURCC, 1196444237)
|
||||||
|
|
||||||
# Capture a single frame so the camera becomes active
|
# Capture a single frame so the camera becomes active
|
||||||
|
|
|
||||||
|
|
@ -46,3 +46,5 @@ dark_threshold = 50
|
||||||
[debug]
|
[debug]
|
||||||
# Show a short but detailed diagnostic report in console
|
# Show a short but detailed diagnostic report in console
|
||||||
end_report = false
|
end_report = false
|
||||||
|
|
||||||
|
dummy = true
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue