Skip to content

Instantly share code, notes, and snippets.

@cookiengineer
Last active September 11, 2023 20:06
Show Gist options
  • Star 31 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • 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;
@melroy89
Copy link

melroy89 commented Nov 8, 2016

Love it! This definitely higher the accessibility to new users in a Arch-like distro!

@cookiengineer
Copy link
Author

Added some features I regularly used over the last months: clean, changelog, download and policy.

@materemias
Copy link

lol, awesome idea :))

@famewolf
Copy link

famewolf commented Jul 15, 2018

Any chance for a "dpkg -l " equivalent so I can use grep to see what packages are already installed vs whats available?

famewolf@hp810-135qe ~/Downloads/linux $ dpkg -l | grep opera
ii  eject                                                       2.1.5+deb1+cvs20081104-13.1ubuntu0.16.04.1               amd64        ejects CDs and operates CD-Changers under Linux
ii  libboost-filesystem1.58.0:amd64                             1.58.0+dfsg-5ubuntu3.1                                   amd64        filesystem operations (portable paths, iteration over directories, etc) in C++
ii  libcrypt-passwdmd5-perl                                     1.3-10                                                   all          interoperable MD5-based crypt() for perl
ii  libostree-1-1:amd64                                         2017.12-0alexlarsson1~xenial                             amd64        content-addressed filesystem for operating system binaries (library)
ii  opera-stable                                                54.0.2952.54                                             amd64        Fast and secure web browser

@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