#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS)

. /etc/profile

CFG_PATH="/storage/.config/system/configs"

backup() {
  TYPE=$(grep a ${CFG_PATH}/system.cfg 2>&1)
  if [[ ! "${TYPE}" =~ binary ]]
  then
    cp ${CFG_PATH}/system.cfg ${CFG_PATH}/system.cfg.backup
  fi
}

restore() {
  cp ${CFG_PATH}/system.cfg.backup ${CFG_PATH}/system.cfg
}

verify() {
  TYPE=$(grep a ${CFG_PATH}/system.cfg 2>&1)
  if [[ "${TYPE}" =~ binary ]]
  then
    restore
  fi
}

case ${1} in
  verify)
    verify
  ;;
  backup)
    backup
  ;;
  restore)
    restore
  ;;
esac
