update to 20120731

- add functionality that allows to list all packages in a collection
- add dependency generators
This commit is contained in:
Jindrich Novy 2012-07-31 08:59:20 +02:00
parent 1429cf17de
commit 97011b7899
8 changed files with 10 additions and 371 deletions

5
.gitignore vendored
View File

@ -1,4 +1 @@
/scl
/scl.o
/scl.1
/scl-utils-20120613.tar.gz
/scl-utils-20120731.tar.gz

View File

@ -1,44 +0,0 @@
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.scl scl.1
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: $(NAME)
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.scl $(DESTDIR)/$(CNFDIR)/rpm
cp scl $(DESTDIR)/$(BINDIR)
cp scl_enabled $(DESTDIR)/$(BINDIR)
cp scl.1 $(DESTDIR)/$(MANDIR)/man1
uninstall:
rm -f $(BINDIR)/scl $(BINDIR)/scl_enabled
rm -f $(CNFDIR)/rpm/macros.scl
rm -f $(MANDIR)/man1/scl.1

View File

@ -1,49 +0,0 @@
# scl-utils RPM macros
#
# Copyright (C) 2012 Red Hat, Inc.
# Written by Jindrich Novy <jnovy@redhat.com>.
%scl_package() %{expand:%{!?_root_prefix:
%global pkg_name %1
%global scl_name %{scl}
%global scl_prefix %{scl}-
%global scl_runtime %{scl}-runtime
%{!?_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 %{_localstatedir}
%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 %{_scl_root}/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}-%{pkg_name}
BuildRequires: scl-utils-build
}}
%scl_require() %{_scl_prefix}/%1/enable, %1
%scl_require_package() %1-%2

View File

@ -1,7 +1,7 @@
Summary: Utilities for alternative packaging
Name: scl-utils
Version: 20120613
Release: 2%{?dist}
Version: 20120731
Release: 1%{?dist}
License: GPLv2+
Group: Applications/File
URL: http://jnovy.fedorapeople.org/scl-utils/
@ -50,8 +50,14 @@ rm -rf %buildroot
%files build
%defattr(-,root,root,-)
%{_sysconfdir}/rpm/macros.scl
%{_rpmconfigdir}/scldeps.sh
%{_rpmconfigdir}/fileattrs/scl.attr
%changelog
* Thu Jul 31 2012 Jindrich Novy <jnovy@redhat.com> 20120730-1
- add functionality that allows to list all packages in a collection
- add dependency generators
* Sat Jul 21 2012 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 20120613-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_18_Mass_Rebuild

47
scl.1
View File

@ -1,47 +0,0 @@
.TH "scl" "1"
.SH "NAME"
scl \- Setup and run software from Software Collection environment
.SH "SYNOPSIS"
.PP
\fBscl\fP \fI<action>\fR [\fI<collection1> <collection2> ...\fR] \fI<command>\fR
.PP
\fBscl\fP {\fB-l|--list\fP}
.SH "DESCRIPTION"
.PP
This manual page documents \fBscl\fP, a
program which is an utility for running software packaged as a Software Collection.
.PP
\fBscl\fP utility allows to execute an application which is not located in the filesystem
root hierarchy but is present in an alternative location. This application can still use
and benefit from software installed in the root filesystem. In order to let an application
be visible to the system one has to use \fBscl\fP utility as an interface.
.PP
\fI<action>\fR is a script name to execute in a bash environment before the application
itself takes in executed. Currently only \fBenable\fP scriptlet is mandatory which is needed
to update search paths, etc.
.PP
One can enable more Software Collections if needed and therefore one can use multiple
collections which are enabled by the left-right order as present on \fBscl\fP command-line.
.PP
\fI<command>\fR is an arbitrary command or set of commands to execute within the Software
Collection environment enabled. Control is returned back to the caller with the original
environment as soon as the command finishes. It \fI<command>\fR is '-' (dash) then it is
read from the standard input.
.SH "OPTIONS"
.PP
.IP "\fB-l, --list\fP" 10
Lists all installed Software Collections on the system
.SH "EXAMPLES"
.TP
scl enable example 'less --version'
runs command 'less --version' in the environment with collection 'example' enabled
.TP
scl enable foo bar bash
runs bash instance with foo and bar Software Collections enabled
.TP
cat my_command | scl enable baz -
run set of commands listed in my_command file in the environment with baz Software Collection
enabled
.SH "AUTHOR"
.PP
\fBscl\fP was written by Jindrich Novy <jnovy@redhat.com>.

209
scl.c
View File

@ -1,209 +0,0 @@
/* 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);
}
}
static void list_collections() {
struct stat sb;
struct dirent **nl;
int n, i;
const char prefix[] = "/etc/scl/prefixes/";
if (stat(prefix, &sb) == -1) {
fprintf(stderr, "%s does not exist\n", prefix);
exit(EXIT_FAILURE);
}
if (!S_ISDIR(sb.st_mode)) {
fprintf(stderr, "%s is not a directory\n", prefix);
exit(EXIT_FAILURE);
}
if ((n = scandir(prefix, &nl, 0, alphasort)) < 0) {
perror("scandir");
exit(EXIT_FAILURE);
}
for (i=0; i<n; i++) {
if (*nl[i]->d_name != '.') {
printf("%s\n", nl[i]->d_name);
}
}
free(nl);
}
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 (argc == 2 && (!strcmp(argv[1],"--list") || !strcmp(argv[1],"-l"))) {
list_collections();
return 0;
}
if (!strcmp(argv[argc-1], "-")) { /* reading command from stdin */
size_t r;
if (argc < 4) {
fprintf(stderr, "Need at least 3 arguments.\nRun %s without arguments to get help.\n", argv[0]);
exit(EXIT_FAILURE);
}
cmd = malloc(BUFSIZ);
if (!cmd) {
fprintf(stderr, "Can't allocate memory.\n");
exit(EXIT_FAILURE);
}
for (r=0; (r += fread(cmd+r, 1, BUFSIZ, stdin));) {
if (feof(stdin)) break;
cmd = realloc(cmd, r+BUFSIZ);
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 = strdup(argv[argc-1]);
}
tfd = mkstemp(tmp);
check_asprintf(&enabled, "scl_enabled %s\nif [ $? != 0 ]; then\n"
" eval \"SCLS=( ${x_scls[*]} )\"\n"
" SCLS+=(%s)\n"
" export X_SCLS=$(printf '%%q ' \"${SCLS[@]}\")\nfi\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);
unlink(tmp);
exit(EXIT_FAILURE);
}
r = fread(scl_dir, 1, BUFSIZ, f);
if (!r) {
fprintf(stderr, "Unable to read or file empty %s!\n", path);
unlink(tmp);
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);
unlink(tmp);
exit(EXIT_FAILURE);
}
if (!S_ISDIR(st.st_mode)) {
fprintf(stderr, "%s is not a directory\n", path);
unlink(tmp);
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);
unlink(tmp);
exit(EXIT_FAILURE);
}
close(ffd);
free(echo);
free(enablepath);
free(path);
}
write_script(tfd, cmd);
write_script(tfd, "\n");
free(cmd);
close(tfd);
check_asprintf(&bash_cmd, "/bin/bash %s", tmp);
i = system(bash_cmd);
free(bash_cmd);
unlink(tmp);
return WEXITSTATUS(i);
}

View File

@ -1,15 +0,0 @@
#!/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

@ -1 +1 @@
c21ef8094140752052f83d90d176a0b5 scl-utils-20120613.tar.gz
5cde6cffab5737981f1ccb822515b17d scl-utils-20120731.tar.gz