Skip to content

Instantly share code, notes, and snippets.

@cookiengineer
Last active September 11, 2023 20:06
Show Gist options
  • Save cookiengineer/94265370d66ea73f4782f80c231e126c to your computer and use it in GitHub Desktop.
Save cookiengineer/94265370d66ea73f4782f80c231e126c to your computer and use it in GitHub Desktop.
APT-PAC - pacman with APT syntax
#!/bin/bash
# Save this file as /usr/bin/apt-pac and chmod +x it.
case "$1" in
autoremove)
pacman -Rns $(pacman -Qdtq);
;;
clean)
if [ "$2" == "--force" ]; then
pacman -Scc;
else
echo "Use \"apt-pac clean --force\" to remove all packages from cache.";
pacman -Sc;
fi;
;;
changelog)
pacman -Qc "$2";
;;
download)
pacman -Sw "$2";
;;
install)
pacman -S "$2";
;;
policy)
cat /etc/pacman.d/mirrorlist | grep "^[^#]";
;;
rdepends)
pacman -Sii "$2";
;;
remove)
pacman -Rs "$2";
;;
search)
pacman -Ss "$2";
;;
show)
pacman -Qi "$2";
;;
update)
if [ "$2" == "--force" ]; then
pacman -Syy;
else
echo "Use \"apt-pac update --force\" to force-update packages index.";
pacman -Sy;
fi;
;;
upgrade)
pacman -Su;
;;
*|help)
echo "";
echo "aptpac - pacman wrapper for apt-get syntax";
echo "";
echo "";
echo "APT commands:";
echo "";
echo -e "\tautoremove, clean, update, upgrade, policy";
echo "";
echo "Package-specific commands:";
echo "";
echo -e "\tchangelog, download, install, rdepends, remove, search, show";
echo "";
echo "Command-specific flags:";
echo -e "\t--force can be used with clean, update to emulate same behaviour as aptitude.";
echo "";
;;
esac;
@cookiengineer
Copy link
Author

cookiengineer commented Sep 24, 2018

@famewolf I think you might want to use pacman -Qs or similar which shows a per-line output of all (locally) installed packages.

Example:

# similar to dpkg -l | grep chromium
pacman -Qs chromium;

If you want less information and only a "confirmation" that a package with that name is installed, you can also use pacman -Qqs chromium, so it will only show the equivalent package name per-line, so you can also sort and head/tail the output directly.

The idea behind pacman -Ss chromium and pacman -Qs chromium is that Q queries the locally installed database whereas S queries the local package cache (of all mirrors, basically) that is updated/synced via pacman -Sy.

@lucasrdrgs
Copy link

lucasrdrgs commented Apr 17, 2019

@cookiengineer What about a get argument that runs pacman -Syu <package>? I've forked your script and added that to solve some dependency issues and I think it is quite handy. Nice script by the way!

@Architector4
Copy link

About this bit:

update)
	pacman -Syy;
;;

It is absolutely unnecessary to force refresh all repos, as it puts an additional (even if little) strain on the mirrors for no benefit, unless the user knows that their databases are broken, at which point one could run pacman -Syy by themselves. I know, the additional load is minuscule, but this little change is minuscule too, so why not? lol

Also I'm not sure about separate -Sy and -Su commands, as -Sy updates local repo listings but not packages, which counts as a partial upgrade which is not supported by Arch Linux and could cause all kinds of fun stuff with dependencies. Though, I'm not sure myself how to convert apt's separate update and upgrade things to still provide a good result and not cause a partial upgrade. I dunno, at least add a disclaimer comment please?

@cookiengineer
Copy link
Author

I dunno, at least add a disclaimer comment please?

Disclaimer: It's just a goddamn gist, not an AUR package and neither (hopefully) a git repository.
Do whatever you like with it.

@Architector4
Copy link

I will, and I appreciate your work on this. I'm just more worried about other people not reading these comments, copying the entire thing and doing -Syy without -Su and potentially screwing up their system this way.

I mean, can't gists be edited? Is it too much effort to at least remove that one extra y?

@cookiengineer
Copy link
Author

@Architector4 I updated the gist to reflect the same behaviour, while hiding the force-clean and force-update behind a --force flag. I think this is the best compromise in this case.

@Architector4
Copy link

Oh, that's good. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment