Skip to content
This repository was archived by the owner on Jul 13, 2022. It is now read-only.

Allow user to install additional packages from file #260

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The only thing you need is one USB bootable device of [Arch Linux](https://mir.a
|:------ |:-------- |:----------- |:------- |
|_`-l`_, _`--lang`_|`language`|set installer language|_`sh archboot -l french`_|
|_`-k`_, _`--keyboard`_|`keyboard`|run loadkeys on start|_`sh archboot -k azerty`_|
|_`-f`_, _`--file`_|`file.txt`|install packages from file|_`sh archboot -f file.txt`_|
|_`-h`_, _`--help`_||show help and usage|_`sh archboot --help`_|

* > _`--lang` sets only installer language (archboot supports all [languages](https://github.com/grm34/archboot/wiki/Language-code) available in Arch Linux)._
Expand Down
22 changes: 11 additions & 11 deletions STATS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

File|blank|comment|code
:-------|-------:|-------:|-------:
archboot|82|121|284
archboot|85|124|298
src/arch/partitioning|86|87|230
src/arch/user|48|53|153
src/arch/base|30|39|94
src/arch/base|31|36|104
src/arch/display|23|29|66
src/arch/bootloader|23|25|57
src/arch/gpu_driver|20|22|52
Expand All @@ -14,36 +14,36 @@ src/arch/firmware|14|13|47
src/arch/desktop|11|17|25
src/arch/mounting|9|15|13
--------|--------|--------|--------
SUM:|368|443|1072
SUM:|372|443|1096

### Config files

File|blank|comment|code
:-------|-------:|-------:|-------:
locale/english|13|15|130
locale/german|13|15|130
locale/french|13|15|130
src/apps/desktop_apps|20|24|24
locale/english|13|15|131
locale/german|13|15|131
locale/french|13|15|131
src/conf/xinitrc|8|8|24
src/apps/desktop_apps|20|24|24
src/apps/gpu_apps|12|15|17
src/apps/system_apps|12|14|17
src/apps/display_apps|8|10|10
--------|--------|--------|--------
SUM:|99|116|482
SUM:|99|116|485

### Markdown files

File|blank|comment|code
:-------|-------:|-------:|-------:
README.md|25|0|49
.github/CODE_OF_CONDUCT.md|35|0|49
README.md|25|0|48
STATS.md|5|0|44
.github/CONTRIBUTING.md|10|0|29
.github/PULL_REQUEST_TEMPLATE.md|9|0|20
.github/ISSUE_TEMPLATE/feature_request.md|2|0|9
.github/ISSUE_TEMPLATE/update.md|1|0|8
.github/ISSUE_TEMPLATE/bug_report.md|1|0|8
.github/ISSUE_TEMPLATE/question.md|1|0|8
.github/ISSUE_TEMPLATE/update.md|1|0|8
.github/ISSUE_TEMPLATE/config.yml|0|0|1
--------|--------|--------|--------
SUM:|89|0|224
SUM:|89|0|225
48 changes: 34 additions & 14 deletions archboot
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,27 @@ _help() {
echo -e "${BLUE}
Arch Linux Installer - A script made with love by ${AUTHOR}

${BOLD}Usage: ${NC}sh ${APPNAME} [options]
${BOLD}Usage: ${NC}sh ${APPNAME} [option] [argument]

${BOLD}Options${NC}
-h, --help show this help message
-l, --lang set installer language
-k, --keyboard set keyboard layout
-f, --file install packages from file

${BOLD}Language${NC}
-l, --lang english
french
${BOLD}Installer language${NC}
-l, --lang english (by @${AUTHOR})
french (by @${AUTHOR})
german (by @At1768)

${BOLD}Keyboard${NC}
-k, --keyboard keyboard layout
(run loadkeys on start)
(e.q., --keyboard fr)
${BOLD}Keyboard layout${NC}
-k, --keyboard keyboard code
language code
country code

${BOLD}Additional packages${NC}
-f, --file packages_file_list
(AUR packages available)

${BOLD}For more information, see the wiki: \
${CYAN}<http://tiny.cc/archboot-wiki>${NC}"
Expand Down Expand Up @@ -198,7 +203,8 @@ ${AUTHOR} ${RED}under ${LICENSE} ${GREEN}>>>${NC}"
# HELP AND USAGE
# ============================================================================
# Here we manage help and usage to properly describe and run archboot.
# The only options are to select script language and to load keyboard layout.
# The only options are to select script language, to load keyboard layout
# and to allow installation of additional packages from a file.
# Then we ensure not running script from repository folder to avoid deletes.
#
# Usage: sh archboot [options] (e.g., sh archboot -l french -k fr)
Expand All @@ -211,12 +217,13 @@ for OPT in "${@}"; do
"--help") set -- "${@}" "-h"; break;;
"--lang") set -- "${@}" "-l";;
"--keyboard") set -- "${@}" "-k";;
"--file") set -- "${@}" "-f";;
*) set -- "${@}" "${OPT}"
esac
done

