feat: move user settings to post-install

This commit is contained in:
Rudra Saraswat 2024-02-13 17:16:23 +05:30
parent 2227ddecf8
commit 66fd0578d2
2 changed files with 225 additions and 34 deletions

View file

@ -229,8 +229,6 @@ def inst_setup_base(config):
else:
exec(['unsquashfs', '-f', '-d', '/mnt',
'/run/archiso/bootmnt/blend/x86_64/airootfs.sfs'])
# Enable system services
enable_service('akshara')
enable_service('bluetooth')
enable_service('cups')
# Enable blend-files
@ -239,7 +237,7 @@ def inst_setup_base(config):
exec_chroot(['bash', '-c', 'echo \'MODULES=""\' > /etc/mkinitcpio.conf'])
exec_chroot(['bash', '-c', 'echo \'BINARIES=""\' >> /etc/mkinitcpio.conf'])
exec_chroot(['bash', '-c', 'echo \'FILES=""\' >> /etc/mkinitcpio.conf'])
exec_chroot(['bash', '-c', 'echo \'HOOKS="base udev akshara plymouth autodetect modconf block keyboard keymap consolefont filesystems fsck"\' >> /etc/mkinitcpio.conf'])
exec_chroot(['bash', '-c', 'echo \'HOOKS="base udev plymouth autodetect modconf block keyboard keymap consolefont filesystems fsck"\' >> /etc/mkinitcpio.conf'])
exec_chroot(
['bash', '-c', 'echo \'COMPRESSION="zstd"\' >> /etc/mkinitcpio.conf'])
# Generate fstab
@ -249,13 +247,16 @@ def inst_setup_base(config):
exec_chroot(['pacman-key', '--populate', 'archlinux', 'blend'])
# Install linux-zen
exec_chroot(['pacman', '-Sy', '--noconfirm', 'linux-zen', 'xorriso'])
# Remove jade-gui and blend-inst
exec_chroot(['pacman', '-Rn', '--noconfirm', 'jade-gui', 'blend-inst-git'])
# Remove jade-gui
exec_chroot(['pacman', '-Rn', '--noconfirm', 'jade-gui'])
# Install jade-gui-postinst
exec_chroot(['pacman', '-S', 'jade-gui-post-inst'])
def inst_bootloader(config):
# Install bootloader
if 'NVIDIA' in subprocess.check_output(['lspci']).decode('utf-8'):
exec_chroot(['pacman', '-Sy', '--noconfirm', 'nvidia-dkms'])
exec_chroot(
['bash', '-c', 'echo -e \'\\nGRUB_CMDLINE_LINUX_DEFAULT="${GRUB_CMDLINE_LINUX_DEFAULT} vt.global_cursor_default=0 nvidia_drm.modeset=1 splash"\' >> /etc/default/grub'])
mkdir('/mnt/etc/udev/rules.d')
@ -328,8 +329,7 @@ def inst_networking(config):
def inst_users(config):
# Create sudoers
exec_chroot(['bash', '-c', 'userdel -r blend &>/dev/null'])
# Write files
exec_chroot(
['bash', '-c', 'echo "root ALL=(ALL:ALL) ALL" > /etc/sudoers'])
exec_chroot(
@ -338,35 +338,34 @@ def inst_users(config):
['bash', '-c', 'echo "Defaults pwfeedback" >> /etc/sudoers']
)
# Add users
for user in config['users']:
if user['name'] == 'blend':
print()
print('The username blend is not allowed.')
sys.exit(3)
exec_chroot(
['bash', '-c', 'echo \'{"hasWindows":true,"components":["networkAgent"],"panel":{"left":[],"center":[],"right":["a11y","keyboard","quickSettings"]}}\' > /usr/share/gnome-shell/modes/jade-gui.json'])
exec_chroot(['useradd', '-m', '-s', '/bin/bash', user['name']])
exec_chroot(['usermod', '-c', user['fullname'], user['name']])
exec_chroot(
['bash', '-c', f'echo \'{user["name"]}:{user["password"]}\' | chpasswd'])
exec_chroot(['usermod', '-aG', 'wheel', user['name']])
# Add AccountsService user file
mkdir('/mnt/var/lib/AccountsService/users')
['bash', '-c', 'echo \'[GNOME Session]\' >> /usr/share/gnome-session/sessions/jade-gui.session'])
exec_chroot(
['bash', '-c', f'echo "[User]" > /var/lib/AccountsService/users/{user["name"]}'])
['bash', '-c', 'echo \'Name=First Setup\' >> /usr/share/gnome-session/sessions/jade-gui.session'])
exec_chroot(
['bash', '-c', f'echo "SystemAccount=false" >> /var/lib/AccountsService/users/{user["name"]}'])
['bash', '-c', 'echo \'RequiredComponents=org.gnome.Shell;al.getcryst.jadegui;org.gnome.SettingsDaemon.A11ySettings;org.gnome.SettingsDaemon.Clipboard;org.gnome.SettingsDaemon.Color;org.gnome.SettingsDaemon.Datetime;org.gnome.SettingsDaemon.Housekeeping;org.gnome.SettingsDaemon.Keyboard;org.gnome.SettingsDaemon.MediaKeys;org.gnome.SettingsDaemon.Mouse;org.gnome.SettingsDaemon.Power;org.gnome.SettingsDaemon.PrintNotifications;org.gnome.SettingsDaemon.Rfkill;org.gnome.SettingsDaemon.ScreensaverProxy;org.gnome.SettingsDaemon.Sharing;org.gnome.SettingsDaemon.Smartcard;org.gnome.SettingsDaemon.Sound;org.gnome.SettingsDaemon.Wacom;org.gnome.SettingsDaemon.XSettings;\' >> /usr/share/gnome-session/sessions/jade-gui.session'])
# Update display manager configuration
exec_chroot(['bash', '-c', 'rm -rf /usr/share/xsessions/*'])
exec_chroot(['bash', '-c', 'rm -rf /usr/share/wayland-sessions/*'])
exec_chroot(
['bash', '-c', 'echo "[Theme]" > /etc/sddm.conf.d/default.conf'])
['bash', '-c', 'echo \'[Desktop Entry]\' >> /usr/share/wayland-sessions/jade-gui.desktop'])
exec_chroot(
['bash', '-c', 'echo "Current=breeze" >> /etc/sddm.conf.d/default.conf'])
exec_chroot(['rm', '-f', '/etc/gdm/custom.conf'])
# Create ~/.local/share/applications with right perms
exec_chroot(['sudo', '-u', user['name'], 'mkdir', '-p',
f'/home/{user["name"]}/.local/share/applications'])
['bash', '-c', 'echo \'Type=Application\' >> /usr/share/wayland-sessions/jade-gui.desktop'])
exec_chroot(
['bash', '-c', 'echo \'Name=First Setup\' >> /usr/share/wayland-sessions/jade-gui.desktop'])
exec_chroot(
['bash', '-c', 'echo \'Exec=gnome-shell --builtin --mode=jade-gui\' >> /usr/share/wayland-sessions/jade-gui.desktop'])
exec_chroot(
['bash', '-c', 'echo \'X-GNOME-AutoRestart=true\' >> /usr/share/wayland-sessions/jade-gui.desktop'])
exec_chroot(
['bash', '-c', 'echo \'X-GNOME-Autostart-Phase=DisplayServer\' >> /usr/share/wayland-sessions/jade-gui.desktop'])
exec_chroot(
['bash', '-c', 'echo \'X-GNOME-Provides=panel;windowmanager;\' >> /usr/share/wayland-sessions/jade-gui.desktop'])
exec_chroot(
['bash', '-c', 'echo \'X-GNOME-Autostart-Notify=true\' >> /usr/share/wayland-sessions/jade-gui.desktop'])
########################################################################################

