Minimalistic AUR-complient pacman wrapper
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

352 lines
10 KiB

#!/usr/bin/env bash
# pamod (PAkka MODified) is simple AUR-complient pacman wrapper written in bash
SELF=pamod
SELF_PROG=$0
SELF_VER=1.6.6
SELF_URL=http://codeberg.org/glowiak/pamod
SELF_RAW_URL=http://codeberg.org/glowiak/pamod/raw/branch/master/pamod
CONFIGDIR=${CONFIGDIR:-$HOME/.config/pamod}
if [ ! -f "$CONFIGDIR/config" ]; then
echo "$SELF: Config file doesn't seems to exists, so using the defaults"
fi
CACHEDIR="${HOME}/.pamod_cache" # not all people write config files, this is the default CACHEDIR
if [ -f "$CONFIGDIR/config" ]; then
. "$CONFIGDIR/config"
fi
if [ ! -f "/usr/bin/package-query" ]; then
echo "$SELF: Cannot find package-query on your system!"
echo "$SELF: Please install package-query and rerun the script"
exit 1
fi
mkdir -p "$CACHEDIR/archive"
mkdir -p "$CACHEDIR/packaging"
mkdir -p "$CACHEDIR/packages"
as_root()
{
if [[ "`whoami`" == "root" ]]; then
$*
elif [[ -x "$(command -v doas)" ]]; then
doas $*
elif [[ -x "$(command -v sudo)" ]]; then
sudo $*
else
su root -c "$*"
fi
}
die()
{
echo "[FATAL ERROR] $*"
exit 1
}
msg_info()
{
echo "[INFO] $*"
}
msg_error()
{
echo "[ERROR] $*"
exit 1
}
msg_warn()
{
echo "[WARNING] $*"
}
exitm() {
exit "$1"
}
install_aur_pkg() {
i="$1"
msg_info "Building $i"
SRCDIR=$CACHEDIR/packaging/$i
if [ ! -f "$CACHEDIR/archive/$i.tar.gz" ]; then
curl -L -o "$CACHEDIR/archive/$i.tar.gz" "https://aur.archlinux.org/cgit/aur.git/snapshot/$i.tar.gz" || msg_error "Couldn't download PKGBUILD"
fi
tar xzf "$CACHEDIR/archive/$i.tar.gz" -C "$CACHEDIR/packaging" || msg_error "Couldn't extact file"
cd "$SRCDIR"
case $(uname -m) in
i686)
echo -n "$SELF: ArchLinux32 detected, do you want to patch PKGBUILD to use pentium4 architecture? (will not work without that!) [y/n] "
read pentiumq
case "$pentiumq" in
y)
msg_info "Patching..."
sed -i 's/i686/pentium4/' PKGBUILD
;;
*)
msg_error "In ArchLinux32, without patching, you cannot use AUR!"
exit 1
;;
esac
esac
echo -n "$SELF: Wanna see PKGBUILD? [y/n] "
read q1
if [ "$q1" == "y" ]; then
less PKGBUILD
fi
echo -n "$SELF: Start building ${i}? [y/n] "
read prompt
if [ ! "$prompt" == "y" ]; then
rm -rf "$CACHEDIR/packaging/$i"
rm -rf "$CACHEDIR/archive/$i.tar.gz"
msg_error Interrupted!
fi
if [ -d "$CONFIGDIR/overrides/$i/srcpatch" ];
then
msg_info "Patching"
for j in $(ls $CONFIGDIR/overrides/$i/srcpatch/)
do
patch -p1 < "$CONFIGDIR/overrides/$i/srcpatch/$j"
msg_info "Patched $j !" || {
echo -n "$SELF: Failed to patch. Ignore it and continue? [y/n] "
read prompt2
if [ ! "$prompt2" == "y" ]; then
msg_error Interrupted
fi
}
done
fi
if [ -d $"CONFIGDIR/overrides/$i/srccopy" ];
then
cp -rv "$CONFIGDIR/overrides/$i/srccopy/*" "$SRCDIR" # i don't know why everything is doing so useless code parts. every path sould be double quoted
fi
makepkg -s -o || msg_error "Couldn't execute makepkg"
if [ -d "$CONFIGDIR/overrides/$i/copy" ];
then
cp -rv "$CONFIGDIR/overrides/$i/copy/*" "$SRCDIR/src" # again...
fi
cd src/
if [ -d "$CONFIGDIR/overrides/$i/patch" ];
then
msg_info "Patching"
for j in $(ls $CONFIGDIR/overrides/$i/patch/) # agaaaaain
do
patch -p1 < "$CONFIGDIR/overrides/$i/patch/$j"
msg_info "Patched $j !" || {
read -rp "$SELF: Failed Patch $j! Do you want to continue without it? [y/n] " prompt3
if [ ! "$prompt3" == "y" ]; then
msg_error Interrupted!
fi
}
done
fi
cd ..
makepkg -sci || {
read -rp "$SELF: Do you want to disable verify checks? [y/n] " prompt
if [[ $prompt == "y" ]];
then
makepkg -sci --skipinteg
fi
}
PKGFILE=$(ls ./*.pkg.ta*)
cp "${PKGFILE}" "$CACHEDIR/packages/"
}
install_aur_pkg_nc() {
i="$1"
msg_info "Building $i"
SRCDIR=$CACHEDIR/packaging/$i
if [ ! -f "$CACHEDIR/archive/$i.tar.gz" ]; then
curl -L -o "$CACHEDIR/archive/$i.tar.gz" "https://aur.archlinux.org/cgit/aur.git/snapshot/$i.tar.gz" || msg_error "Couldn't download PKGBUILD"
fi
tar xzf "$CACHEDIR/archive/$i.tar.gz" -C "$CACHEDIR/packaging" || msg_error "Couldn't extact file"
cd "$SRCDIR"
case $(uname -m) in
i686)
msg_info "ArchLinux32 detected, patching architecture..."
sed -i 's/i686/pentium4/' PKGBUILD
;;
esac
if [ -d "$CONFIGDIR/overrides/$i/srcpatch" ];
then
msg_info "Patching"
for j in $(ls $CONFIGDIR/overrides/$i/srcpatch/)
do
patch -p1 < "$CONFIGDIR/overrides/$i/srcpatch/$j"
msg_info "Patched $j !" || {
msg_error "Failed to patch ${j}!"
}
done
fi
if [ -d $"CONFIGDIR/overrides/$i/srccopy" ];
then
cp -rv "$CONFIGDIR/overrides/$i/srccopy/*" "$SRCDIR" # i don't know why everything is doing so useless code parts. every path sould be double quoted
fi
makepkg -s -o --noconfirm || msg_error "Couldn't execute makepkg"
if [ -d "$CONFIGDIR/overrides/$i/copy" ];
then
cp -rv "$CONFIGDIR/overrides/$i/copy/*" "$SRCDIR/src" # again...
fi
cd src/
if [ -d "$CONFIGDIR/overrides/$i/patch" ];
then
msg_info "Patching"
for j in $(ls $CONFIGDIR/overrides/$i/patch/) # agaaaaain
do
patch -p1 < "$CONFIGDIR/overrides/$i/patch/$j"
msg_info "Patched $j !" || {
msg_error "Failed to patch ${j}!"
}
done
fi
cd ..
makepkg -sci --noconfirm || makepkg -sci --skipinteg --noconfirm
PKGFILE=$(ls ./*.pkg.ta*)
cp "${PKGFILE}" "$CACHEDIR/packages/"
}
case "$1" in
-C)
msg_info "Removing Cache Dir"
rm -rf "$CACHEDIR"
exit 0
;;
-Ss)
search_string="$(echo $* | sed 's/-Ss //')"
/usr/bin/package-query -A -Q --insecure -s "$search_string"
/usr/bin/pacman -Ss "$search_string"
exit 0
;;
-G)
get_pkg_list="$(echo $* | sed 's/-G //')"
for listpkg in $get_pkg_list; do
msg_info "Downloading package ${listpkg}'s PKGBUILD to current directory"
curl -L -o ./$listpkg.PKGBUILD "https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=$listpkg" || die "Couldn't download file!"
msg_info "AUR/$listpkg/PKGBUILD --> $(pwd)/$listpkg.PKGBUILD"
exit 0
done
;;
-V)
msg_info "You're running $SELF version $SELF_VER"
exit 0
;;
-P)
if [ ! -d "$2" ]; then
msg_error "This path doesn't exist"
fi
cd "$2"
makepkg -s || die "makepkg returned error"
exit 0
;;
-Pi)
if [ ! -d "$2" ]; then
msg_error "This path doesn't exist"
fi
cd "$2"
makepkg -si || die "makepkg returned error"
exit 0
;;
-Pn)
if [ ! -d "$2" ]; then
msg_error "This path doesn't exist"
fi
cd "$2"
makepkg -s --noconfirm || die "makepkg returned error"
exit 0
;;
-Pni)
if [ ! -d "$2" ]; then
msg_error "This path does't exist"
fi
cd "$2"
makepkg -si --noconfirm || die "makepkg returned error"
exit 0
;;
--help)
msg_info "$SELF (PAkka MODified) - small, AUR-complient pacman wrapper written in bash"
msg_info "Usage: $SELF {OPTION} package1 package2..."
msg_info "Options:"
msg_info "-C | clean cache"
msg_info "-Ss | search for packages in aur and repos"
msg_info "-G | get PKGBUILD of package"
msg_info "-V | display version of $SELF and exit"
msg_info "-P | build package from specified directory"
msg_info "-Pi | the same as previous, but installs after building"
msg_info "-Pn | the same as '-P', but doesn't asks for anything"
msg_info "-Pni | the same as previous, but installs after building"
msg_info "-J | yogurt (very interactive) mode"
msg_info "-S | install packages from AUR or repos"
msg_info "-SVv | the same as previous, but shot all in verbose output"
msg_info "-Du | do self-upgrade"
msg_info "--help | show this help"
msg_info "Any other arguments will be piped to pacman"
msg_info "Visit projects website at http://codeberg.org/glowiak/${SELF}"
exit 0
;;
"")
msg_info "No arguments given. Type '$SELF --help' for help"
exit 0
;;
-J)
msg_info Entering Yogurt Mode
pkg_lists="$(echo $* | sed 's/-J //')"
if [ "$2" == "" ]; then
msg_error Yogurt Mode cannot search for nothing!
fi
$SELF_PROG -Ss "$pkg_lists"
echo -n "Name of program you want to install: "
read yogurt1
if [ "$yogurt1" == "" ]; then
msg_error "Package air doesn't exists!"
fi
if [ "$(whoami)" == "root" ]; then
msg_error "You shouldn't run yogurt mode as root"
fi
as_root pacman -S $yogurt1 || install_aur_pkg $yogurt1
exit 0
;;
-S)
if [ "$2" == "" ]; then
msg_error "Cannot install air!"
fi
pkg_lists="$(echo $* | sed 's/-S //')"
echo "Packages to be installed: $pkg_lists"
echo -n "Proceed? [y/n] "
read prompt3
if [ ! "$prompt3" == "y" ]; then
msg_error Interrupted!
fi
for pkgs in $pkg_lists; do
msg_info "Installing $pkgs"
as_root pacman -S --noconfirm $pkgs || install_aur_pkg_nc $pkgs
done
exit 0
;;
-SVv)
if [ "$2" == "" ]; then
msg_error "Cannot install air!"
fi
pkg_lists="$(echo $* | sed 's/-SVv //')"
echo "Packages to be installed: $pkg_lists"
echo -n "Proceed? [y/n] "
read prompt3
if [ ! "$prompt3" == "y" ]; then
msg_error Interrupted!
fi
for pkgs in $pkg_lists; do
msg_info "Installing $pkgs"
as_root pacman -S $pkgs || install_aur_pkg $pkgs
done
exit 0
;;
-Du)
msg_info Getting information...
curl -L -o /tmp/pamod-get $SELF_RAW_URL
UPDATE_VERSION="$(cat /tmp/pamod-get | grep SELF_VER | sed 's/SELF_VER=//')"
if [ "$SELF_VER" == "$UPDATE_VERSION" ]; then
msg_error "You already have latest version of $SELF"
fi
msg_info "Upgrading ${SELF}: $SELF_VER --> ${UPDATE_VERSION}"
WHICH_SELF="$(readlink -f $0)"
as_root rm -rf "$WHICH_SELF"
as_root mv /tmp/pamod-get "$WHICH_SELF"
msg_info "Upgraded $SELF to version $UPDATE_VERSION"
exit 0
;;
*)
as_root pacman $*
exit 0
;;
esac