Skip to content
Snippets Groups Projects
Commit 312eebfe authored by Eric Vidal's avatar Eric Vidal :speech_balloon:
Browse files

Bump v0.3.0

parent 23d0b3c2
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/bash
# Copyright (c) 2015-2019 Eric Vidal <eric@obarun.org>
# All rights reserved.
#
# This file is part of Obarun. It is subject to the license terms in
# the LICENSE file found in the top-level directory of this
# distribution.
# This file may not be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.
PROG="66-mods.sh"
service_system="${service_system:-/usr/lib/66/service}"
module_system="${module_system:-/usr/lib/66/module}"
force=0
out() {
msg="${1}"
66-echo -- $PROG: $msg
}
die() {
out "${1}"
exit 111
}
usage () {
cat <<EOF
$PROG [ -h ] [ -H ] [ -f ] module@instance
$PROG <options> modules@instance
options :
-h: print this help
-H: print module help
-f: force to overwrite an existing module
EOF
exit 0
}
for arg ; do
case "$arg" in
-h|--help) usage ;;
-H|--help-module) hm=1 ;;
-f|--force) force=1 ;;
-*) die "fatal: unknown option $arg" ;;
*) target+=( $arg ) ;;
esac
done
if [[ "${target[0]}" != *"@"* ]];then
die "fatal: invalid argument -- not a module name"
fi
mod="${target[0]}"
mod="${mod%%@*}"
mod="${mod%%@*}@"
insta="${target[0]}"
insta="${insta##*@}"
service="${mod}${insta}"
if [[ ! -d ${module_system}/${mod} ]]; then
die "fatal: module ${mod} doesn't exist"
fi
if (( ${hm} )); then
if [[ -e ${module_system}/${mod}/.configure/help ]]; then
h=$(<${module_system}/${mod}/.configure/help)
66-echo -- "${h}"
else
out "warning: no help found for ${mod}"
fi
exit 0
fi
if [[ -z "${insta}" ]];then
die "fatal: instance for ${mod} is not set"
fi
if [[ -d ${service_system}/${service} ]]; then
if (( !$force )) ; then
die "fatal: ${service_system}/${service} already exist"
else
rm -rf ${service_system}/${service} || die "fatal: unable to remove ${service_system}/${service}"
fi
fi
cp -rT ${module_system}/${mod} ${service_system}/${service} || die "fatal: unable to cp ${module_system}/${mod} to ${service_system}/${service}"
## @I in file
for i in $(find ${service_system}/${service} -mindepth 1 -type f);do
sed -i "s:@I:${insta}:g" $i || die "fatal: unable to sed ${i}"
done
## change directory name
for i in $(find ${service_system}/${service} -mindepth 1 -type d|grep -v "configure");do
mv $i $(66-echo -- ${i}|sed "s:@M:${insta}:g") || die "fatal: unable to move ${i} to $(echo ${i}|sed "s:@M:${insta}:g")"
done
## change file name
for i in $(find ${service_system}/${service} -mindepth 1 -type f|grep -v "configure");do
mv $i $(66-echo -- ${i}|sed "s:@M:${insta}:g") || die "fatal: unable to move ${i} to $(echo ${i}|sed "s:@M:${insta}:g")"
done
## run .configure scripts
if [[ -x ${service_system}/${service}/.configure/configure ]]; then
cd ${service_system}/${service}/.configure/
${service_system}/${service}/.configure/configure ${insta} || die "fatal: unable to configure ${service_system}/${service}"
rm -rf ${service_system}/${service}/.configure || die "fatal: unable to remove ${service_system}/${service}/.configure"
fi
[main]
@type = module
@version = @VERSION@
@description = "Configure a nested supervision tree for @I user"
@user = ( root )
@options = ( env )
@depends = ( scandir@@I )
[regex]
@configure = "@I"
@infiles = ( ::@version@=@VERSION@ )
[environment]
## Uncomment it to use a display manager.
## Can be any display manager as long as the
## corresponding frontend file exist on your system
## e.g sddm,lightdm,...
## It also prepare the .xsession file.
@DISPLAY_MANAGER@
## Uncomment it to use a console tracker.
## Can be any console tracker as long as the
## corresponding frontend file exist on your system
## e.g consolekit,elogind,...
@CONSOLE_TRACKER@
## Create and mount the XDG_RUNTIME directory
## at /run/user/@I [yes|no]
@XDG_RUNTIME@
## Command to use in your .xinitrc
## to launch your desktop e.g.: openbox-session.
## If commented the .xinitrc file is not configured.
@DESKTOP_CMDLINE@
#!/bin/sh
usage() {
echo "usage: $0 [-D] [-l] [-m mode] src dst" 1>&2
exit 1
}
mkdirp=false
symlink=false
mode=0755
while getopts Dlm: name ; do
case "$name" in
D) mkdirp=true ;;
l) symlink=true ;;
m) mode=$OPTARG ;;
?) usage ;;
esac
done
shift $(($OPTIND - 1))
test "$#" -eq 2 || usage
src=$1
dst=$2
tmp="$dst.tmp.$$"
case "$dst" in
*/) echo "$0: $dst ends in /" 1>&2 ; exit 1 ;;
esac
set -C
set -e
if $mkdirp ; then
umask 022
case "$2" in
*/*) mkdir -p "${dst%/*}" ;;
esac
fi
trap 'rm -f "$tmp"' EXIT INT QUIT TERM HUP
umask 077
if $symlink ; then
ln -s "$src" "$tmp"
else
cat < "$1" > "$tmp"
chmod "$mode" "$tmp"
fi
mv -f "$tmp" "$dst"
if test -d "$dst" ; then
rm -f "$dst/$(basename $tmp)"
if $symlink ; then
mkdir "$tmp"
ln -s "$src" "$tmp/$(basename $dst)"
mv -f "$tmp/$(basename $dst)" "${dst%/*}"
rmdir "$tmp"
else
echo "$0: $dst is a directory" 1>&2
exit 1
fi
fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment