#!/bin/bash # MIT License # # Copyright (c) 2018 Fredes Computer Service # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. #set -x if [[ -n ${APP_UTILITY} ]]; then echo "This script is part of Manjaro Application Utility\nIt is not meant to be run from command line\n exit()" fi # files IN_PKG_FILE="/tmp/.install-packages.txt" RM_PKG_FILE="/tmp/.remove-packages.txt" PM_STATUS_FILE="/tmp/.pm-status.txt" PM_LOCK_FILE="/var/lib/pacman/db.lck" echo ${IN_PKG_FILE} echo ${RM_PKG_FILE} # messages TITLE="Manjaro Application Utility" UPD_DB_MSG="Updating Package Database..." DB_LOCKED_MSG="Another package manager is running.\n If you are updating the system\n you MUST finish before continuing.\n If you are not, it is safe to kill the other process.\n What would you like to do?" KILL_PROCESS="Kill other process and continue" WAIT_PROCESS="Wait to finish updating" IN_WORKING_MSG="Installing Packages..." RM_WORKING_MSG="Uninstalling Packages..." DONE="Your System has Been Successfully Updated" if [[ -f ${IN_PKG_FILE} ]]; then IN_PKG=` cat ${IN_PKG_FILE} ` echo ${IN_PKG} fi if [[ -f ${RM_PKG_FILE} ]]; then RM_PKG=` cat ${RM_PKG_FILE} ` echo ${RM_PKG} fi # Make sure only root can run our script if [[ $EUID -ne 0 ]]; then echo "Superuser required ..." 1>&2 exit 1 fi # updating databases and writing results to a file pacman -Syy | tee ${PM_STATUS_FILE} | zenity --progress --title="${TITLE}" --no-cancel --pulsate --text "${UPD_DB_MSG}" --width=500 --auto-close PM_STATUS=` cat ${PM_STATUS_FILE} ` # checking for other running package managers if [[ $(cat ${PM_STATUS_FILE} | grep -i 'core.db') = "" ]] then # giving choice to user to kill other process or wait ans=$(zenity --list --title="${TITLE}" --radiolist --text "${DB_LOCKED_MSG}" --column Select --column Choice TRUE "${KILL_PROCESS}" FALSE "${WAIT_PROCESS}" --width=500 --height=300) # killing pamac and unlocking db if [ "$ans" = "${KILL_PROCESS}" ] then killall pamac-updater killall pamac-manager rm ${PM_LOCK_FILE} pacman -Syy | zenity --progress --title="${TITLE}" --no-cancel --pulsate --text "${UPD_DB_MSG}" --width=500 --auto-close else # exiting according to user choice exit fi fi # Installing packages if [[ -n ${IN_PKG} ]]; then pacman -Syu --noconfirm ${IN_PKG} | zenity --progress --title="${TITLE}" --no-cancel --pulsate --text "${IN_WORKING_MSG}" --width=500 --auto-close fi # Uninstalling packages if [[ -n ${RM_PKG} ]]; then pacman -R --noconfirm ${RM_PKG} | zenity --progress --title="${TITLE}" --no-cancel --pulsate --text "${RM_WORKING_MSG}" --width=500 --auto-close fi # Letting user know that packages have been installed zenity --info --text="${DONE}" --width=500 --height=300 # removing files no longer needed if [[ -f ${IN_PKG_FILE} ]]; then rm ${IN_PKG_FILE} fi if [[ -f ${RM_PKG_FILE} ]]; then rm ${RM_PKG_FILE} fi if [[ -f ${PM_STATUS_FILE} ]]; then rm ${PM_STATUS_FILE} fi if [[ -f ${PM_LOCK_FILE} ]]; then rm ${PM_LOCK_FILE} fi