# SPDX-FileCopyrightText: no
# SPDX-License-Identifier: CC0-1.0
#
# Configuration for the shell process job.
#
# Executes a list of commands found under the key *script*.
# If the top-level key *dontChroot* is true, then the commands
# are executed in the context of the live system, otherwise
# in the context of the target system. In all of the commands,
# the following variable expansions will take place:
#  - `ROOT` is replaced by the root mount point of the **target**
#    system from the point of view of the command (when run in the target
#    system, e.g. when *dontChroot* is false, that will be `/`).
#  - `USER` is replaced by the username, set on the user page.
#
# Variables are written as `${var}`, e.g. `${ROOT}`.
#
# The (global) timeout for the command list can be set with
# the *timeout* key. The value is a time in seconds, default
# is 30 seconds if not set. The timeout **must** be tuned, either
# globally or per-command (see below in the description of *script*),
# to the load or expected running-time of the command.
#
#  - Setting a timeout of 30 for a `touch` command is probably exessive
#  - Setting a timeout of 1 for a `touch` command might be low,
#    on a slow disk where touch needs to be loaded from CDROM
#  - Setting a timeout of 30 for a 1GB download is definitely low
#  - Setting a timeout of 3600 for a 1GB download is going to leave
#    the user in uncertainty for a loooong time.
#
# If a command starts with "-" (a single minus sign), then the
# return value of the command following the - is ignored; otherwise,
# a failing command will abort the installation. This is much like
# make's use of - in a command.
#
# The value of *script* may be:
#   - a single string; this is one command that is executed.
#   - a single object (this is not useful).
#   - a list of items; these are executed one at a time, by
#     separate shells (/bin/sh -c is invoked for each command).
#     Each list item may be:
#     - a single string; this is one command that is executed.
#     - a single object, specifying a key *command* and (optionally)
#       a key *timeout* to set the timeout for this specific
#       command differently from the global setting.
#
# Using a single object is not useful because the same effect can
# be obtained with a single string and a global timeout, but when
# there are multiple commands to execute, one of them might have
# a different timeout than the others.
#
# To change the description of the job, set the *name* entries in *i18n*.
---
# Set to true to run in host, rather than target system
# dontChroot: false
# Tune this for the commands you're actually running
# timeout: 10

# Script may be a single string (because false returns an error exit
# code, this will trigger a failure in the installation):
#
# script: "/usr/bin/false"

# Script may be a list of strings (because false returns an error exit
# code, **but** the command starts with a "-", the error exit is
# ignored and installation continues):
#
# script:
#     - "-/usr/bin/false"
#     - "/bin/ls"
#     - "/usr/bin/true"

# Script may be a list of items (if the touch command fails, it is
# ignored; the slowloris command has a different timeout from the
# other commands in the list):
# script:
#    - "-touch ${ROOT}/tmp/thingy"
#    - "/usr/bin/true"
#    - command: "/usr/local/bin/slowloris"
#      timeout: 3600

# You can change the description of the job (as it is displayed in the
# progress bar during installation) by defining an *i18n* key, which
# has a *name* field and optionally, translations as *name[lang]*.
#
# Without a translation here, the default name from the source code
# is used, "Shell Processes Job".
#

i18n:
  name: "Final cleaning"
  name[ru]: "Финальная очистка"

dontChroot: false

timeout: 3600

script:
  # - "-rm /root/.config/{qt5ct,Kvantum,dconf}"
  # - "-rm /root/{,.[!.],..?}*"
  #
  # - "-rm /etc/resolv.conf"
  # - "-ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf"
  # - "-touch /etc/resolv.conf"
  # - "-rm /etc/skel/.bash_profile"
  # - "-rm /home/${USER}/.bash_profile"
  - "-rm -rf /etc/pacman-cache.conf"
  - "-rm -rf /etc/pacman-std.conf"
  - "-rm -rf /etc/systemd/journald.conf.d"
  - "-rm -rf /etc/systemd/logind.conf.d"
  - "-rm -rf /etc/systemd/system/getty@tty1.service.d"
  - "-rm -rf /home/liveuser"
  - "-rm -rf /opt/extra-drivers"
  - "-rm -rf /usr/local/share/livecd-sound"
  - "-rm -rf /usr/share/packages"
  - "-rm /etc/initcpio"
  - "-rm /etc/polkit-1/rules.d/49-nopasswd-calamares.rules"
  - "-rm /etc/polkit-1/rules.d/49-nopasswd_global.rules"
  - "-rm /etc/skel/{.xsession,.xprofile,.xinitrc}"
  - "-rm /etc/sudoers.d/g_wheel"
  - "-rm /etc/systemd/system/display-manager.service"
  - "-rm /etc/systemd/system/etc-pacman.d-gnupg.mount"
  - "-rm /etc/systemd/system/intel.service"
  - "-rm /root/{.automated_script.sh,.zlogin,.xinitrc,.xsession,.xprofile,.wget-hsts,.screenrc,.ICEauthority}"
  - "-rm /usr/bin/GPU-Intel-installer"
  - "-rm /var/lib/NetworkManager/NetworkManager.state"
  - "-rm /version"
  - "-rm /{gpg.conf,gpg-agent.conf,pubring.gpg,secring.gpg}"

  - "-runuser ${USER} -c 'cp -rf /etc/skel/. /home/${USER}/.'"
  - "-runuser ${USER} -c 'rm -rf /home/${USER}/{.xsession,.xprofile,.xinitrc}'"

  - '-sed -e "/HandleSuspendKey=ignore/d" -e "/HandleHibernateKey=ignore/d" -e "/HandleLidSwitch=ignore/d" -i /etc/systemd/logind.conf'
  - '-sed -e "s/.*pam_wheel\.so/#&/" -i /etc/pam.d/su'
  - '-sed -e "s/volatile/auto/g" -i /etc/systemd/journald.conf 2>>/tmp/.errlog'

  - "-rm /etc/mkinitcpio-archiso.conf"
  - "-rm /etc/ssh/sshd_config.d/10-archiso.conf"
  - "-rm /etc/systemd/resolved.conf.d/archiso.conf"
  - "-rm /etc/systemd/system/reflector.service.d/archiso.conf"
  - "-rm /etc/mkinitcpio.conf.d/archiso.conf"
  - '-find /usr/lib/initcpio -name archiso* -type f -exec rm "{}" \;'

  - "-rm -rf /root/archives"
  - "-rm -rf /root/packages"

  - command: "-/usr/local/bin/dmcheck"
  - "-rm -rf /usr/local/bin/*"

  - '-sed -i /etc/sddm.conf.d/kde_settings.conf -e "s/liveuser//"'

  - "-rm /etc/systemd/system/mount-data-flash.service"
  - "-rm /etc/systemd/system/multi-user.target.wants/mount-data-flash.service"
  - "-rm /etc/systemd/system/dnscrypt-proxy-resolv.conf.service"
  - "-rm /etc/systemd/system/network-online.target.wants/dnscrypt-proxy-resolv.conf.service"
