Big update

This commit is contained in:
Eduard Tolosa 2018-08-05 01:39:37 -05:00
parent 2370494d6b
commit b8d3404bca

View file

@ -1,11 +1,29 @@
#!/bin/sh
# install AUR packages
basebuilddir="$HOME/.simpleaur/Build"
pacmanexist=$(command -v pacman 2> /dev/null)
lockfile="$basebuilddir/simpleaur.lock"
# prefer terminal safe colored and bold text when tput is supported - /usr/share/makepkg/util/message.sh
if tput setaf 0 &>/dev/null; then
ALL_OFF="$(tput sgr0)"
BOLD="$(tput bold)"
BLUE="${BOLD}$(tput setaf 4)"
GREEN="${BOLD}$(tput setaf 2)"
RED="${BOLD}$(tput setaf 1)"
YELLOW="${BOLD}$(tput setaf 3)"
else
ALL_OFF="\e[0m"
BOLD="\e[1m"
BLUE="${BOLD}\e[34m"
GREEN="${BOLD}\e[32m"
RED="${BOLD}\e[31m"
YELLOW="${BOLD}\e[33m"
fi
readonly ALL_OFF BOLD BLUE GREEN RED YELLOW
ctrl_c() {
printf '\n\e[1;31m%-6s\e[m\n' 'Keyboard Interrupt detected, removing lock file and leaving...'
printf "\n${RED}Keyboard Interrupt detected, removing lock file and leaving...\n"
rm "$lockfile"
exit
}
@ -13,11 +31,8 @@ ctrl_c() {
trap ctrl_c 2
#Make sure that you are using an ArchLinux system
if [ -x "$pacmanexist" ]; then
printf ""
else
printf '\n\e[1;31m%-6s\e[m\n' "Error: You are not using ArchLinux, pacman was not found in ($PATH)"
rm "$lockfile"
if ! command -v pacman > /dev/null; then
printf "\n${RED}Error: You are not using ArchLinux, pacman was not found in ($PATH)\n"
exit
fi
@ -28,8 +43,8 @@ fi
#Prevent two instances running at same time
if [ -f "$lockfile" ]; then
printf '\n\e[1;31m%-6s\e[m\n' 'simpleaur is running, leaving.'
printf '\n\e[1;31m%-6s\e[m\n' "If you are sure that simpleaur is not running, delete [ $lockfile ]"
printf "\n${RED}simpleaur is running, leaving.\n"
printf "\n${RED}If you are sure that simpleaur is not running, delete [ $lockfile ]\n"
exit
else
touch "$lockfile"
@ -37,7 +52,7 @@ fi
#Verify that package names are not empty
if [ -z "$*" ] ; then
printf '\n\e[1;31m%-6s\e[m\n' 'Error: Please, pass AUR package(s) name(s) to simpleaur.'
printf "\n${RED}Error: Please, pass AUR package(s) name(s) to simpleaur.\n"
rm "$lockfile"
exit
else
@ -46,21 +61,12 @@ fi
# Check if the package was already downloaded and then download the PKGBUILDs accordly to user needs.
for ipackage in "$@"; do
if [ -d "$basebuilddir/$ipackage" ]; then
printf '\n\e[1;32m%-6s\e[m\n' "PKGBUILD for [ $ipackage ] exist in the [ $basebuilddir/$ipackage ] directory, if you want to update the package because an update was found by simplecheck, then you need remove the existing directory to update the package, otherwise you are reinstaling the same package version that's already installed."
printf '\n\e[1;33m%-6s\e[m' "Remove the [ $basebuilddir/$ipackage ] directory? [Y/n] "
read -r rmolddir
if [ "$rmolddir" = "y" ] || [ "$rmolddir" = "Y" ] ; then
printf '\n\e[1;32m%-6s\e[m\n' 'Info: removing the old directory and getting the new sources...'
rm -rf "$basebuilddir/$ipackage"
git clone "https://aur.archlinux.org/${ipackage}.git"
continue
elif [ "$rmolddir" = "n" ]; then
continue
else
printf '\n\e[1;33m%-6s\e[m\n' 'Warning: Wrong option, continuing...'
continue
fi
if [ -f "$basebuilddir/$ipackage/PKGBUILD" ]; then
printf "\n${GREEN}PKGBUILD for ${BLUE}[ $ipackage ] ${GREEN}exist in the ${BLUE}[ $basebuilddir/$ipackage ] ${GREEN}directory, pulling the git directory and reinstalling/updating the packages.\n"
cd "$basebuilddir/$ipackage" || exit
git pull
cd "$basebuilddir" || exit
continue
else
git clone "https://aur.archlinux.org/${ipackage}.git"
fi
@ -69,13 +75,10 @@ done
# Check PKGBUILDs.
for ipackage in "$@"; do
cd "$basebuilddir/$ipackage" || exit
printf '\e[1;33m%-6s\e[m' "View PKGBUILD for [ $ipackage ]? [Y/n] "
printf "${BLUE}View PKGBUILD for [ $ipackage ]? [Y/n] ${ALL_OFF}"
read -r answer
if [ "$answer" = "y" ] || [ "$answer" = "Y" ] ; then
${EDITOR} PKGBUILD
continue
else
continue
fi
done
@ -88,39 +91,39 @@ for ipackage in "$@"; do
cd "$ipackage" || exit
if makepkg -sci ; then
cd "$basebuilddir" || exit
printf '\e[1;32m%-6s\e[m\n\n' "The package [ $ipackage ] has been installed"
printf "\n${GREEN}The package ${BLUE}[ $ipackage ] ${GREEN}has been installed.\n"
continue
else
printf '\n\e[1;31m%-6s\e[m' "Error: Installation for the package [ $ipackage ] was not completed."
printf '\n\e[1;33m%-6s\e[m' "Do you want to continue? [Y/n] "
printf "\n${RED}Error: Installation for the package ${BLUE}[ $ipackage ] ${RED}was not completed.\n"
printf "${YELLOW}Do you want to continue? [Y/n] ${ALL_OFF}"
read -r answer
if [ "$answer" = "y" ] || [ "$answer" = "Y" ] ; then
cd "$basebuilddir" || exit
continue
else
printf '\e[1;32m%-6s\e[m\n' 'Info: finishing tasks...'
printf "${GREEN}Info: finishing tasks..."
break
fi
fi
else
printf '\n\e[1;31m%-6s\e[m\n' "Error: The PKGBUILD file for [ $ipackage ] does not exist, please check your internet connection and make sure that the AUR package name exists, you can use simplesearch for that."
printf '\n\e[1;32m%-6s\e[m\n' 'Info: Removing the failed build directory...'
printf "${RED}Error: The PKGBUILD file for the package ${YELLOW}[ $ipackage ] ${RED}does not exist, please check your internet connection and make sure that the AUR package name exists, you can use simplesearch for that.\n"
printf "${GREEN}Info: Removing the failed build directory...\n\n"
rm -rf "$basebuilddir/$ipackage"
fi
done
#Ask to the user if want to remove the directory created for git
printf '\e[1;33m%-6s\e[m' 'Remove previously compiled packages? [Y/n] '
printf "\n${YELLOW}Remove previously compiled packages? [Y/n] ${ALL_OFF}"
read -r yn
#Take the answer from the user input and decide what to do.
if [ "$yn" = "y" ] || [ "$yn" = "Y" ] ; then
printf '\e[1;32m%-6s\e[m\n' 'Info: Removing previously compiled packages...'
printf "\n${GREEN}Info: Removing previously compiled packages...\n"
for ipackage in "$@"; do
rm -rf "$basebuilddir/$ipackage"
done
printf '\e[1;32m%-6s\e[m\n' 'Info: Leaving'
printf "${GREEN}Info: Leaving\n"
else
printf '\e[1;32m%-6s\e[m\n' 'Info: Leaving'
printf "${GREEN}Info: Leaving\n"
fi
rm -f "$lockfile"
exit