cScm Configuration Daemon

cScm – is a tool to convert SCM configuration files into binary format and store its in shared memory for reading by cSvn-ui and cGit-ui CGI scripts

2 Commits   0 Branches   1 Tag
author: kx <kx@radix.pro> 2023-03-24 02:53:04 +0300 committer: kx <kx@radix.pro> 2023-03-24 02:53:04 +0300 commit: 12c7b1c5658602269da2f5b75835ec0f5fab8890 parent: 4e72ffe940d9aff7c019d37a6459e765902c1fae
Commit Summary:
Version 0.1.4
Diffstat:
12 files changed, 324 insertions, 0 deletions
diff --git a/doc/build-packages/archlinux/PKGBUILD b/doc/build-packages/archlinux/PKGBUILD
new file mode 100644
index 0000000..15218b2
--- /dev/null
+++ b/doc/build-packages/archlinux/PKGBUILD
@@ -0,0 +1,49 @@
+#
+# Maintainer: Andrey V.Kosteltsev <kx@radix.pro>
+#
+pkgname=cscm
+pkgver=0.1.4
+pkgrel=2
+pkgdesc='cScm Configuration Daemon for cSvn-ui and cGit-ui packages'
+arch=('x86_64')
+url='https://csvn.radix.pro'
+license=('custom')
+depends=('pcre2')
+source=("https://ftp.radix.pro/pub/cscm/${pkgname}-${pkgver}.tar.xz")
+md5sums=('..Check MD5 sum before Building Package..')
+
+build() {
+  cd ${pkgname}-${pkgver}
+
+  CFLAGS="-O2 -fPIC -Wno-unused-result" \
+  ./configure \
+    --prefix=/usr \
+    --sysconfdir=/etc \
+    --libdir=/usr/lib \
+    --sbindir=/usr/bin \
+    --with-controldir=/etc/rc.d \
+    --with-logrotatedir=/etc/logrotate.d \
+    --with-homepath=/var/lib \
+    --with-logdir=/var/log \
+    --with-piddir=/var/run
+  make
+}
+
+package() {
+  cd ${pkgname}-${pkgver}
+
+  make install DESTDIR="${pkgdir}"
+
+  # Install systemd unit:
+  install -d ${pkgdir}/usr/lib/systemd/system
+  install -m 644 doc/build-packages/rpms/csvnd.service ${pkgdir}/usr/lib/systemd/system
+  install -m 644 doc/build-packages/rpms/cgitd.service ${pkgdir}/usr/lib/systemd/system
+  rm -rf ${pkgdir}/etc/rc.d
+
+  # Gsip man pages:
+  gzip -9 ${pkgdir}/usr/share/man/man8/cscmd.8
+
+  # Install documentation:
+  install -d ${pkgdir}/usr/share/doc/${pkgname}-${pkgver}
+  cp -a LICENSE README README.md doc/ ${pkgdir}/usr/share/doc/${pkgname}-${pkgver}
+}
diff --git a/doc/build-packages/archlinux/README b/doc/build-packages/archlinux/README
new file mode 100644
index 0000000..0ffa946
--- /dev/null
+++ b/doc/build-packages/archlinux/README
@@ -0,0 +1,32 @@
+
+Sytem requires:
+  fakeroot, logrotate
+
+Build time requires:
+  make, binutils, gcc, bison, autoconf, automake, pkgconfig,
+  pcre2
+
+Runtime requires:
+  pcre2
+
+As non-privileged user:
+
+  $ mkdir build
+  $ cp PKGBUILD build/
+  $ cd build/
+  $ makepkg
+
+As root:
+
+  # pacman -U ./cscm-0.1.4-2-x86_64.pkg.tar.zst
+
+After install binary package we have to create /etc/csvn-ui.rc [or|and] /etc/cgit-ui.rc
+configuration files and then enable and run csvnd.service [or|and] cgitd.service:
+
+ $ systemctl enable csvnd.service
+ $ systemctl start csvnd.service
+
+ $ systemctl enable cgitd.service
+ $ systemctl start cgitd.service
+
+Then we can to enable csvn-ui [or|and] cgit-ui web-servers.
diff --git a/doc/build-packages/rpms/README b/doc/build-packages/rpms/README
new file mode 100644
index 0000000..e8c6c5d
--- /dev/null
+++ b/doc/build-packages/rpms/README
@@ -0,0 +1,26 @@
+
+To build RPM packages we have to copy source package downloaded
+from https://ftp.radix.pro/pub/cscm directory to /usr/src/packages/SOURSES/
+directory. And also copy the cscm.spec file into /usr/src/packages/SPECS/
+directory. Then edit the package version in the cscm.spec file according
+to source package version.
+
+Dependencies: pcre2-devel.
+
+RPMs can be built by following command:
+
+ $ rpmbuild --define "_topdir /usr/src/packages" -ba /usr/src/packages/SPECS/cscm.spec
+
+Resulting RPMs will be saved in /usr/src/packages/SRPMS/ and
+/usr/src/packages/RPMS/`uname -m`/ directories.
+
+After install binary RPM we have to create /etc/csvn-ui.rc [or|and] /etc/cgit-ui.rc
+configuration files and then enable and run csvnd.service [or|and] cgitd.service:
+
+ $ systemctl enable csvnd.service
+ $ systemctl start csvnd.service
+
+ $ systemctl enable cgitd.service
+ $ systemctl start cgitd.service
+
+Then we can to enable csvn-ui [or|and] cgit-ui web-servers.
diff --git a/doc/build-packages/rpms/cgitd.service b/doc/build-packages/rpms/cgitd.service
new file mode 100644
index 0000000..fa87546
--- /dev/null
+++ b/doc/build-packages/rpms/cgitd.service
@@ -0,0 +1,13 @@
+
+[Unit]
+Description=The cGit daemon
+After=network.target
+
+[Service]
+PIDFile=/var/run/cgitd.pid
+ExecStart=/usr/sbin/cscmd --daemonize --inotify --scm=git --pid=/var/run/cgitd.pid --log=/var/log/cgitd.log --config=/etc/cgit-ui.rc
+ExecReload=/bin/kill -s HUP $MAINPID
+ExecStop=/bin/kill -s TERM $MAINPID
+
+[Install]
+WantedBy=multi-user.target
diff --git a/doc/build-packages/rpms/cscm.spec b/doc/build-packages/rpms/cscm.spec
new file mode 100644
index 0000000..3ce0248
--- /dev/null
+++ b/doc/build-packages/rpms/cscm.spec
@@ -0,0 +1,57 @@
+
+Name:       cscm
+Version:    0.1.4
+Release:    2
+Summary:    cScm Configuration Daemon
+License:    RADIX-1.0
+Group:      System/base
+Source:     https://ftp.radix.pro/pub/cscm/cscm-0.1.4.tar.xz
+Url:        https://csvn.radix/pro/cscm/
+
+
+%define _sysconfdir /etc
+%define _libdir     /usr/lib64
+%define _homepath   /var/lib
+%define _logdir     /var/log
+%define _piddir     /var/run
+%define _systemddir /usr/lib/systemd/system
+
+
+%description
+cScm - is a Configuration Daemon for cSvn-ui and cGit-ui packages
+
+%prep
+%setup -q
+
+%build
+./configure \
+  --prefix=/usr \
+  --sysconfdir=%{_sysconfdir} \
+  --libdir=%{_libdir} \
+  --with-controldir=%{_sysconfdir}/rc.d \
+  --with-logrotatedir=%{_sysconfdir}/logrotate.d \
+  --with-homepath=%{_homepath} \
+  --with-logdir=%{_logdir} \
+  --with-piddir=%{_piddir}
+
+%install
+make install DESTDIR=%{buildroot}
+install -d %{buildroot}%{_systemddir}
+install -m 644 doc/build-packages/rpms/csvnd.service %{buildroot}%{_systemddir}
+install -m 644 doc/build-packages/rpms/cgitd.service %{buildroot}%{_systemddir}
+rm -rf %{buildroot}%{_sysconfdir}/rc.d
+
+%clean
+%{?buildroot:%__rm -rf "%{buildroot}"}
+
+%files
+%defattr(-,root,root)
+%{_sysconfdir}/*
+%attr(755,root,root) %{_sbindir}/cscmd
+%{_homepath}/*
+%{_includedir}/*
+%{_datadir}/*
+%doc LICENSE README README.md doc/
+%{_systemddir}/csvnd.service
+%{_systemddir}/cgitd.service
+
diff --git a/doc/build-packages/rpms/csvnd.service b/doc/build-packages/rpms/csvnd.service
new file mode 100644
index 0000000..f51919c
--- /dev/null
+++ b/doc/build-packages/rpms/csvnd.service
@@ -0,0 +1,13 @@
+
+[Unit]
+Description=The cSvn daemon
+After=network.target
+
+[Service]
+PIDFile=/var/run/csvnd.pid
+ExecStart=/usr/sbin/cscmd --daemonize --inotify --scm=svn --pid=/var/run/csvnd.pid --log=/var/log/csvnd.log --config=/etc/csvn-ui.rc
+ExecReload=/bin/kill -s HUP $MAINPID
+ExecStop=/bin/kill -s TERM $MAINPID
+
+[Install]
+WantedBy=multi-user.target
diff --git a/doc/build-packages/slackware/README b/doc/build-packages/slackware/README
new file mode 100644
index 0000000..b9a2999
--- /dev/null
+++ b/doc/build-packages/slackware/README
@@ -0,0 +1,6 @@
+
+cscm (a SCM Configuration Daemon)
+
+cScm is a SCM Configuration daemon for cSvn-ui and cGit-ui packages.
+
+Homepage: https://csvn.radix.pro
diff --git a/doc/build-packages/slackware/cscm.SlackBuild b/doc/build-packages/slackware/cscm.SlackBuild
new file mode 100644
index 0000000..110edc0
--- /dev/null
+++ b/doc/build-packages/slackware/cscm.SlackBuild
@@ -0,0 +1,92 @@
+#!/bin/bash
+
+cd $(dirname $0) ; CWD=$(pwd)
+
+PKGNAM=cscm
+VERSION=${VERSION:-$(echo cscm-*.tar.?z* | rev | cut -f 3- -d . | cut -f 1 -d - | rev)}
+BUILD=${BUILD:-2}
+
+# Automatically determine the architecture we're building on:
+if [ -z "$ARCH" ]; then
+  case "$( uname -m )" in
+    i?86) export ARCH=i586 ;;
+    arm*) export ARCH=arm ;;
+    # Unless $ARCH is already set, use uname -m for all other archs:
+       *) export ARCH=$( uname -m ) ;;
+  esac
+fi
+
+if [ "$ARCH" = "i586" ]; then
+  SLKCFLAGS="-O2 -march=i586 -mtune=i686"
+  LIBDIRSUFFIX=""
+elif [ "$ARCH" = "s390" ]; then
+  SLKCFLAGS="-O2"
+  LIBDIRSUFFIX=""
+elif [ "$ARCH" = "x86_64" ]; then
+  SLKCFLAGS="-O2 -fPIC"
+  LIBDIRSUFFIX="64"
+else
+  SLKCFLAGS="-O2"
+  LIBDIRSUFFIX=""
+fi
+
+TMP=${TMP:-/tmp}
+PKG=$TMP/package-${PKGNAM}
+
+rm -rf $PKG
+mkdir -p $TMP $PKG
+
+cd $TMP
+rm -rf ${PKGNAM}-${VERSION}
+tar xvf $CWD/${PKGNAM}-${VERSION}.tar.?z* || exit 1
+cd ${PKGNAM}-$VERSION || exit 1
+
+chown -R root:root .
+find . \
+ \( -perm 777 -o -perm 775 -o -perm 711 -o -perm 555 -o -perm 511 \) \
+ -exec chmod 755 {} \+ -o \
+ \( -perm 666 -o -perm 664 -o -perm 600 -o -perm 444 -o -perm 440 -o -perm 400 \) \
+ -exec chmod 644 {} \+
+
+CFLAGS="$SLKCFLAGS" \
+./configure \
+  --prefix=/usr \
+  --sysconfdir=/etc \
+  --libdir=/usr/lib${LIBDIRSUFFIX} \
+  --with-controldir=/etc/rc.d \
+  --with-logrotatedir=/etc/logrotate.d \
+  --with-homepath=/var/lib \
+  --with-logdir=/var/log \
+  --with-piddir=/var/run \
+  --build=$ARCH-slackware-linux || exit 1
+
+
+make || exit 1
+make install DESTDIR=$PKG || exit 1
+
+mv $PKG/etc/rc.d/rc.csvnd $PKG/etc/rc.d/rc.csvnd.new
+mv $PKG/etc/rc.d/rc.cgitd $PKG/etc/rc.d/rc.cgitd.new
+
+find $PKG | xargs file | grep -e "executable" -e "shared object" | grep ELF \
+  | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
+
+mv $PKG/usr/share/man $PKG/usr/
+gzip -9 $PKG/usr/man/man?/*
+rmdir $PKG/usr/share/man
+
+find $PKG/usr/man -type f -exec gzip -9 {} \;
+
+mkdir -p $PKG/usr/doc/${PKGNAM}-${VERSION}
+cp -a \
+  LICENSE README README.md doc \
+  $PKG/usr/doc/${PKGNAM}-${VERSION}
+
+cp -a $CWD/${PKGNAM}.info        $PKG/usr/doc/${PKGNAM}-${VERSION}
+cp -a $CWD/${PKGNAM}.SlackBuild  $PKG/usr/doc/${PKGNAM}-${VERSION}
+
+mkdir -p $PKG/install
+cat $CWD/doinst.sh  > $PKG/install/doinst.sh
+cat $CWD/slack-desc > $PKG/install/slack-desc
+
+cd $PKG
+/sbin/makepkg -l y -c n $TMP/${PKGNAM}-${VERSION}-${ARCH}-${BUILD}.txz
diff --git a/doc/build-packages/slackware/cscm.info b/doc/build-packages/slackware/cscm.info
new file mode 100644
index 0000000..9436a98
--- /dev/null
+++ b/doc/build-packages/slackware/cscm.info
@@ -0,0 +1,10 @@
+PRGNAM="cscm"
+VERSION="0.1.4"
+HOMEPAGE="http://csvn.radix.pro"
+DOWNLOAD="https://ftp.radix.pro/pub/cscm/cscm-0.1.4.tar.xz"
+MD5SUM="..Check MD5 sum before Building Package.."
+DOWNLOAD_x86_64=""
+MD5SUM_x86_64=""
+REQUIRES="libpcre2-32"
+MAINTAINER="Andrey V.Kosteltsev"
+EMAIL="kx@radix.pro"
diff --git a/doc/build-packages/slackware/doinst.sh b/doc/build-packages/slackware/doinst.sh
new file mode 100644
index 0000000..7ee79cf
--- /dev/null
+++ b/doc/build-packages/slackware/doinst.sh
@@ -0,0 +1,15 @@
+
+config() {
+  NEW="$1"
+  OLD="`dirname $NEW`/`basename $NEW .new`"
+  # If there's no config file by that name, mv it over:
+  if [ ! -r $OLD ]; then
+    mv $NEW $OLD
+  elif [ "`cat $OLD | md5sum`" = "`cat $NEW | md5sum`" ]; then # toss the redundant copy
+    rm $NEW
+  fi
+  # Otherwise, we leave the .new copy for the admin to consider...
+}
+
+config etc/rc.d/rc.csvnd.new
+config etc/rc.d/rc.cgitd.new
diff --git a/doc/build-packages/slackware/slack-desc b/doc/build-packages/slackware/slack-desc
new file mode 100644
index 0000000..2d7c2b9
--- /dev/null
+++ b/doc/build-packages/slackware/slack-desc
@@ -0,0 +1,19 @@
+# HOW TO EDIT THIS FILE:
+# The "handy ruler" below makes it easier to edit a package description. Line
+# up the first '|' above the ':' following the base package name, and the '|' on
+# the right side marks the last column you can put a character in. You must make
+# exactly 11 lines for the formatting to be correct. It's also customary to
+# leave one space after the ':'.
+
+    |-----handy-ruler------------------------------------------------------|
+cscm: cscm (a SCM Configuration Daemon)
+cscm:
+cscm: cSvn is a SCM Configuration daemon for cSvn-ui and cGit-ui packages.
+cscm:
+cscm:
+cscm:
+cscm: Homepage: https://csvn.radix.pro
+cscm:
+cscm:
+cscm:
+cscm:
diff --git a/doc/cscmd.8.md b/doc/cscmd.8.md
new file mode 100644
index 0000000..b0c9423
--- /dev/null
+++ b/doc/cscmd.8.md
@@ -0,0 +1,112 @@
+
+# [cScm Daemon](https://csvn.radix.pro/cscm/trunk/doc/cscmd.8.md)
+
+**cscmd** &#8211; a daemon for monitoring changes in SCM configuration files.
+
+
+## Table of Contents
+
+* [Options](#options)
+* [Grammar](#grammar)
+* [See Also](#see-also)
+
+<br/>
+
+In order to not load the **cSvn-ui** and **cGit-ui** CGI scripts with unnecessary functionality and speed up
+its work, information about the list of repositories is transmitted to it in binary form through
+shared memory (see: */dev/shm/csvn.bcf*, */dev/shm/cgit.bcf*).
+
+Binary Config File (**BCF**) format is similar to the simplified implementation of the **COFF**
+and is described in the header file [*/usr/include/cscm/bcf.h*](https://csvn.radix.pro/cscm/trunk/cscm/bcf.h).
+
+On startup, the daemon parses the */etc/csvn-ui.rc* or */etc/csvn-ui.rc* configuration files
+(depends on **--scm=[svn|git]** option) and stores its binary forms in shared memory. In addition, the binary
+form is saved in the daemon's home directory, by default it is the file */var/lib/csvn/csvn.bcf* or
+*/var/lib/cgit/cgit.bcf*.
+
+**cscmd(8)** daemon rereads SCM configuration files upon arrival of the **-HUP** signal and, in addition,
+can be configured to monitor changes in the configuration files using the `--inotify` option. If the `--inotify`
+option is specified, then after editing the file */ets/csvn-ui.rc* or */ets/cgit-ui.rc* and saving it to disk,
+the **cscmd** daemon will reread file */etc/csvn-ui.rc* or */etc/cgit-ui.rc* as if it received the **-HUP** signal.
+
+The work of the **cscmd(8)** daemon's can be monitored by the log, which it leaves in the file
+*/var/log/csvnd.log* or the file */var/log/cgitd.log* (depends on **--scm=[svn|git]** option). There you can also
+observe messages about errors that are detected in */ets/csvn-ui.rc* or */ets/cgit-ui.rc* files, if any.
+
+To start the **cScm** daemon during system boot, can be used the start/stop script */etc/rc.d/rc.csvnd* or
+*/etc/rc.d/rc.cgitd*.
+
+
+## Options
+
+
+### -h, --help
+
+Display help information.
+
+
+### -v, --version
+
+Display the version of **cScm** daemon.
+
+
+### -d, --daemonize
+
+Run in background as a daemon.
+
+
+### -i, --inotify
+
+Notify about configuration changes. If this option is set then **cscmd(8)** daemon selects changes
+made in */etc/csvn-ui.rc* or */etc/cgit-ui.rc* configuration file and reread configuration when changes
+is done. Without this option rereading configuration file can be done by sending **-HUP** to the **cscmd(8)**
+process.
+
+
+### -b, --bcf=<BCF_FILE>
+
+Binary config file (depends on **--scm=[svn|git]** option). Default: */var/lib/csvn/csvn.bcf*.
+
+
+### -c, --config=<CONFIG_FILE>
+
+Config file (depends on **--scm=[svn|git]** option). Default: */etc/csvn-ui.rc*.
+
+
+### -l, --log=<LOG_FILE>
+
+Log file (depends on **--scm=[svn|git]** option). Default: */var/log/csvnd.log*.
+
+
+### -p, --pid=<PID_FILE>
+
+Log file (depends on **--scm=[svn|git]** option). Default: */var/run/csvnd.pid*.
+
+
+### -s, --scm=[svn|git]
+
+SCM engine name: **svn** or **git**. Default: **svn**.
+
+
+### -t, --test
+Test the config file and exit.
+
+
+## Grammar
+
+The grammar of the language describing the **cScm** congfiguration is simple
+([**parse.y**](https://csvn.radix.pro/cscm/trunk/cscmd/parse.y)). File */etc/csvn-ui.rc*
+allows you to set variable values and create repository lists as named structures.
+
+Any variables can be defined in the */etc/csvn-ui.rc* file, but only variables with
+reserved names will be used by the **cSvn** or **cGit** CGI script.
+
+In addition, if a variable already defined at the global level is specified in the
+description of a repository, then within this repository this variable will have a local
+value. In other words, within the repository, global variables can be overridden.
+
+
+## See Also
+
+> [**README**](https://csvn.radix.pro/cscm/trunk/README.md)
+