### Option processing
while getopts ':hl:k:' OPTION; do
while getopts ':hl:k:f:' OPTION; do
case ${OPTION} in

# Help (-h, --help)
Expand All @@ -226,7 +233,7 @@ while getopts ':hl:k:' OPTION; do
l) if [[ ${OPTARG} =~ ^(english$|french$|german$) ]]; then
ARCHBOOT_LANG="${OPTARG}"
else
echo -e "${RED}Error:${NC} invalid language '${OPTARG}'"
echo -e "${RED}Error:${NC} invalid language \"${OPTARG}\""
_help; rm -f old_vars.log; _exit_msg; exit 1
fi;;

Expand All @@ -235,16 +242,24 @@ while getopts ':hl:k:' OPTION; do
if [[ ${STATUS} -ne 1 ]]; then
export KEYMAP="${OPTARG}"
else
echo -e "${RED}Error:${NC} invalid keyboard '${OPTARG}'"
echo -e "${RED}Error:${NC} invalid keyboard \"${OPTARG}\""
_help; rm -f old_vars.log; _exit_msg; exit 1
fi;;

# Packages file list (-f, --file)
f) if [[ -f ${OPTARG} ]]; then
export PACKAGES_FILE="${OPTARG}"
else
echo -e "${RED}Error:${NC} invalid file \"${OPTARG}\""
_help; rm -f old_vars.log; _exit_msg; exit 1
fi;;

# Missing argument
:) echo -e "${RED}Error:${NC} missing argument for -${OPTARG}"
:) echo -e "${RED}Error:${NC} missing argument for \"-${OPTARG}\""
_help; rm -f old_vars.log; _exit_msg; exit 1;;

# Invalid option
\?) echo -e "${RED}Error:${NC} invalid option -${OPTARG}"
\?) echo -e "${RED}Error:${NC} invalid option \"-${OPTARG}\""
_help; rm -f old_vars.log; _exit_msg; exit 1
esac
done
Expand Down Expand Up @@ -435,6 +450,11 @@ _install_display_manager; _enable_user_rights) 2>&1 | tee -a "${INSTALL_LOG}"
(_install_AUR_helper) 2>&1 | tee -a "${INSTALL_LOG}"
fi

### Install user personal packages
if [[ ${PACKAGES_FILE} ]]; then
(_install_personal_packages) 2>&1 | tee -a "${INSTALL_LOG}"
fi

### Clean cache and unused dependencies (src/arch/base)
(_clean_dependencies) 2>&1 | tee -a "${INSTALL_LOG}"

Expand Down
1 change: 1 addition & 0 deletions locale/english
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export MSG_INSTALL_NTFS="Installing NTFS filesystem support"
export MSG_BOOT_HOOKS="Adding kernel parameters for bootloader"
export MSG_SET_USER="Setting user"
export MSG_INSTALL_AUR="Installing AUR Helper"
export MSG_INSTALL_ADDONS="Installing user personal packages"
export MSG_CLEAN_CACHE="Cleaning cache and unused dependencies"

### src/arch/bootloader
Expand Down
1 change: 1 addition & 0 deletions locale/french
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export MSG_INSTALL_NTFS="Installation du support pour le système de fichiers NT
export MSG_BOOT_HOOKS="Ajout des paramètres kernel pour le bootloader"
export MSG_SET_USER="Création de l'utilisateur"
export MSG_INSTALL_AUR="Installation d'un AUR Helper"
export MSG_INSTALL_ADDONS="Installation des paquets personnels de l'utilisateur"
export MSG_CLEAN_CACHE="Nettoyage du cache et des dépendences inutiles"

