Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A simple Bash script I wrote to automate copying PKGBUILD scripts and makepkg in Arch Linux
#!/bin/bash
yesno()
{
echo -ne "$1 [Y/n] "
read -r
case $REPLY in
[yY]) return 0 ;;
*) return 1 ;;
esac
}
if [ -z "$2" ] || [ "$1" != "-S" ]; then
echo "Usage: $0 -S [package]"
exit 0
fi
ABS_DIRS=("/var/abs/core" "/var/abs/extra" "/var/abs/community")
BUILD_DIR="$HOME/abs"
# To turn off colors, comment these lines
RED="\e[1;31m"
BLUE="\e[1;34m"
GREEN="\e[1;32m"
YELLOW="\e[1;33m"
EC="\e[0m"
if [ ! -d "$BUILD_DIR" ]; then
mkdir -p "$BUILD_DIR" || exit 1
fi
shift
for PKG in "$@"; do
INSTALL_FILE="${PKG}.install"
found=0
for dir in ${ABS_DIRS[@]}; do
cd $dir
if [ -d $PKG ]; then
found=1
break
fi
done
if [ $found -eq 0 ]; then
echo -e "${RED}::${EC} Package '$PKG' not found" 1>&2
continue
fi
# Copy the package directory from ABS
cp -R $PKG "${BUILD_DIR}"
echo -e "${BLUE}::${EC} $PKG found in `pwd` and copied to $BUILD_DIR"
# Move to the build directory
cd "${BUILD_DIR}"/${PKG}
if yesno "${GREEN}::${EC} Edit PKGBUILD?"; then
$EDITOR PKGBUILD
fi
if [ -e $INSTALL_FILE ]; then
if yesno "${GREEN}::${EC} Edit $INSTALL_FILE?"; then
$EDITOR $INSTALL_FILE
fi
fi
echo "Enter the arguments to be passed to makepkg"
echo -n "> "
read -r
makepkg $REPLY || exit 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment