diff --git a/src/script/arch-update.sh b/src/script/arch-update.sh index 911bbb8..f4dabf1 100755 --- a/src/script/arch-update.sh +++ b/src/script/arch-update.sh @@ -27,8 +27,8 @@ if grep -Eq '^[[:space:]]*NoVersion[[:space:]]*$' "${XDG_CONFIG_HOME:-${HOME}/.c no_version="y" fi -if grep -Eq '^[[:space:]]*NoNews[[:space:]]*$' "${XDG_CONFIG_HOME:-${HOME}/.config}/${name}/${name}.conf" 2> /dev/null; then - no_news="y" +if grep -Eq '^[[:space:]]*AlwaysShowNews[[:space:]]*$' "${XDG_CONFIG_HOME:-${HOME}/.config}/${name}/${name}.conf" 2> /dev/null; then + show_news="y" fi if grep -Eq '^[[:space:]]*NewsNum[[:space:]]*=[[:space:]]*[1-9][0-9]*[[:space:]]*$' "${XDG_CONFIG_HOME:-${HOME}/.config}/${name}/${name}.conf" 2> /dev/null; then @@ -59,6 +59,10 @@ if [ -z "${no_color}" ]; then color_off="\e[0m" fi +# Create state dir if it does not exist +statedir="${XDG_STATE_HOME:-${HOME}/.local/state}/${name}" +mkdir -p "${statedir}" + # Definition of the main_msg function: Display a message as a main message main_msg() { msg="${1}" @@ -197,18 +201,16 @@ check() { fi if [ -n "${notif}" ]; then - statedir="${XDG_STATE_HOME:-${HOME}/.local/state}/${name}" - mkdir -p "${statedir}" - echo "${update_available}" > "${statedir}/current_check" - sed -i '/^\s*$/d' "${statedir}/current_check" + echo "${update_available}" > "${statedir}/current_updates_check" + sed -i '/^\s*$/d' "${statedir}/current_updates_check" fi if [ -n "${update_available}" ]; then icon_updates_available if [ -n "${notif}" ]; then - if ! diff "${statedir}/current_check" "${statedir}/last_check" &> /dev/null; then - update_number=$(wc -l "${statedir}/current_check" | awk '{print $1}') + if ! diff "${statedir}/current_updates_check" "${statedir}/last_updates_check" &> /dev/null; then + update_number=$(wc -l "${statedir}/current_updates_check" | awk '{print $1}') if [ "${update_number}" -eq 1 ]; then notify-send -i "${icon_dir}/${name}_updates-available.svg" "${_name}" "$(eval_gettext "\${update_number} update available")" else @@ -220,8 +222,8 @@ check() { icon_up_to_date fi - if [ -f "${statedir}/current_check" ]; then - mv -f "${statedir}/current_check" "${statedir}/last_check" + if [ -f "${statedir}/current_updates_check" ]; then + mv -f "${statedir}/current_updates_check" "${statedir}/last_updates_check" fi } @@ -283,55 +285,69 @@ list_packages() { # Definition of the list_news function: Display the latest Arch news and offers to read them list_news() { - redo="y" + if [ -z "${show_news}" ]; then + curl -Ls https://www.archlinux.org/news | htmlq -a title a | grep ^"View:" | sed "s/View:\ //g" | head -1 > "${statedir}/current_news_check" + + if ! diff "${statedir}/current_news_check" "${statedir}/last_news_check" &> /dev/null; then + show_news="y" + fi + + if [ -f "${statedir}/current_news_check" ]; then + mv -f "${statedir}/current_news_check" "${statedir}/last_news_check" + fi + fi - while [ "${redo}" = "y" ]; do - news=$(curl -Ls https://www.archlinux.org/news) - news_titles=$(echo "${news}" | htmlq -a title a | grep ^"View:" | sed "s/View:\ //g" | head -"${news_num}") - mapfile -t news_dates < <(echo "${news}" | htmlq td | grep -v "class" | grep "[0-9]" | sed "s/<[^>]*>//g" | head -"${news_num}" | xargs -I{} date -d "{}" "+%s") + if [ -n "${show_news}" ]; then + redo="y" - echo - main_msg "$(eval_gettext "Arch News:")" + while [ "${redo}" = "y" ]; do + news=$(curl -Ls https://www.archlinux.org/news) + news_titles=$(echo "${news}" | htmlq -a title a | grep ^"View:" | sed "s/View:\ //g" | head -"${news_num}") + mapfile -t news_dates < <(echo "${news}" | htmlq td | grep -v "class" | grep "[0-9]" | sed "s/<[^>]*>//g" | head -"${news_num}" | xargs -I{} date -d "{}" "+%s") - i=1 - while IFS= read -r line; do - if [ "${news_dates["${i}-1"]}" -ge "$(date -d "$(date "+%Y-%m-%d" -d "15 days ago")" "+%s")" ]; then - new_tag="$(eval_gettext "[NEW]")" - echo -e "${i} - ${line} ${green}${new_tag}${color_off}" - else - echo "${i} - ${line}" - fi - ((i=i+1)) - done < <(printf '%s\n' "${news_titles}") + echo + main_msg "$(eval_gettext "Arch News:")" - echo + i=1 + while IFS= read -r line; do + if [ -z "${no_new_tag}" ] && [ "${news_dates["${i}-1"]}" -ge "$(date -d "$(date "+%Y-%m-%d" -d "100 days ago")" "+%s")" ]; then + new_tag="$(eval_gettext "[NEW]")" + echo -e "${i} - ${line} ${green}${new_tag}${color_off}" + else + echo "${i} - ${line}" + fi + ((i=i+1)) + done < <(printf '%s\n' "${news_titles}") - case "${option}" in - -n|--news) - ask_msg "$(eval_gettext "Select the news to read (or just press \"enter\" to quit):")" - ;; - *) - ask_msg "$(eval_gettext "Select the news to read (or just press \"enter\" to proceed with update):")" - ;; - esac + echo - if [ "${answer}" -le "${news_num}" ] 2> /dev/null && [ "${answer}" -gt "0" ]; then - news_selected=$(sed -n "${answer}"p <<< "${news_titles}") - news_path=$(echo "${news_selected}" | sed s/\ -//g | sed s/\ /-/g | sed s/[.]//g | sed s/=//g | sed s/\>//g | sed s/\ /dev/null && [ "${answer}" -gt "0" ]; then + news_selected=$(sed -n "${answer}"p <<< "${news_titles}") + news_path=$(echo "${news_selected}" | sed s/\ -//g | sed s/\ /-/g | sed s/[.]//g | sed s/=//g | sed s/\>//g | sed s/\ /dev/null; then news_num="${2}" fi