1010set -e -u
1111
1212
13- # Default value
1413# Default value
1514# All values can be changed by arguments.
1615password=alter
@@ -56,45 +55,15 @@ kernel_mkinitcpio_profile="${kernel_config_line[2]}"
5655# Make it compatible with previous code
5756unset OPTIND OPTARG arg
5857
58+ # Load functions
59+ source " /root/functions.sh"
5960
60- # Check whether true or false is assigned to the variable.
61- function check_bool() {
62- local
63- case $( eval echo ' $' ${1} ) in
64- true | false) : ;;
65- * ) echo " The value ${boot_splash} set is invalid" >&2 ;;
66- esac
67- }
6861
62+ # Check bool type
6963check_bool boot_splash
7064check_bool debug
7165
7266
73- # Delete file only if file exists
74- # remove <file1> <file2> ...
75- function remove () {
76- local _list
77- local _file
78- _list=($( echo " $@ " ) )
79- for _file in " ${_list[@]} " ; do
80- if [[ -f ${_file} ]]; then
81- rm -f " ${_file} "
82- elif [[ -d ${_file} ]]; then
83- rm -rf " ${_file} "
84- fi
85- echo " ${_file} was deleted."
86- done
87- }
88-
89-
90- function installedpkg () {
91- if pacman -Qq " ${1} " 1> /dev/null 2> /dev/null; then
92- return 0
93- else
94- return 1
95- fi
96- }
97-
9867# Enable and generate languages.
9968sed -i ' s/#\(en_US\.UTF-8\)/\1/' /etc/locale.gen
10069if [[ ! " ${localegen} " = " en_US\\ .UTF-8\\ " ]]; then
@@ -113,21 +82,6 @@ if [[ -f "/etc/skel/Desktop/calamares.desktop" ]]; then
11382fi
11483
11584
116- # user_check <name>
117- function user_check () {
118- if [[ ! -v 1 ]]; then return 2; fi
119- getent passwd " ${1} " > /dev/null
120- }
121-
122- # Execute only if the command exists
123- # run_additional_command [command name] [command to actually execute]
124- run_additional_command () {
125- if [[ -f " $( type -p " ${1} " 2> /dev/null) " ]]; then
126- shift 1
127- eval " ${@ } "
128- fi
129- }
130-
13185usermod -s " ${usershell} " root
13286cp -aT /etc/skel/ /root/
13387if [[ -f " $( type -p " xdg-user-dirs-update" 2> /dev/null) " ]]; then LC_ALL=C LANG=Cxdg-user-dirs-update; fi
@@ -136,40 +90,8 @@ echo -e "${password}\n${password}" | passwd root
13690# Allow sudo group to run sudo
13791sed -i ' s/^#\s*\(%sudo\s\+ALL=(ALL)\s\+ALL\)/\1/' /etc/sudoers
13892
139- # Create a user.
140- # create_user <username> <password>
141- function create_user () {
142- local _password
143- local _username
144-
145- _username=${1}
146- _password=${2}
147-
148- set +u
149- if [[ -z " ${_username} " ]]; then
150- echo " User name is not specified." >&2
151- return 1
152- fi
153- if [[ -z " ${_password} " ]]; then
154- echo " No password has been specified." >&2
155- return 1
156- fi
157- set -u
158-
159- if ! user_check " ${_username} " ; then
160- useradd -m -s ${usershell} ${_username}
161- groupadd sudo
162- usermod -U -g ${_username} ${_username}
163- usermod -aG sudo ${_username}
164- usermod -aG storage ${_username}
165- cp -aT /etc/skel/ /home/${_username} /
166- fi
167- chmod 700 -R /home/${_username}
168- chown ${_username} :${_username} -R /home/${_username}
169- echo -e " ${_password} \n${_password} " | passwd ${_username}
170- set -u
171- }
17293
94+ # Create user
17395create_user " ${username} " " ${password} "
17496
17597
@@ -281,23 +203,6 @@ sed -i -r "s/(GRUB_DISTRIBUTOR=).*/\1\"${grub_os_name}\"/g" "/etc/default/grub"
281203run_additional_command " gtk-update-icon-cache -f /usr/share/icons/hicolor"
282204
283205
284- # systemctl helper
285- # Execute the subcommand only when the specified unit is available.
286- # Usage: _systemd_service <systemctl subcommand> <service1> <service2> ...
287- _systemd_service (){
288- local _service
289- local _command=" ${1} "
290- shift 1
291- for _service in " ${@ } " ; do
292- # https://unix.stackexchange.com/questions/539147/systemctl-check-if-a-unit-service-or-target-exists
293- if (( "$(systemctl list- unit- files "${_service} " | wc - l)" > 3 )) ; then
294- systemctl ${_command} " ${_service} "
295- else
296- echo " ${_service} was not found" >&2
297- fi
298- done
299- }
300-
301206# Enable graphical.
302207_systemd_service set-default graphical.target
303208
0 commit comments