replace grep with rg and sed with sd

This commit is contained in:
Tobias Powalowski 2024-06-28 14:15:47 +02:00
parent c244ff56ee
commit d874cc905f

View file

@ -4,7 +4,7 @@
_mkinitcpio() { _mkinitcpio() {
if [[ "${_RUNNING_ARCH}" == "aarch64" ]]; then if [[ "${_RUNNING_ARCH}" == "aarch64" ]]; then
# disable error out on kms install hook # disable error out on kms install hook
sed -i -e 's: add_checked_modules_from_symbol: #add_checked_modules_from_symbol:g' \ sd ' add_checked_modules_from_symbol' ' #add_checked_modules_from_symbol' \
"${_DESTDIR}"/usr/lib/initcpio/install/kms "${_DESTDIR}"/usr/lib/initcpio/install/kms
chroot "${_DESTDIR}" mkinitcpio -p "${_KERNELPKG}"-"${_RUNNING_ARCH}" &>"${_LOG}" && : > /tmp/.mkinitcpio-success chroot "${_DESTDIR}" mkinitcpio -p "${_KERNELPKG}"-"${_RUNNING_ARCH}" &>"${_LOG}" && : > /tmp/.mkinitcpio-success
else else
@ -54,7 +54,7 @@ _set_mkinitcpio() {
_check_root_password() { _check_root_password() {
_USER="root" _USER="root"
# check if empty password is set # check if empty password is set
if passwd -R "${_DESTDIR}" -S root | cut -d ' ' -f2 | grep -q NP; then if passwd -R "${_DESTDIR}" -S root | rg -q ' NP '; then
_dialog --title " Root Account " --no-mouse --infobox "Setup detected no password set for root user.\nPlease set new password now." 4 50 _dialog --title " Root Account " --no-mouse --infobox "Setup detected no password set for root user.\nPlease set new password now." 4 50
read -r -t 3 read -r -t 3
if _prepare_password Root; then if _prepare_password Root; then
@ -64,7 +64,7 @@ _check_root_password() {
fi fi
fi fi
# check if account is locked # check if account is locked
if passwd -R "${_DESTDIR}" -S root | cut -d ' ' -f2 | grep -q L; then if passwd -R "${_DESTDIR}" -S root | rg -q ' L '; then
_dialog --title " Root Account " --no-mouse --infobox "Setup detected locked account for root user.\nPlease set new password to unlock account now." 4 50 _dialog --title " Root Account " --no-mouse --infobox "Setup detected locked account for root user.\nPlease set new password to unlock account now." 4 50
if _prepare_password Root; then if _prepare_password Root; then
_set_password _set_password
@ -154,8 +154,8 @@ _user_management() {
fi ;; fi ;;
esac esac
# change default shell for root and all users >= UID 1000 # change default shell for root and all users >= UID 1000
sed -i -e "s#^SHELL=.*#SHELL=/usr/bin/${_SHELL}#g" "${_DESTDIR}"/etc/default/useradd sd "^SHELL=.*' 'SHELL=/usr/bin/${_SHELL}" "${_DESTDIR}"/etc/default/useradd
for i in root $(grep 'x:10[0-9][0-9]' "${_DESTDIR}"/etc/passwd | cut -d : -f 1); do for i in root $(rg -o '(.*):x:10[0-9][0-9]' -r '$1' "${_DESTDIR}"/etc/passwd); do
usermod -R "${_DESTDIR}" -s "/usr/bin/${_SHELL}" "${i}" &>"${_LOG}" usermod -R "${_DESTDIR}" -s "/usr/bin/${_SHELL}" "${i}" &>"${_LOG}"
done done
_dialog --title " Success " --no-mouse --infobox "Default shell set to ${_SHELL}." 3 50 _dialog --title " Success " --no-mouse --infobox "Default shell set to ${_SHELL}." 3 50
@ -166,7 +166,7 @@ _user_management() {
fi ;; fi ;;
"2") while true; do "2") while true; do
_set_user || break _set_user || break
if grep -q "^${_USER}:" "${_DESTDIR}"/etc/passwd; then if rg -q "^${_USER}:" "${_DESTDIR}"/etc/passwd; then
_dialog --title " ERROR " --no-mouse --infobox "Username already exists! Please choose an other one." 3 60 _dialog --title " ERROR " --no-mouse --infobox "Username already exists! Please choose an other one." 3 60
read -r -t 3 read -r -t 3
else else
@ -192,7 +192,7 @@ _user_management() {
"3") _USER="root" "3") _USER="root"
while true; do while true; do
# root and all users with UID >= 1000 # root and all users with UID >= 1000
_USERS="$(grep 'x:10[0-9][0-9]' "${_DESTDIR}"/etc/passwd | cut -d : -f 1,5 | sed -e 's: :#:g' | sed -e 's#:# #g')" _USERS="$(rg -o '(.*):x:10[0-9][0-9]:.*:(.*):.*:' -r '"$1" "$2"' "${_DESTDIR}"/etc/passwd)"
#shellcheck disable=SC2086 #shellcheck disable=SC2086
_dialog --no-cancel --default-item ${_USER} --menu " User Account Selection " 15 40 10 \ _dialog --no-cancel --default-item ${_USER} --menu " User Account Selection " 15 40 10 \
"root" "Super User" ${_USERS} "< Back" "Return To Previous Menu" 2>"${_ANSWER}" || break "root" "Super User" ${_USERS} "< Back" "Return To Previous Menu" 2>"${_ANSWER}" || break
@ -209,7 +209,7 @@ _user_management() {
while true; do while true; do
_DEFAULT="--default-item ${_NEXTITEM}" _DEFAULT="--default-item ${_NEXTITEM}"
#shellcheck disable=SC2086 #shellcheck disable=SC2086
if grep wheel "${_DESTDIR}"/etc/group | grep -qw "${_USER}"; then if rg wheel "${_DESTDIR}"/etc/group | rg -qw "${_USER}"; then
_ADMIN_ATTR=1 _ADMIN_ATTR=1
_USER_TITLE="${_USER} | Administrator | wheel group" _USER_TITLE="${_USER} | Administrator | wheel group"
_USER_MENU="Change To Normal User" _USER_MENU="Change To Normal User"