Skip to content

Instantly share code, notes, and snippets.

@ShalokShalom
Last active September 23, 2023 14:55
Show Gist options
  • Save ShalokShalom/95009e04452de8407c794af8c6df3695 to your computer and use it in GitHub Desktop.
Save ShalokShalom/95009e04452de8407c794af8c6df3695 to your computer and use it in GitHub Desktop.
From Pacman to Habitat
This page aims to pick up Pacman users from where they are and bring them to the world of Habitat:
'General hints'
What is a PKGBUILD at Pacman, is a plan.sh at Habitat.
In general, both use bash scripts and a very simple approach.
Habitat builds all in own chroot environments, which are called studios.
You access such a studio with the command "hab studio enter"
Be aware about the fact, that you can use different studios on different locations,
so the studio inside your /home/username/ is this another one as that one in your /home/username/habitat.
You can put a .studiorc file in each studio directory and use that one like a .bashrc inside the studio.
Its also helpful to export ENVIRONMENT=values. https://www.habitat.sh/docs/reference/environment-vars/
Since you manage practically everything at the packages itself, including their relationship to a specific depo,
is the following topic important to know also: Keys and Depos. (upcoming section and/or link to an updated document)
Be also aware to put basic stuff like core/gcc, core/gcc-libs, core/automake, core/autoconf and core/pkg-config into the pkg_build_deps section
Here are the core differences between the syntax of Pacman and Habitat:
pkgname=pkg_name
pkgver=pkg_version
pkgdir=pkg_prefix
depends=pkg_deps
makedepends=pkg_build_deps
url=pkg_upstream_url
source=pkg_source
md5sums=pkg_shasum
sha1sums=pkg_shasum
sha256sums=pkg_shasum
sha512sums=pkg_shasum
license=pkg_license
srcdir=CACHE_PATH
https://www.habitat.sh/docs/reference/plan-syntax/
~~~
Functions / Callbacks
They are most often optional, since there are default commands like ./configure --prefix=$pkg_prefix, when do_build() is not used.
prepare()=do_prepare()
pkgver()=do_download()
build()=do_build()
check()=do_check() To use this callback, two conditions must be true.¹
package()=do_install()
~~~
Unique variables
In Arch:
pkgbase= https://github.com/habitat-sh/habitat/issues/2548
options= delete the whole line
pkgrel= delete the whole line, since it gets added automatically in Habitat
arch= delete the whole line, since x86_64 is currently (June17) the only single one supported arch.
optdepends= there are not existent, use pkg_deps= and pkg_build_deps=
checkdepends= also not present, use pkg_deps for that one.
conflicts, replaces, provides= not present currently
In Habitat:
pkg_origin= defines the depo
pkg_dirname= specify a directory name for where your extracted source is going to live, default is pkg_name-pkg_version
pkg_maintainer= says it all
~~~
Hints for porters:
If you literally port PKGBUILDs to plan.sh files, here is how i do it:
1) You can use the search and replace feature by text editors like Kate.
If you went into issues, reduce the number of files that you change at once.
In Kate, you can simply choose a folder and the changes get applied recursive.
Be aware, that this change more as PKGBUILDs, so you also change patches, licenses and so on by default. Kate lets you choose, which files to add, sorted by their name. Might be, that you even like to change some of those too, i recommend you to check them with a simple double click. Save them all with Ctrl + L.
2) Here is one single command, which deletes the very most "Pacman-only" stuff for you, run it on the first level of your PKGBUILD directory structure: (Be aware that bash is your shell, does not work in fish for example)
find . -name PKGBUILD* -exec sed -i '/^arch=/d' {} + && find . -name PKGBUILD* -exec sed -i '/^pkgrel=/d' {} + && find . -name PKGBUILD* -exec sed -i '/^options=/d' {} + && find . -name PKGBUILD* -exec sed -i '/^replaces=/d' {} + && find . -name PKGBUILD* -exec sed -i '/^conflicts=/d' {} + && find . -name PKGBUILD* -exec sed -i '/^provides=/d' {} + && find . -name PKGBUILD* -exec sed -i '/^epoch=/d' {} + && find . -name PKGBUILD* -exec sed -i '/^backup=/d' {} + && find . -name PKGBUILD* -exec sed -i '/^[[:blank:]]*cd/d' {} + && find . -name PKGBUILD* -exec sed -i '/^groups=/d' {} + && find . -name PKGBUILD* -exec sed -i '/^install=/d' {} +
3) In order to add pkg_origin and the other Habitat exclusive functions, run: (replace pkg_origin in this command with pkg_maintainer, if you want one/some to set).
find . -name PKGBUILD* -exec sed -i $'1i\\\npkg_origin=' {} +
Hint: You can replace pkg_origin= with pkg_origin=myoriginname of course.
4) Finally, replace all the PKGBUILD files with plan.sh (and remind that the commands in 1-3 here cant work then anymore, unless you replace PKGBUILD with plan.sh there)
find . name "*PKGBUILD*" -exec rename PKGBUILD plan.sh '{}' \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment