Skip to content

Commit

Permalink
Added auto config backup and restore for upgarades
Browse files Browse the repository at this point in the history
This does remove all comments from the config file
  • Loading branch information
boltgolt committed May 10, 2018
1 parent 5ac5070 commit 22cc108
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
1 change: 1 addition & 0 deletions autocomplete/howdy
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ _howdy() {
return 0
}

# Register the autocomplete function
complete -F _howdy howdy
30 changes: 28 additions & 2 deletions debian/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,34 @@ def handleStatus(status):
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"):
# 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)

# Open the temporary file containing the device ID
Expand Down Expand Up @@ -162,7 +188,7 @@ if "HOWDY_NO_PROMPT" not in os.environ:

# Abort the whole thing if it's not
if (ans.lower() != "y"):
print("Inerpeting as a \"NO\", aborting")
print("Interpreting as a \"NO\", aborting")
sys.exit(1)

print("Adding lines to PAM\n")
Expand Down
14 changes: 14 additions & 0 deletions debian/preinst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ import os
import re
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
if "install" not in sys.argv:
sys.exit(0)
Expand Down
2 changes: 1 addition & 1 deletion src/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def stop(status):
video_capture = cv2.VideoCapture(int(config.get("video", "device_id")))

# 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)

# Capture a single frame so the camera becomes active
Expand Down
2 changes: 2 additions & 0 deletions src/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ dark_threshold = 50
[debug]
# Show a short but detailed diagnostic report in console
end_report = false

dummy = true

0 comments on commit 22cc108

Please sign in to comment.