Merge pull request #101 from nurverek/installfix

Installfix
This commit is contained in:
Vince 2020-11-12 23:34:56 +08:00 committed by GitHub
commit 8c6ef2aaf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,7 +26,7 @@ b_CGSC=" \033[1;32m" # bold success color
b_CRER=" \033[1;31m" # bold error color b_CRER=" \033[1;31m" # bold error color
b_CWAR=" \033[1;33m" # bold warning color b_CWAR=" \033[1;33m" # bold warning color
# echo like ... with flag type and display message colors # echo like ... with flag type and display message colors
prompt () { prompt () {
case ${1} in case ${1} in
"-s"|"--success") "-s"|"--success")
@ -43,7 +43,7 @@ prompt () {
esac esac
} }
# Check command avalibility # Check command availability
function has_command() { function has_command() {
command -v $1 > /dev/null command -v $1 > /dev/null
} }
@ -91,24 +91,24 @@ install() {
local screen="1080p" local screen="1080p"
fi fi
if [[ ${screen} == '1080p_21:9' && ${name} == 'Slaze' ]]; then
prompt -e "ultrawide 1080p does not support Slaze theme"
exit 1
fi
if [[ ${custom_background} == 'custom-background' ]]; then if [[ ${custom_background} == 'custom-background' ]]; then
local custom_background="custom-background" local custom_background="custom-background"
else else
local custom_background="default-background" local custom_background="default-background"
fi fi
if [[ ${screen} == '1080p_21:9' && ${name} == 'Slaze' ]]; then
prompt -e "ultrawide 1080p does not support Slaze theme"
exit 1
fi
if [[ ${icon} == 'white' ]]; then if [[ ${icon} == 'white' ]]; then
local icon="white" local icon="white"
else else
local icon="color" local icon="color"
fi fi
# Checking for root access and proceed if it is present # Check for root access and proceed if it is present
if [ "$UID" -eq "$ROOT_UID" ]; then if [ "$UID" -eq "$ROOT_UID" ]; then
clear clear
@ -123,7 +123,7 @@ install() {
fi fi
fi fi
# Create themes directory if not exists # Create themes directory if it didn't exist
echo -e "\n Checking for the existence of themes directory..." echo -e "\n Checking for the existence of themes directory..."
[[ -d "${THEME_DIR}/${name}" ]] && rm -rf "${THEME_DIR}/${name}" [[ -d "${THEME_DIR}/${name}" ]] && rm -rf "${THEME_DIR}/${name}"
@ -132,28 +132,29 @@ install() {
# Copy theme # Copy theme
prompt -i "\n Installing ${name} ${icon} ${screen} theme..." prompt -i "\n Installing ${name} ${icon} ${screen} theme..."
cp -a "${REO_DIR}/common/"{*.png,*.pf2} "${THEME_DIR}/${name}" # Don't preserve ownership because the owner will be root, and that causes the script to crash if it is ran from terminal by sudo
cp -a "${REO_DIR}/config/theme-${screen}.txt" "${THEME_DIR}/${name}/theme.txt" cp -a --no-preserve=ownership "${REO_DIR}/common/"{*.png,*.pf2} "${THEME_DIR}/${name}"
cp -a --no-preserve=ownership "${REO_DIR}/config/theme-${screen}.txt" "${THEME_DIR}/${name}/theme.txt"
if [[ ${custom_background} == "background.jpg" ]] || [[ ${custom_background} == "custom-background.jpg" ]]; then if [[ ${custom_background} == "background.jpg" ]] || [[ ${custom_background} == "custom-background.jpg" ]]; then
if [[ -f "$custom_background" ]]; then if [[ -f "$custom_background" ]]; then
prompt -i "\n Using ${custom_background} as background image..." prompt -i "\n Using ${custom_background} as background image..."
cp -a "${REO_DIR}/${custom_background}" "${THEME_DIR}/${name}/background.jpg" cp -a --no-preserve=ownership "${REO_DIR}/${custom_background}" "${THEME_DIR}/${name}/background.jpg"
convert -auto-orient "${THEME_DIR}/${name}/background.jpg" "${THEME_DIR}/${name}/background.jpg" convert -auto-orient "${THEME_DIR}/${name}/background.jpg" "${THEME_DIR}/${name}/background.jpg"
else else
prompt -e "$custom_background couldn't be found, exiting" prompt -e "$custom_background couldn't be found, exiting"
exit 0 exit 0
fi fi
else else
cp -a "${REO_DIR}/backgrounds/${screen}/background-${theme}.jpg" "${THEME_DIR}/${name}/background.jpg" cp -a --no-preserve=ownership "${REO_DIR}/backgrounds/${screen}/background-${theme}.jpg" "${THEME_DIR}/${name}/background.jpg"
fi fi
if [[ ${screen} == '1080p_21:9' ]]; then if [[ ${screen} == '1080p_21:9' ]]; then
cp -a "${REO_DIR}/assets/assets-${icon}/icons-1080p" "${THEME_DIR}/${name}/icons" cp -a --no-preserve=ownership "${REO_DIR}/assets/assets-${icon}/icons-1080p" "${THEME_DIR}/${name}/icons"
cp -a "${REO_DIR}/assets/assets-${icon}/select-1080p/"*.png "${THEME_DIR}/${name}" cp -a --no-preserve=ownership "${REO_DIR}/assets/assets-${icon}/select-1080p/"*.png "${THEME_DIR}/${name}"
else else
cp -a "${REO_DIR}/assets/assets-${icon}/icons-${screen}" "${THEME_DIR}/${name}/icons" cp -a --no-preserve=ownership "${REO_DIR}/assets/assets-${icon}/icons-${screen}" "${THEME_DIR}/${name}/icons"
cp -a "${REO_DIR}/assets/assets-${icon}/select-${screen}/"*.png "${THEME_DIR}/${name}" cp -a --no-preserve=ownership "${REO_DIR}/assets/assets-${icon}/select-${screen}/"*.png "${THEME_DIR}/${name}"
fi fi
# Set theme # Set theme
@ -170,7 +171,7 @@ install() {
echo "GRUB_THEME=\"${THEME_DIR}/${name}/theme.txt\"" >> /etc/default/grub echo "GRUB_THEME=\"${THEME_DIR}/${name}/theme.txt\"" >> /etc/default/grub
fi fi
# Make sure set the right resolution for grub # Make sure the right resolution for grub is set
if [[ ${screen} == '1080p' ]]; then if [[ ${screen} == '1080p' ]]; then
gfxmode="GRUB_GFXMODE=1920x1080,auto" gfxmode="GRUB_GFXMODE=1920x1080,auto"
elif [[ ${screen} == '1080p_21:9' ]]; then elif [[ ${screen} == '1080p_21:9' ]]; then
@ -205,41 +206,71 @@ install() {
updating_grub updating_grub
prompt -w "\n * At the next restart of your computer you will see your new Grub theme: '$theme' " prompt -w "\n * At the next restart of your computer you will see your new Grub theme: '$theme' "
else else
# Error message #Check if password is cached (if cache timestamp not expired yet)
prompt -e "\n [ Error! ] -> Run me as root! " sudo -n true 2> /dev/null && echo
if [[ $? == 0 ]]; then
#No need to ask for password
sudo "$0" --${theme} --${icon} --${screen}
# persisted execution of the script as root
if [[ -n ${tui_root_login} ]] ; then
if [[ -n "${theme}" && -n "${screen}" ]]; then
sudo -S <<< ${tui_root_login} $0 --${theme} --${icon} --${screen}
fi
else else
read -p "[ Trusted ] Specify the root password : " -t${MAX_DELAY} -s #Ask for password
[[ -n "$REPLY" ]] && {
if [[ -n "${theme}" && -n "${screen}" ]]; then
sudo -S <<< $REPLY "$0" --${theme} --${icon} --${screen}
fi
} || {
operation_canceled
}
fi
if [[ -n ${tui_root_login} ]] ; then
if [[ -n "${theme}" && -n "${screen}" ]]; then
sudo -S $0 --${theme} --${icon} --${screen} <<< ${tui_root_login}
fi
else
prompt -e "\n [ Error! ] -> Run me as root! "
read -p " [ Trusted ] Specify the root password : " -t ${MAX_DELAY} -s
sudo -S echo <<< $REPLY 2> /dev/null && echo
if [[ $? == 0 ]]; then
#Correct password, use with sudo's stdin
sudo -S "$0" --${theme} --${icon} --${screen} <<< ${REPLY}
else
#block for 3 seconds before allowing another attempt
sleep 3
prompt -e "\n [ Error! ] -> Incorrect password!\n"
exit 1
fi
fi
fi
fi fi
} }
run_dialog() { run_dialog() {
if [[ -x /usr/bin/dialog ]]; then if [[ -x /usr/bin/dialog ]]; then
tui_root_login=$(dialog --backtitle ${Project_Name} \ if [[ "$UID" -ne "$ROOT_UID" ]]; then
--title "ROOT LOGIN" \ #Check if password is cached (if cache timestamp not expired yet)
--insecure \ sudo -n true 2> /dev/null && echo
--passwordbox "require root permission" 8 50 \
--output-fd 1 ) if [[ $? == 0 ]]; then
[[ -z ${tui_root_login} ]] && exit ${UID} #No need to ask for password
sudo -S <<< $tui_root_login $0 sudo $0
test $? -eq 0 || { else
prompt -e "\n [ Error! ] -> wrong passwords" #Ask for password
exit 1 tui_root_login=$(dialog --backtitle ${Project_Name} \
} --title "ROOT LOGIN" \
--insecure \
--passwordbox "require root permission" 8 50 \
--output-fd 1 )
sudo -S echo <<< $tui_root_login 2> /dev/null && echo
if [[ $? == 0 ]]; then
#Correct password, use with sudo's stdin
sudo -S "$0" <<< $tui_root_login
else
#block for 3 seconds before allowing another attempt
sleep 3
clear
prompt -e "\n [ Error! ] -> Incorrect password!\n"
exit 1
fi
fi
fi
tui=$(dialog --backtitle ${Project_Name} \ tui=$(dialog --backtitle ${Project_Name} \
--radiolist "Choose your Grub theme : " 15 40 5 \ --radiolist "Choose your Grub theme : " 15 40 5 \
@ -333,7 +364,7 @@ remove() {
exit 0 exit 0
fi fi
# Checking for root access and proceed if it is present # Check for root access and proceed if it is present
if [ "$UID" -eq "$ROOT_UID" ]; then if [ "$UID" -eq "$ROOT_UID" ]; then
echo -e "\n Checking for the existence of themes directory..." echo -e "\n Checking for the existence of themes directory..."
if [[ -d "${THEME_DIR}/${name}" ]]; then if [[ -d "${THEME_DIR}/${name}" ]]; then
@ -356,37 +387,62 @@ remove() {
updating_grub updating_grub
else else
# Error message #Check if password is cached (if cache timestamp not expired yet)
prompt -e "\n [ Error! ] -> Run me as root " sudo -n true 2> /dev/null && echo
# persisted execution of the script as root if [[ $? == 0 ]]; then
read -p "[ trusted ] specify the root password : " -t${MAX_DELAY} -s #No need to ask for password
[[ -n "$REPLY" ]] && { sudo "$0" "${PROG_ARGS[@]}"
if [[ -n "${theme}" ]]; then else
sudo -S <<< $REPLY "$0" "${PROG_ARGS[@]}" #Ask for password
prompt -e "\n [ Error! ] -> Run me as root! "
read -p " [ Trusted ] Specify the root password : " -t ${MAX_DELAY} -s
sudo -S echo <<< $REPLY 2> /dev/null && echo
if [[ $? == 0 ]]; then
#Correct password, use with sudo's stdin
sudo -S "$0" "${PROG_ARGS[@]}" <<< $REPLY
else
#block for 3 seconds before allowing another attempt
sleep 3
clear
prompt -e "\n [ Error! ] -> Incorrect password!\n"
exit 1
fi fi
} || { fi
operation_canceled
}
fi fi
} }
# show terminal user interface for better use # Show terminal user interface for better use
if [[ $# -lt 1 ]] && [[ $UID -ne $ROOT_UID ]] && [[ -x /usr/bin/dialog ]] ; then if [[ $# -lt 1 ]] && [[ $UID -ne $ROOT_UID ]] && [[ -x /usr/bin/dialog ]] ; then
run_dialog run_dialog
fi fi
if [[ $# -lt 1 ]] && [[ $UID -ne $ROOT_UID ]] && [[ ! -x /usr/bin/dialog ]] ; then if [[ $# -lt 1 ]] && [[ $UID -ne $ROOT_UID ]] && [[ ! -x /usr/bin/dialog ]] ; then
# Error message #Check if password is cached (if cache timestamp not expired yet)
prompt -e "\n [ Error! ] -> Run me as root! " sudo -n true 2> /dev/null && echo
# persisted execution of the script as root if [[ $? == 0 ]]; then
read -p "[ Trusted ] Specify the root password : " -t${MAX_DELAY} -s #No need to ask for password
[[ -n "$REPLY" ]]&& { exec sudo $0
exec sudo -S <<< $REPLY $0 else
}|| { #Ask for password
operation_canceled prompt -e "\n [ Error! ] -> Run me as root! "
} read -p " [ Trusted ] Specify the root password : " -t ${MAX_DELAY} -s
sudo -S echo <<< $REPLY 2> /dev/null && echo
if [[ $? == 0 ]]; then
#Correct password, use with sudo's stdin
sudo $0 <<< $REPLY
else
#block for 3 seconds before allowing another attempt
sleep 3
prompt -e "\n [ Error! ] -> Incorrect password!\n"
exit 1
fi
fi
fi fi
while [[ $# -ge 1 ]]; do while [[ $# -ge 1 ]]; do