Skip to content

Commit

Permalink
Add a systemd service that enables Initial Setup if /.unconfigured ex…
Browse files Browse the repository at this point in the history
…ists (#1257624)

Add a systemd service called initial-setup-reconfiguration.service that automatically starts
initial-setup.service when a file named .unconfigured exists in filesystem root (/).

Initial Setup will then detect the file & start in the reconfiguration mode.
Initial Setup also makes sure to delete the file & disable its service once done.

Resolves: rhbz#1257624
  • Loading branch information
M4rtinK committed Jun 1, 2016
1 parent bda9a63 commit 1dfa45a
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 16 deletions.
1 change: 1 addition & 0 deletions initial-setup.spec
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ make install-po-files
%exclude %{python_sitelib}/initial_setup/gui
%{_unitdir}/initial-setup-text.service
%{_unitdir}/initial-setup.service
%{_unitdir}/initial-setup-reconfiguration.service
%{_libexecdir}/%{name}/run-initial-setup
%{_libexecdir}/%{name}/firstboot-windowmanager
%{_libexecdir}/%{name}/initial-setup-text
Expand Down
54 changes: 39 additions & 15 deletions initial_setup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class InitialSetupError(Exception):

INPUT_KICKSTART_PATH = "/root/anaconda-ks.cfg"
OUTPUT_KICKSTART_PATH = "/root/initial-setup-ks.cfg"
RECONFIG_FILE = "/etc/reconfigSys"
RECONFIG_FILES = ["/etc/reconfigSys", "/.unconfigured"]

SUPPORTED_KICKSTART_COMMANDS = ["user",
"eula",
Expand All @@ -47,8 +47,6 @@ class InitialSetupError(Exception):

signal.signal(signal.SIGINT, signal.SIG_IGN)

external_reconfig = os.path.exists(RECONFIG_FILE)

# setup logging
log = logging.getLogger("initial-setup")

Expand Down Expand Up @@ -79,7 +77,17 @@ def __init__(self, gui_mode):
else:
log.debug("running in TUI mode")

if external_reconfig:
self._external_reconfig = False

# check if the reconfig mode should be enabled
# by checking if at least one of the reconfig
# files exist
for reconfig_file in RECONFIG_FILES:
if os.path.exists(reconfig_file):
self.external_reconfig = True
log.debug("reconfig trigger file found: %s", reconfig_file)

if self.external_reconfig:
log.debug("running in externally triggered reconfig mode")

if self.gui_mode:
Expand Down Expand Up @@ -112,6 +120,21 @@ def __init__(self, gui_mode):
from pyanaconda.network import setup_ifcfg_log
setup_ifcfg_log()

@property
def external_reconfig(self):
"""External reconfig status.
Reports if external (eq. not triggered by kickstart) has been enabled.
:returns: True if external reconfig mode has been enabled, else False.
:rtype: bool
"""
return self._external_reconfig

@external_reconfig.setter
def external_reconfig(self, value):
self._external_reconfig = value

@property
def gui_mode_id(self):
"""String id of the current GUI mode
Expand Down Expand Up @@ -162,7 +185,7 @@ def _load_kickstart(self):
log.critical("Initial Setup startup failed due to invalid kickstart file")
raise InitialSetupError

if external_reconfig:
if self.external_reconfig:
# set the reconfig flag in kickstart so that
# relevant spokes show up
self.data.firstboot.firstboot = FIRSTBOOT_RECONFIG
Expand Down Expand Up @@ -211,10 +234,10 @@ def _apply(self):
log.info("executing addons")
self.data.addons.execute(None, self.data, None, u, None)

if external_reconfig:
# prevent the reconfig flag from being written out,
# to prevent the reconfig mode from being enabled
# without the /etc/reconfigSys file being present
if self.external_reconfig:
# prevent the reconfig flag from being written out
# to kickstart if neither /etc/reconfigSys or /.unconfigured
# are present
self.data.firstboot.firstboot = None

# Write the kickstart data to file
Expand All @@ -223,12 +246,13 @@ def _apply(self):
f.write(str(self.data))
log.info("finished writing the Initial Setup kickstart file")

# Remove the reconfig file, if any - otherwise the reconfig mode
# would start again next time the Initial Setup service is enabled
if external_reconfig and os.path.exists(RECONFIG_FILE):
log.debug("removing the reconfig file")
os.remove(RECONFIG_FILE)
log.debug("the reconfig file has been removed")
# Remove the reconfig files, if any - otherwise the reconfig mode
# would start again next time the Initial Setup service is enabled.
if self.external_reconfig:
for reconfig_file in RECONFIG_FILES:
if os.path.exists(reconfig_file):
log.debug("removing reconfig trigger file: %s" % reconfig_file)
os.remove(reconfig_file)

def run(self):
"""Run Initial setup
Expand Down
3 changes: 3 additions & 0 deletions scripts/reconfiguration-mode-enabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo "The /.unconfigured file has been detected, enabling Initial Setup in reconfiguration mode." | systemd-cat -t initial-setup -p 6
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def read(fname):
('/usr/libexec/initial-setup/',
["scripts/run-initial-setup", "scripts/firstboot-windowmanager",
"scripts/initial-setup-text", "scripts/initial-setup-graphical",
"scripts/graphical-service-is-deprecated", "scripts/text-service-is-deprecated"])]
"scripts/graphical-service-is-deprecated", "scripts/text-service-is-deprecated",
"reconfiguration-mode-enabled"])]

# add the firstboot start script for s390 architectures
if os.uname()[4].startswith('s390'):
Expand Down
26 changes: 26 additions & 0 deletions systemd/initial-setup-reconfigure.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[Unit]
Description=Initial Setup reconfiguration mode trigger service
After=livesys.service plymouth-quit-wait.service
After=systemd-vconsole-setup.service
Before=display-manager.service getty@tty1.service getty@ttyUSB0.service
Before=serial-getty@ttyS0.service serial-getty@ttyO0.service serial-getty@ttyO2.service
Before=serial-getty@ttyAMA0.service serial-getty@ttymxc0.service serial-getty@ttymxc3.service serial-getty@hvc0.service
Before=initial-setup.service
Conflicts=plymouth-quit-wait.service
ConditionKernelCommandLine=!rd.live.image
ConditionPathExists=/.unconfigured
Requires=initial-setup.service

[Service]
Type=oneshot
TimeoutSec=0
StandardInput=tty
StandardOutput=tty
RemainAfterExit=yes
ExecStart=/usr/libexec/initial-setup/reconfiguration-mode-enabled
TimeoutSec=0
RemainAfterExit=no

[Install]
WantedBy=graphical.target
WantedBy=multi-user.target

0 comments on commit 1dfa45a

Please sign in to comment.