### src/arch/bootloader
Expand Down
1 change: 1 addition & 0 deletions locale/german
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export MSG_INSTALL_NTFS="Installiere Unterstützung für NTFS Dateisystem"
export MSG_BOOT_HOOKS="Füge Kernelparameter für systemd-boot hinzu"
export MSG_SET_USER="Erstelle Benutzer"
export MSG_INSTALL_AUR="Installiere AUR-Helper"
export MSG_INSTALL_ADDONS="Installing user personal packages"
export MSG_CLEAN_CACHE="Bereinige Cache und nicht benötigte Abhängigkeiten"

### src/arch/bootloader
Expand Down
40 changes: 24 additions & 16 deletions src/arch/base
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Then we create user account and we allow him to run commands with sudo.
#
# AUR Helpers (optional) <yay> <pamac-aur> <trizen> <pacaur> <pakku> <pikaur>
#
# Installation of additional packages from a file is available as an option.
# Last function is used to remove unused packages and to clean pacman cache.
#
# All steps are described in the official documentation:
Expand Down Expand Up @@ -121,27 +121,35 @@ EOF
_install_AUR_helper() {
_info "${MSG_INSTALL_AUR} (${AUR_HELPER,,})"

### Allow user to run sudo without passwd
sed -i -e \
"s/${USER_NAME} ALL=(ALL) ALL/${USER_NAME} ALL=(ALL) NOPASSWD: ALL/g" \
/mnt/etc/sudoers
### Clone and install AUR Helper
_allow_user_sudoers "_chroot 'cd /home/${USER_NAME} && sudo -u \
${USER_NAME} git clone https://aur.archlinux.org/${AUR_HELPER,,}.git && cd \
${AUR_HELPER,,} && sudo -u ${USER_NAME} makepkg --noconfirm --needed -sic'"

### Clean AUR Helper sources
rm -rf "/mnt/home/${USER_NAME}/${AUR_HELPER,,}"
echo "-> ${MSG_DONE}"
}

### Clone AUR Helper from aur.archlinux.org
_chroot "cd /home/${USER_NAME} && \
sudo -u ${USER_NAME} git clone https://aur.archlinux.org/${AUR_HELPER,,}.git"
_install_personal_packages() {
_info "${MSG_INSTALL_ADDONS}"

### Install AUR Helper
_chroot "cd /home/${USER_NAME}/${AUR_HELPER,,} && sudo -u ${USER_NAME} \
makepkg --noconfirm --needed -sic"
if [[ ${AUR_HELPER} ]]; then
_allow_user_sudoers \
"_chroot '${AUR_HELPER,,} --noconfirm --needed -S - < ${PACKAGES_FILE}'"

### Deny user to run sudo without passwd
else
_chroot "pacman --noconfirm --needed -S - < ${PACKAGES_FILE}"
fi
echo "-> ${MSG_DONE}"
}

_allow_user_sudoers() {
sed -i -e \
"s/${USER_NAME} ALL=(ALL) ALL/${USER_NAME} ALL=(ALL) NOPASSWD: ALL/g" \
/mnt/etc/sudoers; ${1}; sed -i -e \
"s/${USER_NAME} ALL=(ALL) NOPASSWD: ALL/${USER_NAME} ALL=(ALL) ALL/g" \
/mnt/etc/sudoers

### Clean AUR Helper sources
rm -rf "/mnt/home/${USER_NAME}/${AUR_HELPER,,}"
echo "-> ${MSG_DONE}"
}

