summaryrefslogtreecommitdiff
path: root/configs/profile/root-image/root/customize_root_image.sh
blob: c60222054ec7d11cfbc1c6943c337f6151bcc59a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/bash

readonly DEV_RELEASE=1 # 1 for development builds - 0 for production builds
readonly REPOS='libre core extra community pcr'
readonly SYSTEMD_SERVICES_ALL="choose-mirror.service \
                               multi-user.target     \
                               pacman-init.service   "
readonly SYSTEMD_SERVICES_GUI="NetworkManager.service"
readonly OPENRC_SERVICES_ALL="dbus           \
                              haveged        \
                              NetworkManager \
                              pacman-init    "
readonly OPENRC_SERVICES_GUI="alsasound \
                              elogind   "
readonly DEFAULT_SHELL=/bin/bash
readonly NETINSTALL_MSG="To install Parabola, the system must be connected to the internet."
readonly COMPLETE_MSG="This ISO is capable of installing a complete Parabola system\n\
>>>>without a connection to the internet. If you would like to fetch\n\
>>>>the latest packages from the internet, run the following command\n\
>>>>before beginning the install:\n\
        # cp /etc/pacman-online.conf /etc/pacman.conf"
[ "${enable_offline_install}" == 'false' ] && readonly NETWORK_MOTD_MSG=${NETINSTALL_MSG} || \
                                              readonly NETWORK_MOTD_MSG=${COMPLETE_MSG}
readonly ROOT_SKEL_FILES="/etc/skel/.automated_script.sh \
                          /etc/skel/.bash_logout         \
                          /etc/skel/.bash_profile        "
readonly LIVE_USER=parabola
readonly LIVE_USER_GROUPS="adm,audio,floppy,log,network,rfkill,scanner,storage,optical,power,wheel"
readonly OPENRC_USER_GROUPS="disk,sys"
[[ "${iso_init}" == 'openrc' ]] && readonly USER_GROUPS="${LIVE_USER_GROUPS},${OPENRC_USER_GROUPS}" ||
                                   readonly USER_GROUPS="${LIVE_USER_GROUPS}"
[ "${enable_offline_install}" == 'true' ] && readonly INSTALL_TYPE="Complete"   || \
                                             readonly INSTALL_TYPE="NetInstall"
readonly WELCOME_TITLE="Parabola ${iso_init}/${iso_gui} Edition - (${INSTALL_TYPE})"


set -e -u

# configure locales
ln -sf /usr/share/zoneinfo/UTC   /etc/localtime
sed -i 's/#\(en_US\.UTF-8\)/\1/' /etc/locale.gen
sed -i 's/#\(es_ES\.UTF-8\)/\1/' /etc/locale.gen
sed -i 's/#\(gl_ES\.UTF-8\)/\1/' /etc/locale.gen
sed -i 's/#\(pt_BR\.UTF-8\)/\1/' /etc/locale.gen
sed -i 's/#\(pl_PL\.UTF-8\)/\1/' /etc/locale.gen
sed -i 's/#\(it_IT\.UTF-8\)/\1/' /etc/locale.gen
sed -i 's/#\(fr_FR\.UTF-8\)/\1/' /etc/locale.gen
sed -i 's/#\(eo\)/\1/'           /etc/locale.gen
locale-gen

# configure sudo
chmod 750 /etc/sudoers.d
chmod 440 /etc/sudoers.d/g_wheel

# configure pacman
sed -i "s|#Server|Server|" /etc/pacman.d/mirrorlist
if   [[ "${enable_offline_install}" == 'true' ]]
then cat /etc/pacman-offline.conf                                  > /etc/pacman-online.conf
     for repo in ${REPOS}
     do echo -e "\n[${repo}]\nInclude = /etc/pacman.d/mirrorlist" >> /etc/pacman-online.conf
     done
     cp /etc/pacman-offline.conf                                     /etc/pacman.conf
else cp /usr/share/pacman/defaults/pacman.conf.${arch}               /etc/pacman.conf
     rm /etc/pacman-*.conf
fi

# KLUDGE begin # TODO: https://labs.parabola.nu/issues/1527
echo "Server = https://parabola.isacdaavid.info:8081/\$repo/os/\$arch" > /etc/pacman.d/mirrorlist
# KLUDGE end

# configure services
if   [[ "${iso_init}" == 'systemd' ]]
then systemctl enable ${SYSTEMD_SERVICES_ALL}
     # delete files that are specific to other init systems
     rm /etc/conf.d/agetty.tty1
     rm /etc/conf.d/hostname
     rm /etc/init.d/pacman-init
     rm /etc/X11/Xwrapper.config

     # enable services
     [[ "${iso_gui}" != 'cli' ]] && systemctl enable ${SYSTEMD_SERVICES_GUI}
elif [[ "${iso_init}" == 'openrc' ]]
     # delete files that are specific to other init systems
     rm /etc/hostname
     rm /etc/systemd/scripts/choose-mirror
     rm /etc/systemd/system/choose-mirror.service
     rm /etc/systemd/system/etc-pacman.d-gnupg.mount
     rm /etc/systemd/system/getty@tty1.service.d/autologin.conf
     rm /etc/systemd/system/pacman-init.service

     # enable services
     for service in ${OPENRC_SERVICES_ALL} ; do  rc-update add ${service} default ; done ;
     if [[ "${iso_gui}" != 'cli' ]]
     then for service in ${OPENRC_SERVICES_GUI} ; do  rc-update add ${service} default ; done ;
     fi

     # create the dbus user and group if it does not exist
     if [[ "$(grep 'dbus' /etc/group )" = "" ]] ; then groupadd -g 81 dbus ; fi ;
     if [[ "$(grep 'dbus' /etc/passwd)" = "" ]] ; then useradd -r -s /sbin/nologin -g 81 -u 81 dbus ; fi ;
fi

# configure root user
usermod -s ${DEFAULT_SHELL} root 2> /dev/null

# configure CLI login session
sed -i "s|_EDITION_TITLE_|${iso_title}|"                                    /etc/motd
sed -i "s|_NETWORK_MOTD_MSG_|${NETWORK_MOTD_MSG}| ; s|^>>>>\(.*\)|    \1|g" /etc/motd
if   [[ "${iso_gui}" == 'cli' ]]
then cp ${ROOT_SKEL_FILES} /root/
     sed -i "s|_DESKTOP_SESSION_||" /root/.bash_profile

else # configure GUI login session and live user
     [[ -n "$(id ${LIVE_USER} 2> /dev/null)" ]] && userdel -r ${LIVE_USER} 2> /dev/null
     useradd -m -p "" -g users -G "${USER_GROUPS}" -s ${DEFAULT_SHELL} ${LIVE_USER}
     if   [[ "${iso_init}" == 'systemd' ]]
     then sed -i "s|--autologin root|--autologin ${LIVE_USER}|" /etc/systemd/system/getty@tty1.service.d/autologin.conf
     else sed -i "s|--autologin root|--autologin ${LIVE_USER}|" /etc/conf.d/agetty.tty1
     fi

     # configure desktop environment
     sed -i "s|_EDITION_TITLE_|${WELCOME_TITLE}|" /home/${LIVE_USER}/.config/autostart/autostart.sh
     sed -i "s|--question|--info|"                /home/${LIVE_USER}/.config/autostart/autostart.sh
     sed -i "s|--cancel-label=.*|\&|"             /home/${LIVE_USER}/.config/autostart/autostart.sh

     if   [[ "${iso_gui}" == 'lxde' ]]
     then rm -f /etc/xdg/autostart/octopi-notifier.desktop 2> /dev/null
          sed -i "s|_DESKTOP_SESSION_|LXDE|" /home/${LIVE_USER}/.bash_profile
          sed -i "s|_DESKTOP_SESSION_|LXDE|" /home/${LIVE_USER}/.dmrc
     elif [[ "${iso_gui}" == 'mate' ]]
     then sed -i "s|_DESKTOP_SESSION_|mate|" /home/${LIVE_USER}/.bash_profile
          sed -i "s|_DESKTOP_SESSION_|mate|" /home/${LIVE_USER}/.dmrc
     else echo "invalid \$iso_gui for _DESKTOP_SESSION_ '${iso_gui}'"
          exit 1
     fi

     # development builds - set DEV_RELEASE=0 for production builds
     (($DEV_RELEASE)) && source /root/customize_root_image-dev.sh 2> /dev/null
fi
# development builds - set DEV_RELEASE=0 for production builds
(($DEV_RELEASE))      && rm     /root/customize_root_image-dev.sh 2> /dev/null