Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/k4r4b3y/darkirc-runit

Runit scripts to run DarkFi IRC on termux
https://github.com/k4r4b3y/darkirc-runit

Last synced: about 2 months ago
JSON representation

Runit scripts to run DarkFi IRC on termux

Awesome Lists containing this project

README

        

* DarkIRC-Runit

Some simple runit scripts to automate starting and stopping the
[[https://darkrenaissance.github.io/darkfi/misc/darkirc/darkirc.html][DarkIRC]] daemon.

The =setup.sh= script

1) downloads the =darkirc= compiled binary:
- you can compile yourself and move it its proper directory,
=${HOME}/.local/bin= if you wish.
- I provide a signed sha256sum of the =darkirc= binary so that I
(you) know that github didn't meddle with it.
2) creates runit scripts for =darkirc= so that:
- =darkirc= starts in the background automatically whenever you
start the [[https://termux.dev/en/][Termux app]].
- you can stop the =darkirc= using the =sv stop darkirc= command.
- you can see the =darkirc= daemon's logs using the =tail -f
${PREFIX}/var/log/sv/darkirc/current= command.

** todos

*** TODO do we need to use the command =termux-wake-lock= ?

Can we do it without it? How badly does android (grapheneOS) want to
kill it when it's in the background? Maybe, long tap on termux app ->
battery settings -> allow running in the background, is enough?

** Setup

Git clone this repo in your termux home directory. Install =perl= so
that you can use =shasum -c= command if you want.

#+begin_src bash
pkg install git perl gnupg -y
git clone https://github.com/k4r4b3y/darkirc-runit.git
#+end_src

Check the sha256sum of the =darkirc= binary:

#+begin_src bash
cd ${HOME}/darkirc-runit/bin
shasum -c shasum.txt.asc
#+end_src

You should see the following in the output:

#+begin_quote
darkirc.aarch64-android: OK
shasum: WARNING: 10 lines are improperly formatted
#+end_quote

The important line is the first one, =darkirc.aarch64-android: OK=.
You can verify the signature on the =shasum.txt.asc= file with my gpg
key on [[https://karapara.kyun.li/gpg]].

Then, you should run the install script:

#+begin_src bash
${HOME}/darkirc-runit/bin/setup.sh
#+end_src

During the =setup.sh= script execution, you might see your termux
prompt you with the following:

#+begin_quote
Configuration file '/data/data/com.termux/files/usr/etc/apt/sources.list'

==> File on system created by you or by a script.

==> File also in package provided by package maintainer.

What would you like to do about it ? Your options are:

Y or I : install the package maintainer's version

N or O : keep your currently-installed version

D : show the differences between the versions

Z : start a shell to examine the situation

The default action is to keep your current version.

*** sources.list (Y/I/N/O/D/Z) [default=N] ?
#+end_quote

Here, you can press =Y= and then hit =enter=.

*** Start the darkirc daemon

If the setup executes without errors, you should be able to start the
=darkirc= daemon in the background using the command:

#+begin_src bash
sv-enable darkirc
#+end_src

From then on, whenever you start termux app, the =darkirc= daemon will
also get started in the backgruond.

*** Stop the darkirc daemon

If you want to stop the daemon, use the following command:

#+begin_src bash
sv-disable darkirc
#+end_src

From then on, =darkirc= daemon won't be started automatically whenever
you start the termux app.

*** Check the logs of darkirc daemon

To check the logs of the daemon, use the following command:

#+begin_src bash
tail -f ${PREFIX}/var/log/sv/darkirc/current
#+end_src

-----

The rest of the documentation will go into what each of the scripts in
this repo does. Read on if you are curious.

** Documentation
*** Setup script

Setup script prepares the termux envrionment for running the

1) runit scripts
2) darkirc daemon

Start by defining the runit-related directories, updating the termux
environment, and then installing the =termux-services= which installs
=runit= along with it:

#+begin_src bash :tangle ./bin/setup.sh :mkdirp yes :shebang #!/data/data/com.termux/files/usr/bin/bash
pkg upgrade -y
pkg install termux-services -y
#+end_src

Define some file and directory paths as variables:

#+begin_src bash :tangle ./bin/setup.sh
repo_dir="${HOME}/darkirc-runit"
homelocalbin_dir="${HOME}/.local/bin"
runit_dir="${HOME}/.config/sv"
darkirc_bin="darkirc.aarch64-android"
darkirc_conf="${HOME}/.config/darkfi/darkirc_config.toml"
svdir="${PREFIX}/var/service"
#+end_src

Create the directories for the binary and for the runit service
files if they do not already exist:

#+begin_src bash :tangle ./bin/setup.sh
if [ ! -d "${homelocalbin_dir}" ]; then
mkdir -p "${homelocalbin_dir}"
fi

if [ ! -d "${runit_dir}" ]; then
mkdir -p "${runit_dir}"
fi
#+end_src

Copy the runit scripts into the =${runit_dir}= and make them
executable:

#+begin_src bash :tangle ./bin/setup.sh
cp -r ${repo_dir}/bin/darkirc -t ${runit_dir}
chmod u+x ${runit_dir}/darkirc/run ${runit_dir}/darkirc/log/run
#+end_src

Copy the =darkirc.aarch64-android= binary into its place and make it
executable:

#+begin_src bash :tangle ./bin/setup.sh
cp -r ${repo_dir}/bin/${darkirc_bin} -t ${homelocalbin_dir}
chmod u+x ${homelocalbin_dir}/${darkirc_bin}
#+end_src

And execute it the first time IF the config file isn't in its place:

#+begin_src bash :tangle ./bin/setup.sh
if [ ! -f "${darkirc_conf}" ]; then
${homelocalbin_dir}/${darkirc_bin}
fi
#+end_src

Symlink the runit files to =${SVDIR}=.

#+begin_src bash :tangle ./bin/setup.sh
ln -sf ${runit_dir}/darkirc ${svdir}/
#+end_src

*** Runit scripts

We use runit to start and stop the =darkirc= daemon running in the
background. We also use =svloggerd= to keep the redirec the stdout
of =darkirc= daemon to runit logging utility.

**** conf

This file will hold the environment variables.

#+begin_src bash :tangle ./bin/darkirc/conf :mkdirp yes
# empty for now
#+end_src

**** run

This script starts the =darkirc=. Redirect the stderr to stdout, so
that we can keep track of the errors with =svloggerd=.

#+begin_src bash :tangle ./bin/darkirc/run :mkdirp yes :shebang #!/data/data/com.termux/files/usr/bin/sh
homelocalbin_dir="${HOME}/.local/bin"
darkirc_bin="darkirc.aarch64-android"
exec 2>&1
exec ${homelocalbin_dir}/${darkirc_bin}
#+end_src

**** log/run

#+begin_src bash :tangle ./bin/darkirc/log/run :mkdirp yes :shebang #!/data/data/com.termux/files/usr/bin/sh
svlogger="${PREFIX}/share/termux-services/svlogger"
exec "${svlogger}" "$@"
#+end_src

-----

[[file:assets/powered_by_emacs.svg][This project is powered by emacs]]
[[file:assets/powered_by_org_mode.svg][This project is powered by orgmode]]