Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added openRC daemon #178

Merged
merged 7 commits into from
Nov 2, 2021
Merged

Added openRC daemon #178

merged 7 commits into from
Nov 2, 2021

Conversation

Schievel1
Copy link
Collaborator

So this guy https://github.com/oshaughnessyj/grub-btrfs-openrc is not answering to my pull request and I can not figure out an other way to contact him. So I did the openRC daemon.

I could not find a better way than polling for the snapshot directory of timeshift every five seconds until it is mounted. This only works because the directory is only available after timeshift mounted the parent directory.
Its a terrible hack, and I would be happy if someone has a better idea how to do this. But I am testing the daemon right now on my system an it works fine.

I also changed the Makefile to decide if systemd and openRC are present on the system and install the corresponding service. Checking for systemd by checking if /run/systemd/system exists is also kind of terrible, but this is how they do it: https://www.freedesktop.org/software/systemd/man/sd_booted.html

@Antynea
Copy link
Owner

Antynea commented Oct 25, 2021

Hello,
bravo for your efforts.

Its a terrible hack, and I would be happy if someone has a better idea how to do this. But I am testing the daemon right now on my system an it works fine.

I have no new ideas at the moment...

I also changed the Makefile to decide if systemd and openRC are present on the system and install the corresponding service.

I wonder if this is a problem for building the package on Arch Linux.
@maximbaz , hello, Do you think it breaks anything ?

@Antynea
Copy link
Owner

Antynea commented Oct 29, 2021

@maximbaz
Sorry to ping you again, but I remember a conversation about a major change in the MAKEFILE file that wasn't good to implement due to a chroot environment to build for the package.
@Kr1ss-XD was the author.
@Schievel1 would like to implement automatic detection of (systemd / openrc) in the file,
wouldn't it be better to use a parameter, as we did before for mkinitcipo ?

@maximbaz
Copy link
Contributor

Hey! Thanks for pinging me again, it's very helpful! And you were correct, I just tested this, it won't work as is when building an Arch package, I get the following error strings: '/sbin/init': No such file and so systemd stuff is not getting included.

I think a parameter would make more sense, both not to deal with chroot (less magic is better 😁 ) and also for consistency, so that all things are configured identically.

