initial import

This commit is contained in:
Jindrich Novy 2011-12-15 10:53:17 +01:00
parent adc31cbbf3
commit b0b876b071
7 changed files with 469 additions and 0 deletions

1
.gitignore vendored
View File

@ -0,0 +1 @@
/scl-utils-20111214.tar.gz

42
Makefile Normal file
View File

@ -0,0 +1,42 @@
NAME=scl-utils
VERSION=`date +%Y%m%d`
WARNINGS?=-Wall -Wshadow -Wcast-align -Winline -Wextra -Wmissing-noreturn
CFLAGS?=-O2
CFILES=scl.c
OTHERFILES=Makefile scl_enabled macros.dsc
SOURCES=$(CFILES) $(OTHERFILES)
OBJECTS=scl.o
BINDIR=/usr/bin
MANDIR=/usr/share/man
CNFDIR=/etc
all: $(NAME)
$(NAME): $(SOURCES) $(OBJECTS) $(OTHERFILES)
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJECTS) $(WARNINGS) -o scl
clean:
rm -f *.o scl
distclean: clean
rm -f *~
dist:
LANG=C
rm -rf $(NAME)-$(VERSION)
mkdir $(NAME)-$(VERSION)
cp $(SOURCES) $(NAME)-$(VERSION)
tar fcz $(NAME)-$(VERSION).tar.gz $(NAME)-$(VERSION)
rm -rf $(NAME)-$(VERSION)
install: $(NAME)
mkdir -p $(DESTDIR)/$(BINDIR)
mkdir -p $(DESTDIR)/$(CNFDIR)/rpm
cp macros.dsc $(DESTDIR)/$(CNFDIR)/rpm
cp scl $(DESTDIR)/$(BINDIR)
cp scl_enabled $(DESTDIR)/$(BINDIR)
uninstall:
rm -f $(BINDIR)/$(NAME)
rm -f $(CNFDIR)/rpm/macros.dsc

131
macros.dsc Normal file
View File

