TL;DR this post is introducing
awk
,diff
,wc
,tr
,bash
, andfind
, that's all about.
Background story
I was following Bliss OS build guide on their official site but it require some dependencies to be installed first.
and unfortunately, the tutorial using ubuntu's package manager.
The unix tool
At this point, the unix tool comes in handy to overcome this situation.
First, I fetch the list of ubuntu's packages name and save it to a file list_package.txt
, and then re-format it with tr
:
tr ' ' '\n' < list_package.txt > list_pkg.txt
and I create a script to check if the program is not found:
#!/usr/bin/sh
for pkg_name in "$@"
do
which "$pkg_name" &>/dev/null
if [[ $? -ne 0 ]]; then
echo "$pkg_name"
fi
done
and run it: sh check_pkg.sh $(cat ./list_pkg.txt) > not_found.txt
now the file not_found.txt
will contain installed package and vice versa.
you can check amount of dependencies with wc -l
command, the list_pkg.txt
file contain 59 packages, and after applying the first filter, the not_found.txt
file contain 41 packages.
and now let's move to the another filter, omit/exclude the installed packages from the list. I can modify the script to use pacman -T $pkg_name
instead of which
and pipe it into new file really_not_found.txt
, now it contain only 36 packages.
alright, the current list contain the package name that are either invalid package name or valid but not installed yet, let's narrow it down.
sudo pacman -S $(cat really_not_found.txt) 2>&1 | awk '{ print $5 }' > really_fcking_not_found.txt
well... now it's 26 left, finally. The rest is manual checking I guess.
[hemlo@asus tmp]$ wc -l ./list_pkg.txt
59 ./list_pkg.txt
[hemlo@asus tmp]$ wc -l ./not_found.txt
41 ./not_found.txt
[hemlo@asus tmp]$ wc -l ./really_not_found.txt
36 ./really_not_found.txt
[hemlo@asus tmp]$ wc -l really_fcking_not_found.txt
26 really_fcking_not_found.txt
you can
diff
bothreally_not_found.txt
andreally_fcking_not_found.txt
to figure out which valid package name that aren't installed yet.
I often use other program like find
and bash expansion feature for creating multiple sub-directory with mkdir
, Can your Windows program do that? :P
someone on #archlinux
IRC channel mention: ansible has nice function to make sure packages are installed instead of diy script it (still have to figure out package names tho). But I have zero experience or knowledge on such thing, so I'll pass on it :)
this approach indeed takes a lot of time in the first shot, but I'm pretty sure that you'll get faster if you've experienced enough. My workflow to dealing with this situation is indeed not efficient from the pro's point-of-view, no doubt about that. So, feel free to suggest an improvement on the comment section :)