Move user specific configuration into main script

main^2
axtloss 2 years ago
parent 34dd8a6230
commit 4327b6cf70
No known key found for this signature in database
GPG Key ID: DD6D66939396C90E

@ -64,11 +64,11 @@ class VanillaDefaultUser(Adw.Bin):
def get_finals(self): def get_finals(self):
return { return {
"vars": { "vars": {
"create": True "createUser": True
}, },
"funcs": [ "funcs": [
{ {
"if": "create", "if": "createUser",
"type": "command", "type": "command",
"commands": [ "commands": [
f"adduser --quiet --disabled-password --shell /bin/bash --gecos \"{self.fullname}\" {self.username}", f"adduser --quiet --disabled-password --shell /bin/bash --gecos \"{self.fullname}\" {self.username}",

@ -31,50 +31,20 @@ class Processor:
commands = pre_run + commands + post_run commands = pre_run + commands + post_run
out_run = "" out_run = ""
next_boot = [] next_boot = []
next_boot_script_path = os.path.expanduser("~/.local/org.vanillaos.FirstSetup.nextBoot") next_boot_script_path = os.path.expanduser("/etc/org.vanillaos.FirstSetup.nextBoot")
next_boot_autostart_path = os.path.expanduser("~/.config/autostart/org.vanillaos.FirstSetup.nextBoot.desktop") next_boot_autostart_path = os.path.expanduser("/etc/xdg/autostart/org.vanillaos.FirstSetup.nextBoot.desktop")
done_file = "/etc/vanilla-first-setup-done" done_file = "/etc/vanilla-first-setup-done"
abroot_bin = shutil.which("abroot") abroot_bin = shutil.which("abroot")
logger.info("processing the following commands: \n%s" % logger.info("processing the following commands: \n%s" %
'\n'.join(commands)) '\n'.join(commands))
# nextBoot commands are collected in ~/.local/org.vanillaos.FirstSetup.nextBoot # Collect all the commands that should be run at the next boot
# and executed at the next boot by a desktop entry
for command in commands: for command in commands:
if command.startswith("!nextBoot"): if command.startswith("!nextBoot"):
next_boot.append(command.replace("!nextBoot", "")) next_boot.append(command.replace("!nextBoot", ""))
continue continue
if len(next_boot) > 0:
with open(next_boot_script_path, "w") as f:
f.write("#!/bin/sh\n")
f.write("# This file was created by FirstSetup\n")
f.write("# Do not edit this file manually\n\n")
for command in next_boot:
f.write(f"{command}\n")
f.write(f"rm -f {next_boot_script_path}\n")
f.write(f"rm -f {next_boot_autostart_path}\n")
f.flush()
f.close()
# setting the file executable
os.chmod(next_boot_script_path, 0o755)
# creating the desktop entry
with open(next_boot_autostart_path, "w") as f:
f.write("[Desktop Entry]\n")
f.write("Name=FirstSetup Next Boot\n")
f.write("Comment=Run FirstSetup commands at the next boot\n")
f.write("Exec=vanilla-first-setup --run-post-script 'sh %s'\n" % next_boot_script_path)
f.write("Terminal=false\n")
f.write("Type=Application\n")
f.write("X-GNOME-Autostart-enabled=true\n")
f.flush()
f.close()
# generating a temporary file to store all the commands so we can # generating a temporary file to store all the commands so we can
# run them all at once # run them all at once
with tempfile.NamedTemporaryFile(mode='w', delete=False) as f: with tempfile.NamedTemporaryFile(mode='w', delete=False) as f:
@ -94,6 +64,28 @@ class Processor:
f.write("exit 1\n") f.write("exit 1\n")
f.write("fi\n") f.write("fi\n")
# nextBoot commands are collected in /etc/org.vanillaos.FirstSetup.nextBoot
# and executed at the next boot by a desktop entry
if len(next_boot) > 0:
f.write("cat <<EOF > "+next_boot_script_path+"\n")
f.write("#!/bin/sh\n")
f.write("# This file was created by FirstSetup\n")
f.write("# Do not edit this file manually\n\n")
for command in next_boot:
f.write(f"{command}\n")
f.write("EOF\n")
f.write("chmod +x "+next_boot_script_path+"\n")
f.write("cat <<EOF > "+next_boot_autostart_path+"\n")
f.write("[Desktop Entry]\n")
f.write("Name=FirstSetup Next Boot\n")
f.write("Comment=Run FirstSetup commands at the next boot\n")
f.write("Exec=vanilla-first-setup --run-post-script 'sh %s'\n" % next_boot_script_path)
f.write("Terminal=false\n")
f.write("Type=Application\n")
f.write("X-GNOME-Autostart-enabled=true\n")
f.write("EOF\n")
for command in commands: for command in commands:
if command.startswith("!nextBoot"): if command.startswith("!nextBoot"):
continue continue

Loading…
Cancel
Save