Finally, I can see in patch you use if [[, just be aware that [[ does not exist in POSIX shell, so maybe switch to if test as it's done for mkinitcpio check.

I'll keep an eye for the thread, to see if you keep systemd as "default choice", and if not I'll remember to pass the parameter to use systemd when building Arch package.

Thanks again for the ping, sorry it took me long to reply 🙂

@Antynea
Copy link
Owner

Antynea commented Oct 30, 2021

hello,

Hey! Thanks for pinging me again, it's very helpful! And you were correct, I just tested this, it won't work as is when building an Arch package, I get the following error strings: '/sbin/init': No such file and so systemd stuff is not getting included.

Thank you very much for your message, it is much appreciated.
You confirm my fears about this implementation.

I'll keep an eye for the thread, to see if you keep systemd as "default choice", and if not I'll remember to pass the parameter to use systemd when building Arch package.

If systemd is the default choice, to use OpenRC it will be necessary to disable systemd and enable OpenRC.
Is this an appropriate choice ?

e.g: make SYSTEMD=false OPENRC=true install

Makefile with systemd(by default)/ OpenRC parameters:
PKGNAME ?= grub-btrfs
PREFIX ?= /usr

INITCPIO ?= false
SYSTEMD ?= true
OPENRC ?= false


SHARE_DIR = $(DESTDIR)$(PREFIX)/share
LIB_DIR = $(DESTDIR)$(PREFIX)/lib
BIN_DIR = $(DESTDIR)$(PREFIX)/bin


.PHONY: install uninstall help

install:
  @if test "$(shell id -u)" != 0; then \
  	echo "You are not root, run this target as root please."; \
  	exit 1; \
  fi
  @install -Dm755 -t "$(DESTDIR)/etc/grub.d/" 41_snapshots-btrfs
  @install -Dm644 -t "$(DESTDIR)/etc/default/grub-btrfs/" config
  @# Systemd init system
  @if test "$(SYSTEMD)" = true; then \
  	install -Dm644 -t "$(LIB_DIR)/systemd/system/" grub-btrfs.path; \
  	install -Dm644 -t "$(LIB_DIR)/systemd/system/" grub-btrfs.service; \
   fi
  @# OpenRC init system
  @if test "$(OPENRC)" = true; then \
  	install -Dm744 -t "$(BIN_DIR)/" grub-btrfs-openrc; \
  	install -Dm744 -t "$(DESTDIR)/etc/init.d/" grub-btrfsd; \
   fi
  @# Arch Linux like distros only :
  @if test "$(INITCPIO)" = true; then \
  	install -Dm644 "initramfs/Arch Linux/overlay_snap_ro-install" "$(LIB_DIR)/initcpio/install/grub-btrfs-overlayfs"; \
  	install -Dm644 "initramfs/Arch Linux/overlay_snap_ro-hook" "$(LIB_DIR)/initcpio/hooks/grub-btrfs-overlayfs"; \
   fi
  @install -Dm644 -t "$(SHARE_DIR)/licenses/$(PKGNAME)/" LICENSE 
  @install -Dm644 -t "$(SHARE_DIR)/doc/$(PKGNAME)/" README.md
  @install -Dm644 "initramfs/readme.md" "$(SHARE_DIR)/doc/$(PKGNAME)/initramfs-overlayfs.md"

uninstall:
  @if test "$(shell id -u)" != 0; then \
  	echo "You are not root, run this target as root please."; \
  	exit 1; \
  fi
  @grub_dirname="$$(grep -oP '^[[:space:]]*GRUB_BTRFS_GRUB_DIRNAME=\K.*' "$(DESTDIR)/etc/default/grub-btrfs/config" | sed "s|\s*#.*||;s|(\s*\(.\+\)\s*)|\1|;s|['\"]||g")"; \
   rm -f "$${grub_dirname:-/boot/grub}/grub-btrfs.cfg"
  @rm -f "$(DESTDIR)/etc/default/grub-btrfs/config"
  @rm -f "$(DESTDIR)/etc/grub.d/41_snapshots-btrfs"
  @rm -f "$(LIB_DIR)/systemd/system/grub-btrfs.path;
  @rm -f "$(LIB_DIR)/systemd/system/grub-btrfs.service;
  @rm -f "$(BIN_DIR)/grub-btrfs.openrcbin;
  @rm -f "$(DESTDIR)/etc/init.d/grub-btrfs.openrc;
  @rm -f "$(LIB_DIR)/initcpio/install/grub-btrfs-overlayfs"
  @rm -f "$(LIB_DIR)/initcpio/hooks/grub-btrfs-overlayfs"
  @# Arch Linux UNlike distros only :
  @if test "$(INITCPIO)" != true && test -d "$(LIB_DIR)/initcpio"; then \
  	rmdir --ignore-fail-on-non-empty "$(LIB_DIR)/initcpio/install" || :; \
  	rmdir --ignore-fail-on-non-empty "$(LIB_DIR)/initcpio/hooks" || :; \
  	rmdir --ignore-fail-on-non-empty "$(LIB_DIR)/initcpio" || :; \
   fi
  @rm -f "$(SHARE_DIR)/doc/$(PKGNAME)/README.md"
  @rm -f "$(SHARE_DIR)/doc/$(PKGNAME)/initramfs-overlayfs.md"
  @rm -f "$(SHARE_DIR)/licenses/$(PKGNAME)/LICENSE"
  @rmdir --ignore-fail-on-non-empty "$(SHARE_DIR)/doc/$(PKGNAME)/" || :
  @rmdir --ignore-fail-on-non-empty "$(SHARE_DIR)/licenses/$(PKGNAME)/" || :
  @rmdir --ignore-fail-on-non-empty "$(DESTDIR)/etc/default/grub-btrfs" || :

help:
  @echo
  @echo "Usage: $(MAKE) [ <parameter>=<value> ... ] [ <action> ]"
  @echo
  @echo "  actions: install"
  @echo "           uninstall"
  @echo "           help"
  @echo
  @echo "  parameter | type | description                    | defaults"
  @echo "  ----------+------+--------------------------------+----------------------------"
  @echo "  DESTDIR   | path | install destination            | <unset>"
  @echo "  PREFIX    | path | system tree prefix             | '/usr'"
  @echo "  SHARE_DIR | path | shared data location           | '\$$(DESTDIR)\$$(PREFIX)/share'"
  @echo "  LIB_DIR   | path | system libraries location      | '\$$(DESTDIR)\$$(PREFIX)/lib'"
  @echo "  PKGNAME   | name | name of the ditributed package | 'grub-btrfs'"
  @echo "  INITCPIO  | bool | include mkinitcpio hook        | false"
  @echo "  SYSTEMD   | bool | include unit files             | true"
  @echo "  OPENRC    | bool | include OpenRc daemon          | false"
  @echo

Makefile

@Schievel1
Copy link
Collaborator Author

If systemd is the default choice, to use OpenRC it will be necessary to disable systemd and enable OpenRC. Is this an appropriate choice ?

e.g: make SYSTEMD=false OPENRC=true install
Makefile with systemd(by default)/ OpenRC parameters:

Makefile

its fine with me. I don't know much about Arch packages and how they work, so bear with me here.
I will do the auto detection in the ebuild script or as a use flag then instead. Maybe that would have been the better place to do it in the first place.

@Antynea
Copy link
Owner

Antynea commented Oct 31, 2021

its fine with me. I don't know much about Arch packages and how they work, so bear with me here.

Writing a MAKEFILE file isn't easy.
When someone requests a modification, I have to make sure that it is coherent and doesn't interfere with the initial project.
I noticed a major change that I thought might break something.
So I asked for help, so that we could solve this problem together.
No offence intended.

I will do the auto detection in the ebuild script or as a use flag then instead. Maybe that would have been the better place to do it in the first place.

If your distribution allows it, this would indeed be a good solution.

@Antynea Antynea merged commit 3b0d0c4 into Antynea:master Nov 2, 2021
@Schievel1 Schievel1 deleted the openrc branch November 2, 2021 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants