BMC: Block BMC reboot during code update

- Create functions inside obmc-flash-bmc script to enable
  and disable reboots from command line.
- Create service files for enabling and disabling BMC reboots.
- The enable service will be called during the constructor of
  ActivationBlockTransition and disable service will be run during
  the destructor of ActivationBlockTransition.

Change-Id: Idcec12b2c1126e212ee861150c92aaacd23a1ace
Signed-off-by: Saqib Khan <khansa@us.ibm.com>
diff --git a/common/recipes-phosphor/flash/phosphor-software-manager/obmc-flash-bmc b/common/recipes-phosphor/flash/phosphor-software-manager/obmc-flash-bmc
index 6725eaa..d8eed57 100644
--- a/common/recipes-phosphor/flash/phosphor-software-manager/obmc-flash-bmc
+++ b/common/recipes-phosphor/flash/phosphor-software-manager/obmc-flash-bmc
@@ -271,6 +271,31 @@
   ubi_setenv "root=${block}"
 }
 
+#TODO: Replace the implementation with systemd-inhibitors lock
+#      once systemd/systemd#949 is resolved
+rebootguardenable() {
+  dir="/run/systemd/system/"
+  file="reboot-guard.conf"
+  units=("reboot" "poweroff" "halt")
+
+  for unit in "${units[@]}"; do
+    mkdir -p ${dir}${unit}.target.d
+    echo -e "[Unit]\nRefuseManualStart=yes" >> ${dir}${unit}.target.d/${file}
+  done
+}
+
+#TODO: Replace the implementation with systemd-inhibitors lock
+#      once systemd/systemd#949 is resolved
+rebootguarddisable() {
+  dir="/run/systemd/system/"
+  file="reboot-guard.conf"
+  units=("reboot" "poweroff" "halt")
+
+  for unit in "${units[@]}"; do
+    rm -rf ${dir}${unit}.target.d/${file}
+  done
+}
+
 # Create a copy in the alt mtd
 create_vol_in_alt() {
   alt="alt-bmc"
@@ -334,6 +359,12 @@
     version="$2"
     update_env_vars
     ;;
+  rebootguardenable)
+    rebootguardenable
+    ;;
+  rebootguarddisable)
+    rebootguarddisable
+    ;;
   *)
     echo "Invalid argument"
     exit 1