@ -0,0 +1,131 @@
# Dynamic Software Collections RPM macros
#
# Copyright (C) 2012 Red Hat, Inc.
# Written by Jindrich Novy <jnovy@redhat.com>.
# "scl" prefixed macros are kept for compatibility please use "dsc"
# prefixed ones for production
%dsc_package() %{expand:%{!?_root_prefix:
%global pkg_name %1
%global dsc_short_prefix dsc
%global dsc_name %{dsc_short_prefix}_%{dsc}
%global dsc_runtime %{dsc_name}-runtime
%global dsc_prefix %{dsc_name}_
%{!?_dsc_prefix: %global _dsc_prefix /opt/rh}
%global _dsc_scripts %{_dsc_prefix}/%{dsc}
%global _dsc_root %{_dsc_prefix}/%{dsc}/root
%global _root_prefix %{_prefix}
%global _root_exec_prefix %{_root_prefix}
%global _root_bindir %{_exec_prefix}/bin
%global _root_sbindir %{_exec_prefix}/sbin
%global _root_libexecdir %{_exec_prefix}/libexec
%global _root_datadir %{_prefix}/share
%global _root_sysconfdir %{_sysconfdir}
%global _root_sharedstatedir %{_prefix}/com
%global _root_localstatedir %{_prefix}/var
%global _root_libdir %{_exec_prefix}/%{_lib}
%global _root_includedir %{_prefix}/include
%global _root_infodir %{_datadir}/info
%global _root_mandir %{_datadir}/man
%global _root_initddir %{_sysconfdir}/rc.d/init.d
%global _prefix %{_dsc_root}/usr
%global _exec_prefix %{_prefix}
%global _bindir %{_exec_prefix}/bin
%global _sbindir %{_exec_prefix}/sbin
%global _libexecdir %{_exec_prefix}/libexec
%global _datadir %{_prefix}/share
%global _sysconfdir %{_dsc_root}/etc
%global _sharedstatedir %{_prefix}/com
%global _localstatedir %{_prefix}/var
%global _libdir %{_exec_prefix}/%{_lib}
%global _includedir %{_prefix}/include
%global _infodir %{_datadir}/info
%global _mandir %{_datadir}/man
%global _docdir %{_datadir}/doc
%global _defaultdocdir %{_docdir}
%global dsc_pkg_name %{dsc_short_prefix}_%{dsc}_%{pkg_name}
}}
%dsc_require() %{_dsc_prefix}/%1/enable
%dsc_files %{expand:
%{_dsc_root}
%{_dsc_scripts}
%{_dsc_scripts}/enable
%{_root_sysconfdir}/scl/prefixes/%dsc
}
%dsc_install %{expand:
mkdir -p %{buildroot}%{_root_sysconfdir}/{rpm,scl/prefixes}
echo -n '%' > %{buildroot}%{_root_sysconfdir}/rpm/macros.%{dsc}-config
cat >> %{buildroot}%{_root_sysconfdir}/rpm/macros.%{dsc}-config << EOF
scl %dsc
EOF
cat >> %{buildroot}%{_root_sysconfdir}/scl/prefixes/%{dsc} << EOF
%_dsc_prefix
EOF
}
# compatibility macros follow
%scl_package() %{expand:%{!?_root_prefix:
%global pkg_name %1
%global scl_short_prefix dsc
%global scl_name %{scl_short_prefix}_%{scl}
%global scl_runtime %{scl_name}-runtime
%global scl_prefix %{scl_name}_
%{!?_scl_prefix: %global _scl_prefix /opt/rh}
%global _scl_scripts %{_scl_prefix}/%{scl}
%global _scl_root %{_scl_prefix}/%{scl}/root
%global _root_prefix %{_prefix}
%global _root_exec_prefix %{_root_prefix}
%global _root_bindir %{_exec_prefix}/bin
%global _root_sbindir %{_exec_prefix}/sbin
%global _root_libexecdir %{_exec_prefix}/libexec
%global _root_datadir %{_prefix}/share
%global _root_sysconfdir %{_sysconfdir}
%global _root_sharedstatedir %{_prefix}/com
%global _root_localstatedir %{_prefix}/var
%global _root_libdir %{_exec_prefix}/%{_lib}
%global _root_includedir %{_prefix}/include
%global _root_infodir %{_datadir}/info
%global _root_mandir %{_datadir}/man
%global _root_initddir %{_sysconfdir}/rc.d/init.d
%global _prefix %{_scl_root}/usr
%global _exec_prefix %{_prefix}
%global _bindir %{_exec_prefix}/bin
%global _sbindir %{_exec_prefix}/sbin
%global _libexecdir %{_exec_prefix}/libexec
%global _datadir %{_prefix}/share
%global _sysconfdir %{_scl_root}/etc
%global _sharedstatedir %{_prefix}/com
%global _localstatedir %{_prefix}/var
%global _libdir %{_exec_prefix}/%{_lib}
%global _includedir %{_prefix}/include
%global _infodir %{_datadir}/info
%global _mandir %{_datadir}/man
%global _docdir %{_datadir}/doc
%global _defaultdocdir %{_docdir}
%global scl_pkg_name %{scl_short_prefix}_%{scl}_%{pkg_name}
}}
%scl_require() %{_scl_prefix}/%1/enable
%scl_files %{expand:
%{_scl_root}
%{_scl_scripts}
%{_scl_scripts}/enable
%{_root_sysconfdir}/scl/prefixes/%scl
}
%scl_install %{expand:
mkdir -p %{buildroot}%{_root_sysconfdir}/{rpm,scl/prefixes}
echo -n '%' > %{buildroot}%{_root_sysconfdir}/rpm/macros.%{scl}-config
cat >> %{buildroot}%{_root_sysconfdir}/rpm/macros.%{scl}-config << EOF
scl %scl
EOF
cat >> %{buildroot}%{_root_sysconfdir}/scl/prefixes/%{scl} << EOF
%_scl_prefix
EOF
}

119
scl-utils.spec Normal file
View File

