From 7810486bd385880deeef527765a9b551e0ff7805 Mon Sep 17 00:00:00 2001 From: Dustin Falgout Date: Fri, 17 Jun 2016 22:25:38 -0500 Subject: [PATCH] working on #1 --- dist/antergos-iso | 170 +++++++++++++++++++++++++++++++ dist/antergos-iso_i18n | 49 +++++++++ iso-hotfix-utility | 222 ++++++++++++++--------------------------- 3 files changed, 293 insertions(+), 148 deletions(-) create mode 100644 dist/antergos-iso create mode 100644 dist/antergos-iso_i18n diff --git a/dist/antergos-iso b/dist/antergos-iso new file mode 100644 index 0000000..e01b470 --- /dev/null +++ b/dist/antergos-iso @@ -0,0 +1,170 @@ +#!/bin/bash +# +# antergos-iso +# +# Copyright © 2013-2016 Antergos +# +# This file is part of iso-hotfix-utility. +# +# iso-hotfix-utility is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# iso-hotfix-utility is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# The following additional terms are in effect as per Section 7 of the license: +# +# The preservation of all legal notices and author attributions in +# the material or in the Appropriate Legal Notices displayed +# by works containing it is required. +# +# You should have received a copy of the GNU General Public License +# along with iso-hotfix-utility; if not, see . + + +### +## +# Initialize Variables +## +### + +APP_ICON='' +APP_NAME='' +CNCHI_STARTED='False' +IS_MINIMAL='False' +LOG_PATH='/tmp/pacman-boot' + + +### +## +# Define Functions +## +### + +hotfix_setup_environment() { + _2log "[antergos-iso] Setting up environment.." + + APP_NAME='Cnchi' + LEVEL='critical' + APP_ICON='/usr/share/cnchi/data/images/antergos/antergos-icon.png' + + [[ -f /tmp/.setup-running ]] && CNCHI_STARTED='True' + [[ -d /home/antergos/.config/openbox ]] && IS_MINIMAL='True' + + alias pacSyy='sudo pacman -Syy --noconfirm' + alias pacS='sudo pacman -S --noconfirm' + alias packey_populate='sudo pacman-key --populate archlinux antergos' + alias packey_init='sudo pacman-key --init' + + if [[ $(systemd-detect-virt) && 'oracle' = $(systemd-detect-virt -v) ]]; then + VBoxClient-all + fi +} + + +font_patch() { + local clear_fcache _file file_name + clear_fcache='False' + + for _file in /usr/share/cnchi/data/fonts/OpenSans** + do + file_name=$(basename "${_file}") + if ! [[ -f /usr/share/fonts/TTF/"${file_name}" && -f "${_file}" ]]; then + sudo cp "${_file}" /usr/share/fonts/TTF + clear_fcache='True' + fi + done + + if [[ 'True' = "${clear_fcache}" ]]; then + sudo fc-cache -f -v + fi +} + + +stop_cnchi() { + sudo killall -w /usr/bin/cnchi cnchi python && sudo rm /tmp/.setup-running + sudo systemctl stop pamac > /dev/null 2>&1 + sudo rm /var/lib/pacman/db.lck > /dev/null 2>&1 + + return 0 +} + + +start_cnchi() { + stop_cnchi && sudo -E cnchi -d -v -s bugsnag & + + return 0; +} + + +add_or_remove_antbs_mirrorlist() { + if [[ "$1" = 'add' ]]; then + sudo sed -i '1s%^%Server = http://repo.antergos.info/$repo/$arch\n%' /etc/pacman.d/antergos-mirrorlist + elif [[ "$1" = 'remove' ]]; then + sudo sed -i '1d' /etc/pacman.d/antergos-mirrorlist + fi + + sudo rm /var/lib/pacman/db.lck > /dev/null 2>&1 +} + + +notify_no_updates() { + _notify_user "${NO_UPDATES_CN}" "${NO_UPDATES_CN_SUB}" + add_or_remove_antbs_mirrorlist 'remove' +} + + +populate_pacman_keyring() { + { ${BASH_ALIASES[packey_populate]} && return 0; } || \ + { ${BASH_ALIASES[packey_init]} && ${BASH_ALIASES[packey_populate]} && return 0; } || \ + return 1 +} + + +hotfix_waiting_for_internet() { + start_cnchi +} + + +hotfix_maybe_update() { + add_or_remove_antbs_mirrorlist 'add' + ${BASH_ALIASES[pacSyy]} iso-hotfix-utility || populate_pacman_keyring && ${BASH_ALIASES[pacSyy]} iso-hotfix-utility +} + + +hotfix_run_when_connected() { + if [[ 'True' = "${IS_MINIMAL}" ]]; then + ${BASH_ALIASES[pacS]} numix-icon-theme-square numix-icon-theme numix-frost-themes adwaita-icon-theme + else + sudo modprobe -a spl zfs + fi + + local CHECK_UPDATES + CHECK_UPDATES=$(sudo checkupdates) + + [[ "${CHECK_UPDATES}" = *'cnchi'* ]] && INSTALL_CNCHI='True' + + if [[ ${INSTALL_CNCHI} = 'True' ]]; then + notify_user "${INSTALLING_UPDATES}" "${INSTALLING_UPDATES_SUB}" + stop_cnchi + ${BASH_ALIASES[pacS]} --force cnchi && LEVEL='normal'; _notify_user "${UPDATE_COMPLETE}" "${UPDATE_COMPLETE_SUB}" + start_cnchi && CNCHI_RESTARTED='True' + else + LEVEL='normal'; _notify_no_updates + fi +} + + +hotfix_before_environment_setup() { + if [[ "$1" = cnchi-dev ]]; then + sudo rm -rf /usr/share/cnchi + sudo git clone https://github.com/lots0logs/cnchi-dev.git /usr/share/cnchi + cd /usr/share/cnchi && sudo git checkout playing && start_cnchi + exit 0 + fi +} + diff --git a/dist/antergos-iso_i18n b/dist/antergos-iso_i18n new file mode 100644 index 0000000..a12f63d --- /dev/null +++ b/dist/antergos-iso_i18n @@ -0,0 +1,49 @@ +#!/bin/bash +# +# antergos-iso_i18n +# +# Copyright © 2013-2016 Antergos +# +# This file is part of iso-hotfix-utility. +# +# iso-hotfix-utility is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# iso-hotfix-utility is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# The following additional terms are in effect as per Section 7 of the license: +# +# The preservation of all legal notices and author attributions in +# the material or in the Appropriate Legal Notices displayed +# by works containing it is required. +# +# You should have received a copy of the GNU General Public License +# along with iso-hotfix-utility; if not, see . + + +export TEXTDOMAIN="CNCHI_UPDATER" +export GETTEXT='gettext "CNCHI_UPDATER"' + +### +## +# Translatable Strings +## +### + +NO_CONNECTION=$(${GETTEXT} "INSTALLER NOTICE:") +NO_CONNECTION_SUB_STR='You must be connected to the internet to install Antergos. ' +NO_CONNECTION_SUB_STR+='Click the network icon in the top bar to configure your connection.' +NO_CONNECTION_SUB=$(${GETTEXT} "${NO_CONNECTION_SUB_STR}") +INSTALLING_UPDATES=$(${GETTEXT} "Installing Updates") +INSTALLING_UPDATES_SUB=$(${GETTEXT} "Installing available updates.") +UPDATE_COMPLETE=$(${GETTEXT} "Update Complete") +UPDATE_COMPLETE_SUB=$(${GETTEXT} "Updates were installed sucessfully. Starting Cnchi...") +CHECKING_UPDATES=$(${GETTEXT} "Cnchi Automatic Updates") +CHECKING_UPDATES_SUB=$(${GETTEXT} "Checking for available updates for the Antergos Installer.") +NO_UPDATES_CN=$(${GETTEXT} "Check was sucessful.") +NO_UPDATES_CN_SUB=$(${GETTEXT} "You have the latest version. You can proceed with your installation!") diff --git a/iso-hotfix-utility b/iso-hotfix-utility index 50e174f..9052908 100644 --- a/iso-hotfix-utility +++ b/iso-hotfix-utility @@ -25,27 +25,7 @@ # You should have received a copy of the GNU General Public License # along with iso-hotfix-utility; if not, see . -export TEXTDOMAIN="CNCHI_UPDATER" -export GETTEXT='gettext "CNCHI_UPDATER"' - -### -## -# Translatable Strings -## -### - -NO_CONNECTION=$(${GETTEXT} "INSTALLER NOTICE:") -NO_CONNECTION_SUB_STR='You must be connected to the internet to install Antergos. ' -NO_CONNECTION_SUB_STR+='Click the network icon in the top bar to configure your connection.' -NO_CONNECTION_SUB=$(${GETTEXT} "${NO_CONNECTION_SUB_STR}") -INSTALLING_UPDATES=$(${GETTEXT} "Installing Updates") -INSTALLING_UPDATES_SUB=$(${GETTEXT} "Installing available updates.") -UPDATE_COMPLETE=$(${GETTEXT} "Update Complete") -UPDATE_COMPLETE_SUB=$(${GETTEXT} "Updates were installed sucessfully. Starting Cnchi...") -CHECKING_UPDATES=$(${GETTEXT} "Cnchi Automatic Updates") -CHECKING_UPDATES_SUB=$(${GETTEXT} "Checking for available updates for the Antergos Installer.") -NO_UPDATES_CN=$(${GETTEXT} "Check was sucessful.") -NO_UPDATES_CN_SUB=$(${GETTEXT} "You have the latest version. You can proceed with your installation!") +shopt -s expand_aliases ### @@ -57,10 +37,10 @@ NO_UPDATES_CN_SUB=$(${GETTEXT} "You have the latest version. You can proceed wit NETWORK_ALIVE=1 NOTIFIED='False' SCRIPT_UPDATED='False' -CNCHI_RESTARTED='False' LAST_SENT='' -CNCHI_ICON='' -IS_MINIMAL='False' +APP_ICON='' +APP_NAME='' +LEVEL='' ### @@ -69,156 +49,82 @@ IS_MINIMAL='False' ## ### -setup_environment() { - NETWORK_ALIVE=$(ping -c1 8.8.8.8 >/dev/null 2>&1; echo $?) - CNCHI_ICON='/usr/share/cnchi/data/images/antergos/antergos-icon.png' - - [[ $0 = 'iso-hotfix-utility' ]] && SCRIPT_UPDATED='True' - [[ -f /tmp/.setup-running ]] && CNCHI_STARTED='True' - [[ -d /home/antergos/.config/openbox ]] && IS_MINIMAL='True' - - alias pacSyy='sudo pacman -Syy --noconfirm' - alias pacS='sudo pacman -S --noconfirm' - alias packey_populate='sudo pacman-key --populate archlinux antergos' - alias packey_init='sudo pacman-key --init' - - if [[ $(systemd-detect-virt) && 'oracle' = $(systemd-detect-virt -v) ]]; then - VBoxClient-all - fi +_2log() { + echo "====>>>$1<<<====" } -notify_user() { - if [[ "${LAST_SENT}" != '' ]]; then - LAST_SENT=$(notify-send.sh -a "Cnchi" -i "${CNCHI_ICON}" -u critical -p -r "${LAST_SENT}" "$1" "$2") - else - LAST_SENT=$(notify-send.sh -a "Cnchi" -i "${CNCHI_ICON}" -u critical -p "$1" "$2") - fi - - echo "${LAST_SENT}" -} - +_setup_environment() { + _2log '[iso-hotfix-utility] Setting up environment..' -font_patch() { - local clear_fcache='False' - - for file in /usr/share/cnchi/data/fonts/OpenSans** - do - file_name=$(basename "${file}") - if ! [[ -f /usr/share/fonts/TTF/"${file_name}" && -f "${file}" ]]; then - sudo cp "${file}" /usr/share/fonts/TTF - clear_fcache='True' - fi - done + NETWORK_ALIVE=$(ping -c1 8.8.8.8 >/dev/null 2>&1; echo $?) - if [[ 'True' = "${clear_fcache}" ]]; then - sudo fc-cache -f -v + if [[ $0 = 'iso-hotfix-utility' ]]; then + SCRIPT_UPDATED='True' + _2log '[iso-hotfix-utility] Script has been updated.' fi } -stop_cnchi() { - sudo killall -w /usr/bin/cnchi cnchi python && sudo rm /tmp/.setup-running - sudo systemctl stop pamac > /dev/null 2>&1 - sudo rm /var/lib/pacman/db.lck > /dev/null 2>&1 - - return 0 -} - - -start_cnchi() { - stop_cnchi && sudo -E cnchi -d -v -s bugsnag & +_notify_user() { + if [[ "${LAST_SENT}" != '' ]]; then + LAST_SENT=$(notify-send.sh -a "${APP_NAME}" -i "${APP_ICON}" -u "${LEVEL}" -p -r "${LAST_SENT}" "$1" "$2") + else + LAST_SENT=$(notify-send.sh -a "${APP_NAME}" -i "${APP_ICON}" -u "${LEVEL}" -p "$1" "$2") + fi - return 0; + _2log "${LAST_SENT}" } -wait_for_internet_connection() { - if [[ "${NETWORK_ALIVE}" != 0 ]]; then - start_cnchi - - while [[ "${NETWORK_ALIVE}" != 0 ]]; do - if [[ "${NOTIFIED}" = 'False' ]]; then - notify_user "${NO_CONNECTION}" "${NO_CONNECTION_SUB}" - NOTIFIED='True' - fi - - NETWORK_ALIVE=$(ping -c1 8.8.8.8 >/dev/null 2>&1; echo $?) +_maybe_wait_for_internet_connection() { + local connected + connected='[iso-hotfix-utility] We have internet connection.' - sleep 1; - done - fi -} - - -add_or_remove_antbs_mirrorlist() { - if [[ "$1" = 'add' ]]; then - sudo sed -i '1s%^%Server = http://repo.antergos.info/$repo/$arch\n%' /etc/pacman.d/antergos-mirrorlist - elif [[ "$1" = 'remove' ]]; then - sudo sed -i '1d' /etc/pacman.d/antergos-mirrorlist + if [[ "${NETWORK_ALIVE}" = 0 ]]; then + _2log "${connected}" + return fi - sudo rm /var/lib/pacman/db.lck > /dev/null 2>&1 -} + hotfix_waiting_for_internet + while [[ "${NETWORK_ALIVE}" != 0 ]]; do + if [[ "${NOTIFIED}" = 'False' ]]; then + _notify_user "${NO_CONNECTION}" "${NO_CONNECTION_SUB}" + NOTIFIED='True' + fi -notify_no_updates() { - notify_user "${NO_UPDATES_CN}" "${NO_UPDATES_CN_SUB}" - add_or_remove_antbs_mirrorlist 'remove' -} + NETWORK_ALIVE=$(ping -c1 8.8.8.8 >/dev/null 2>&1; echo $?) + sleep 1; + done -populate_pacman_keyring() { - { packey_populate && return 0; } || \ - { packey_init && packey_populate && return 0; } || \ - return 1 + _2log "${connected}" } -maybe_update_rerun_and_exit() { +_maybe_update_rerun_and_exit() { if [[ "${SCRIPT_UPDATED}" = 'True' ]]; then return fi - add_or_remove_antbs_mirrorlist 'add' - notify_user "${CHECKING_UPDATES}" "${CHECKING_UPDATES_SUB}" - - pacSyy iso-hotfix-utility || populate_pacman_keyring && pacSyy iso-hotfix-utility + _notify_user "${CHECKING_UPDATES}" "${CHECKING_UPDATES_SUB}" + hotfix_maybe_update if [[ -f /usr/bin/iso-hotfix-utility ]]; then - { nohup /usr/bin/iso-hotfix-utility & } && exit 0 + { nohup /usr/bin/iso-hotfix-utility & >> "${LOG_PATH}" 2>&1; } && exit 0 else - notify_no_updates + _2log '[iso-hotfix-utility] Failed to update hotifx package!' fi } -run_when_connected() { - if [[ "${NETWORK_ALIVE}" != 0 ]]; then - wait_for_internet_connection - fi +_run_when_connected() { + _maybe_wait_for_internet_connection - maybe_update_rerun_and_exit - - if [[ 'True' = "${IS_MINIMAL}" ]]; then - pacS numix-icon-theme-square numix-icon-theme numix-frost-themes adwaita-icon-theme - else - sudo modprobe -a spl zfs - fi + _maybe_update_rerun_and_exit - local CHECK_UPDATES - CHECK_UPDATES=$(sudo checkupdates) - - [[ "${CHECK_UPDATES}" = *'cnchi'* ]] && INSTALL_CNCHI='True' - - if [[ ${INSTALL_CNCHI} = 'True' ]]; then - notify_user "${INSTALLING_UPDATES}" "${INSTALLING_UPDATES_SUB}" - stop_cnchi - pacS --force cnchi && notify_user "${UPDATE_COMPLETE}" "${UPDATE_COMPLETE_SUB}" - start_cnchi && CNCHI_RESTARTED='True' - else - notify_no_updates - fi + hotfix_run_when_connected } @@ -228,22 +134,42 @@ run_when_connected() { ## ### -for supplemental_file in /etc/iso-hotfix-utility.d/** +# remember whether extglob was originally set, so we know whether to unset it +shopt -q extglob; extglob_set=$? + +# set extglob if it wasn't originally set. +((extglob_set)) && shopt -s extglob + +supplemental_files_i18n=(/etc/iso-hotfix-utility.d/**_i18n) +supplemental_files=(/etc/iso-hotfix-utility.d/**!(_i18n)) + +for supplemental_file_i18n in "${supplemental_files_i18n[@]}" do + # shellcheck source=/dev/null + source "${supplemental_file_i18n}" +done + +for supplemental_file in "${supplemental_files[@]}" +do + # shellcheck source=/dev/null source "${supplemental_file}" done -if [[ "$1" = cnchi-dev ]]; then - sudo rm -rf /usr/share/cnchi - sudo git clone https://github.com/lots0logs/cnchi-dev.git /usr/share/cnchi - cd /usr/share/cnchi && sudo git checkout playing && start_cnchi - exit 0 -fi +# unset extglob if it wasn't originally set +((extglob_set)) && shopt -u extglob -{ setup_environment && run_when_connected; } > /tmp/pacman-boot.log 2>&1 \ + +hotfix_before_environment_setup "$1" + +{ _setup_environment \ + && hotfix_setup_environment \ + && _run_when_connected \ && sleep 5 \ - && { [[ -f /tmp/.setup-running ]] && exit 0; } \ - || { start_cnchi && exit 0; } + && [[ -f /tmp/.setup-running ]] \ + && exit 0 +} >> /tmp/pacman-boot.log 2>&1; + +hotfix_run_if_failed exit 1;