192
blend-postinst Executable file
View file

@ -0,0 +1,192 @@
#!/usr/bin/env python3
# Copyright (C) 2023 Rudra Saraswat
# Licensed under GPL-3.0.
# Error codes
# 1 - Partitioning error
# 3 - Username not allowed
import os
import sys
import json
import yaml
import signal
import subprocess
if os.environ.get('TESTING_INST') == 'true':
testing = True
else:
testing = False
# State variables
mountpoints = []
########################################################################################
# Helper utils
def preexec():
signal.signal(signal.SIGHUP, signal.SIG_IGN)
signal.signal(signal.SIGINT, signal.SIG_IGN)
signal.signal(signal.SIGQUIT, signal.SIG_IGN)
def exec(cmd):
if testing:
print(' '.join(cmd))
else:
subprocess.call(cmd, shell=False, stdout=sys.stdout,
stderr=sys.stderr, preexec_fn=preexec)
def enable_service(service):
exec(['systemctl', 'enable', service])
def enable_user_service(service):
exec(['systemctl', '--global', 'enable', service])
def mount(part, path):
exec(['mount', part, path])
def mkdir(path):
exec(['mkdir', '-p', path])
########################################################################################
# Setup base
def inst_system_config(config):
system_config = {
'repo': 'https://pkg-repo.blendos.co',
'impl': 'http://github.com/blend-os/tracks/raw/main',
'track': 'default-gnome'
}
if 'NVIDIA' in subprocess.check_output(['lspci']).decode('utf-8'):
system_config['packages'] = [
'nvidia-dkms',
'nvidia-prime',
'switcheroo-control'
]
system_config['services'] = [
'switcheroo-control'
]
if testing == False:
with open('/system.yaml') as system_config_file:
yaml.dump(system_config, system_config_file)
else:
print(system_config)
########################################################################################
# Locale
def inst_locale(config):
# Set locale
exec(['bash', '-c', 'echo \'en_US.UTF-8 UTF-8\' > /etc/locale.gen'])
first_locale = True
for locale in config['locale']['locale']:
if locale != 'en_US.UTF-8 UTF-8':
exec(
['bash', '-c', f'echo \'{locale}\' >> /etc/locale.gen'])
if first_locale:
exec(
['bash', '-c', f'echo \'LANG={locale.split()[0]}\' > /etc/locale.conf'])
first_locale = False
exec(['locale-gen'])
# Set keyboard layout
exec(
['bash', '-c', f'echo \'KEYMAP={config["locale"]["keymap"]}\' > /etc/vconsole.conf'])
# Set timezone
exec(
['ln', '-sf', f'/usr/share/zoneinfo/{config["locale"]["timezone"]}', '/etc/localtime'])
########################################################################################
# Networking
def inst_networking(config):
# Set hostname
exec(
['bash', '-c', f'echo \'{config["networking"]["hostname"]}\' > /etc/hostname'])
# Create hosts file
exec(['bash', '-c', 'echo \'127.0.0.1 localhost\' > /etc/hosts'])
if config['networking']['ipv6']:
# Enable ipv6
exec(['bash', '-c', 'echo \'::1 localhost\' > /etc/hosts'])
########################################################################################
# Users
def inst_users(config):
exec_chroot(['bash', '-c', 'userdel -r blend &>/dev/null'])
for home_dir in os.listdir('/home'):
exec(['rm', '-rf', '/home/' + home_dir])
# Add users
for user in config['users']:
exec(['useradd', '-m', '-s', '/bin/bash', user['name']])
exec(['usermod', '-c', user['fullname'], user['name']])
exec(
['bash', '-c', f'echo \'{user["name"]}:{user["password"]}\' | chpasswd'])
exec(['usermod', '-aG', 'wheel', user['name']])
# Add AccountsService user file
mkdir('/mnt/var/lib/AccountsService/users')
exec(
['bash', '-c', f'echo "[User]" > /var/lib/AccountsService/users/{user["name"]}'])
exec(
['bash', '-c', f'echo "SystemAccount=false" >> /var/lib/AccountsService/users/{user["name"]}'])
# Create ~/.local/share/applications with right perms
exec(['sudo', '-u', user['name'], 'mkdir', '-p',
f'/home/{user["name"]}/.local/share/applications'])
########################################################################################
# Akshara
def inst_akshara():
exec(['akshara', 'update'])
########################################################################################
signal.signal(signal.SIGHUP, signal.SIG_IGN)
signal.signal(signal.SIGINT, signal.SIG_IGN)
signal.signal(signal.SIGQUIT, signal.SIG_IGN)
try:
if sys.argv[1] == 'config' and os.path.isfile(sys.argv[2]):
with open(sys.argv[2]) as config_file:
config = json.load(config_file)
inst_system_config(config)
inst_locale(config)
inst_networking(config)
inst_users(config)
inst_akshara()
print()
print('===========')
print('Successful.')
sys.exit()
except IndexError:
pass