_clean_dependencies() {
Expand Down
3 changes: 2 additions & 1 deletion src/arch/firmware
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ _firmware() {
_info "${MSG_GET_FW}"

### UEFI
if [ -d /sys/firmware/efi/efivars ]; then
EFI_TYPE=$( cat /sys/firmware/efi/fw_platform_size )
if [[ -d /sys/firmware/efi/efivars && ${EFI_TYPE} == "64" ]]; then
export FIRMWARE="UEFI"
export PART_TABLE="GPT"
export PART_CODE="g"
Expand Down
36 changes: 23 additions & 13 deletions src/arch/partitioning
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ _default_partitioning_scheme() {
umount -fv "/dev/${PART}"; sleep 1
fi
_info "${MSG_DELETE_PART} /dev/${PART}"
printf "d\n\nw\n" | fdisk --wipe=always "${DRIVE}"
printf "d\n\nw" | fdisk --wipe=always "${DRIVE}"
partprobe "${DRIVE}" && sleep 1
done
fi
Expand All @@ -118,7 +118,7 @@ _default_partitioning_scheme() {
_info "${MSG_FORMAT_DRIVE} ${DRIVE}"
dd if=/dev/zero of="${DRIVE}" bs=512 count=1 conv=notrunc status=progress
wipefs --force --all "${DRIVE}"; sleep 1
printf "%s\nw\n" "${PART_CODE}" | fdisk "${DRIVE}"
printf "%s\nw" "${PART_CODE}" | fdisk "${DRIVE}"
partprobe "${DRIVE}" && sleep 1

### Logical Volume Manager ? (UEFI only)
Expand Down Expand Up @@ -192,8 +192,11 @@ _default_partitioning_scheme() {
fi

### Set partition order
if [[ ${DRIVE} =~ "/dev/nvme0n" ]]; then ORDER=(p1 p2 p3 p4)
else ORDER=(1 2 3 4); fi
if [[ ${DRIVE} =~ "/dev/nvme" || ${DRIVE} =~ "/dev/mmcblk" ]]; then
ORDER=(p1 p2 p3 p4)
else
ORDER=(1 2 3 4)
fi

### Partition processing
INDEX=0
Expand All @@ -206,26 +209,32 @@ _default_partitioning_scheme() {
if [[ (${SET_LVM} && ${PART} == "ROOT_PARTITION") || \
(${PART} == "HOME_PARTITION" && ${SIZES[${INDEX}]} == "freespace") ]]; then

printf "n\n%s\n\n\nw\n" "${PART_TYPE}" | fdisk "${DRIVE}"
partprobe "${DRIVE}" && sleep 1
if [[ ${FIRMWARE} == "BIOS" ]]; then
printf "n\np\n\n\nw" | fdisk "${DRIVE}"
else
printf "n\n\n\n\nw" | fdisk "${DRIVE}"
fi

elif [[ ! ${SET_LVM} || ${PART} == "BOOT_PARTITION" ]]; then

printf "n\n%s\n\n\n+%s\nw\n" \
"${PART_TYPE}" "${SIZES[${INDEX}]}" | fdisk "${DRIVE}"

partprobe "${DRIVE}" && sleep 1
if [[ ${FIRMWARE} == "BIOS" ]]; then
printf \
"n\np\n\n\n+%s\nw" "${SIZES[${INDEX}]}" | fdisk "${DRIVE}"
else
printf "n\n\n\n+%s\nw" "${SIZES[${INDEX}]}" | fdisk "${DRIVE}"
fi
fi
partprobe "${DRIVE}" && sleep 1

## Set required partition types
if [[ ${PART} == "BOOT_PARTITION" && ${FIRMWARE} == "UEFI" ]]; then
_info "${MSG_PART_TYPE} ${FIRMWARE/U/} ${DRIVE}${ORDER[${INDEX}]}"
printf "t\nef00\nw\n" | gdisk "${DRIVE}"
printf "t\nef00\nw" | gdisk "${DRIVE}"
partprobe "${DRIVE}" && sleep 1

elif [[ ${SET_LVM} && ${PART} != "BOOT_PARTITION" ]]; then
_info "${MSG_PART_TYPE} ${PART_NAME} ${DRIVE}${ORDER[${INDEX}]}"
printf "t\n%s\n8e00\nw\n" "${INDEX}" | gdisk "${DRIVE}"
printf "t\n1\n8e00\nw" | gdisk "${DRIVE}"
partprobe "${DRIVE}" && sleep 1
fi

Expand Down Expand Up @@ -339,7 +348,8 @@ grep "NAME\|disk\|part"
done

### Set and return boot drive
if [[ ${BOOT_PARTITION} =~ "/dev/nvme0n" ]]; then
if [[ ${BOOT_PARTITION} =~ "/dev/nvme" || \
${BOOT_PARTITION} =~ "/dev/mmcblk" ]]; then
export DRIVE=${BOOT_PARTITION%p*}
else
export DRIVE=${BOOT_PARTITION//[0-9]}
Expand Down