@ -0,0 +1,119 @@
Summary: Utilities for alternative packaging
Name: scl-utils
Version: 20111214
Release: 1%{?dist}
License: GPLv2+
Group: Applications/File
URL: http://jnovy.fedorapeople.org/scl-utils/
Source0: http://jnovy.fedorapeople.org/scl-utils/%{name}-%{version}.tar.gz
Provides: dsc-utils = %version
Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
%description
Run-time utility for alternative packaging.
%package build
Summary: RPM build macros for alternative packaging
Group: Applications/File
Provides: dsc-utils-build = %version
%description build
Essential RPM build macros for alternative packaging.
%prep
%setup -q
%build
export CFLAGS="$RPM_OPT_FLAGS"
make
%install
rm -rf %buildroot
mkdir -p %buildroot%{_sysconfdir}/rpm
mkdir -p %buildroot%{_sysconfdir}/scl/prefixes
mkdir -p %buildroot/opt/rh
make install DESTDIR=%buildroot
%clean
rm -rf %buildroot
%files
%defattr(-,root,root,-)
%dir /opt/rh
%dir %{_sysconfdir}/scl/prefixes
%{_bindir}/scl
%{_bindir}/scl_enabled
%files build
%defattr(-,root,root,-)
%{_sysconfdir}/rpm/macros.dsc
%changelog
* Wed Dec 14 2011 Jindrich Novy <jnovy@redhat.com> 20111214-1
- initial review fixes (#767556)
* Fri Dec 9 2011 Jindrich Novy <jnovy@redhat.com> 20111209-1
- allow to use dsc_* macros and dsc* package naming
* Wed Nov 16 2011 Jindrich Novy <jnovy@redhat.com> 20111116-1
- package is now named scl-utils
* Mon Oct 17 2011 Jindrich Novy <jnovy@redhat.com> 20111017-1
- initial packaging for upstream
* Thu Sep 21 2011 Jindrich Novy <jnovy@redhat.com> 0.1-14
- define %%_defaultdocdir to properly relocate docs into
a stack
- document a way how to pass command to stack via stdin
* Wed Jun 22 2011 Jindrich Novy <jnovy@redhat.com> 0.1-13
- fix Stack meta config configuration
* Fri Jun 17 2011 Jindrich Novy <jnovy@redhat.com> 0.1-12
- use own Stack path configuration mechanism
* Fri Jun 17 2011 Jindrich Novy <jnovy@redhat.com> 0.1-11
- avoid redefinition of %%_root* macros by multiple
occurence of %%stack_package
- make the Stack root path configurable
* Tue Jun 14 2011 Jindrich Novy <jnovy@redhat.com> 0.1-10
- stack utility allows to read command from stdin
* Mon Jun 13 2011 Jindrich Novy <jnovy@redhat.com> 0.1-9
- introduce stack enablement tracking
- introduce "stack_enabled" helper utility to let a stack
application figure out which stacks are actually enabled
- disallow running stacks recursively
* Mon Jun 13 2011 Jindrich Novy <jnovy@redhat.com> 0.1-8
- stack utility returns executed commands' exit value
* Fri Jun 10 2011 Jindrich Novy <jnovy@redhat.com> 0.1-7
- fix possible segfault in the stack utility
* Fri Jun 10 2011 Jindrich Novy <jnovy@redhat.com> 0.1-6
- %%stack_name: initial part of stack prefix and name of
meta package providing scriptlets
- %%stack_prefix: stack namespacing part to be prepended to
original non-stack package name, can be used for Provides
namespacing as well
- %%stack_runtime: run-time package name providing scriptlets
- %%stack_require: macro to define dependency to other stacks
* Thu Jun 09 2011 Jindrich Novy <jnovy@redhat.com> 0.1-5
- split the package into two - runtime and build part
- decrease verbosity when enabling a stack
* Wed Jun 08 2011 Jindrich Novy <jnovy@redhat.com> 0.1-4
- prepend stack package with stack_* to prevent namespace
conflicts with core packages
* Thu Jun 02 2011 Jindrich Novy <jnovy@redhat.com> 0.1-3
- introduce metapackage concept
* Wed Jun 01 2011 Jindrich Novy <jnovy@redhat.com> 0.1-2
- modify macros so that they don't change preamble tags
* Sun May 08 2011 Jindrich Novy <jnovy@redhat.com> 0.1-1
- initial packaging

160
scl.c Normal file
View File

@ -0,0 +1,160 @@
/* Copyright (C) 2011 Red Hat, Inc.
Written by Jindrich Novy <jnovy@redhat.com>.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public
License along with this program; see the file COPYING. If not,
write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include <getopt.h>
#include <string.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
static void check_asprintf( char **strp, const char *fmt, ... ) {
va_list args;
va_start(args, fmt);
if (vasprintf(strp, fmt, args) == -1 || !*strp) {
fprintf(stderr, "Allocation failed.\n");
exit(EXIT_FAILURE);
}
va_end(args);
}
static void write_script( int tfd, char *s ) {
if (write(tfd, s, strlen(s)) == -1) {
fprintf(stderr, "Error writing to temporary file\n");
exit(EXIT_FAILURE);
}
}
int main(int argc, char **argv) {
struct stat st;
char *path, *enablepath;
char tmp[] = "/var/tmp/sclXXXXXX";
char *cmd = NULL, *bash_cmd, *echo, *enabled;
int i, tfd, ffd, stdin_read = 0;
if (!strcmp(argv[argc-1], "-")) { /* reading command from stdin */
size_t r = 0;
cmd = malloc(BUFSIZ);
if (!cmd) {
fprintf(stderr, "Can't allocate memory.\n");
exit(EXIT_FAILURE);
}
for (;(r += fread(cmd+r, 1, BUFSIZ, stdin));) {
if (feof(stdin)) break;
cmd = realloc(cmd, r);
if (!cmd) {
fprintf(stderr, "Can't reallocate memory.\n");
exit(EXIT_FAILURE);
}
}
if (!r) {
fprintf(stderr, "Error reading command from stdin.\n");
exit(EXIT_FAILURE);
}
stdin_read = 1;
}
if (!stdin_read) {
if (argc < 4) {
fprintf(stderr, "Usage: %s <action> [<collection1>, <collection2> ...] <command>\n"
"If <command> is '-' then the command will be read from standard input.\n", argv[0]);
exit(EXIT_FAILURE);
}
cmd = argv[argc-1];
}
tfd = mkstemp(tmp);
check_asprintf(&enabled, "scl_enabled %s\n[ $? == 0 ] && exit 1\n"
"eval \"SCLS=( ${x_scls[*]} )\"\n"
"SCLS+=(%s)\n"
"export X_SCLS=$(printf '%%q ' \"${SCLS[@]}\")\n", argv[2], argv[2]);
write_script(tfd, enabled);
free(enabled);
for (i=2; i<argc-1; i++) {
FILE *f;
size_t r;
char scl_dir[BUFSIZ];
check_asprintf(&path, "/etc/scl/prefixes/%s", argv[i]);
if (!(f=fopen(path,"r"))) {
fprintf(stderr, "Unable to open %s!\n", path);
exit(EXIT_FAILURE);
}
r = fread(scl_dir, 1, BUFSIZ, f);
if (!r) {
fprintf(stderr, "Unable to read or file empty %s!\n", path);
exit(EXIT_FAILURE);
}
scl_dir[r-1] = '\0';
strncat(scl_dir, "/", BUFSIZ-1);
strncat(scl_dir, argv[i], BUFSIZ-1);
strncat(scl_dir, "/", BUFSIZ-1);
fclose(f);
free(path);
check_asprintf(&path, "%s", scl_dir);
if (lstat(path, &st)) {
fprintf(stderr, "%s doesn't exist\n", path);
exit(EXIT_FAILURE);
}
if (!S_ISDIR(st.st_mode)) {
fprintf(stderr, "%s is not a directory\n", path);
exit(EXIT_FAILURE);
}
check_asprintf(&enablepath, "%s/%s", path, argv[1]);
check_asprintf(&echo, ". %s\n", enablepath);
ffd = open(enablepath, O_RDONLY);
if (ffd != -1) {
write_script(tfd, echo);
} else {
fprintf(stderr, "WARNING: %s scriptlet does not exist!\n", enablepath);
exit(EXIT_FAILURE);
}
close(ffd);
free(echo);
free(enablepath);
free(path);
}
write_script(tfd, cmd);
write_script(tfd, "\n");
close(tfd);
check_asprintf(&bash_cmd, "/bin/bash %s", tmp);
i = system(bash_cmd);
free(bash_cmd);
return WEXITSTATUS(i);
}

15
scl_enabled Executable file
View File

@ -0,0 +1,15 @@
#!/bin/sh
eval "SCLS=(${X_SCLS[*]})"
[ -z "$SCLS" ] && exit 1
[ -z "$*" ] && exit 0
for scl in $*; do
FOUND=0
for i in `seq 0 ${#SCLS[@]}`; do
if [ "${SCLS[$i]}" == "$scl" ]; then
FOUND=1;
break;
fi;
done
[ $FOUND == 0 ] && exit 1;
done
exit 0

View File

@ -0,0 +1 @@
b7dbe39477d6ad5641ec1df73eeaa36e scl-utils-20111214.tar.gz