From 39b582d8b6989c85013038f383b4ff291a04db75 Mon Sep 17 00:00:00 2001 From: Enrico Scholz Date: Thu, 27 Jan 2005 19:13:04 +0000 Subject: [PATCH] initial checkin git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@1814 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- util-vserver/distrib/fc3/pkgs/01 | 1 + util-vserver/distrib/fc3/pkgs/02 | 4 + util-vserver/distrib/fc3/pkgs/03 | 2 + .../distrib/fc3/yum.repos.d/fedora-devel.repo | 5 + .../fc3/yum.repos.d/fedora-updates-testing.repo | 6 + .../distrib/fc3/yum.repos.d/fedora-updates.repo | 6 + util-vserver/distrib/fc3/yum.repos.d/fedora.repo | 6 + util-vserver/distrib/fc3/yum/yum.conf | 7 ++ util-vserver/scripts/vserver-build.functions.yum | 74 ++++++++++++ util-vserver/scripts/vserver-build.yum | 57 ++++++++++ util-vserver/scripts/vsomething | 126 +++++++++++++++++++++ util-vserver/scripts/vyum | 72 ++++++++++++ util-vserver/scripts/vyum-worker | 38 +++++++ util-vserver/src/check-unixfile.c | 115 +++++++++++++++++++ 14 files changed, 519 insertions(+) create mode 100644 util-vserver/distrib/fc3/pkgs/01 create mode 100644 util-vserver/distrib/fc3/pkgs/02 create mode 100644 util-vserver/distrib/fc3/pkgs/03 create mode 100644 util-vserver/distrib/fc3/yum.repos.d/fedora-devel.repo create mode 100644 util-vserver/distrib/fc3/yum.repos.d/fedora-updates-testing.repo create mode 100644 util-vserver/distrib/fc3/yum.repos.d/fedora-updates.repo create mode 100644 util-vserver/distrib/fc3/yum.repos.d/fedora.repo create mode 100644 util-vserver/distrib/fc3/yum/yum.conf create mode 100644 util-vserver/scripts/vserver-build.functions.yum create mode 100644 util-vserver/scripts/vserver-build.yum create mode 100755 util-vserver/scripts/vsomething create mode 100755 util-vserver/scripts/vyum create mode 100755 util-vserver/scripts/vyum-worker create mode 100644 util-vserver/src/check-unixfile.c diff --git a/util-vserver/distrib/fc3/pkgs/01 b/util-vserver/distrib/fc3/pkgs/01 new file mode 100644 index 0000000..1a5ef72 --- /dev/null +++ b/util-vserver/distrib/fc3/pkgs/01 @@ -0,0 +1 @@ +glibc diff --git a/util-vserver/distrib/fc3/pkgs/02 b/util-vserver/distrib/fc3/pkgs/02 new file mode 100644 index 0000000..5b347f9 --- /dev/null +++ b/util-vserver/distrib/fc3/pkgs/02 @@ -0,0 +1,4 @@ +--reinstall + +filesystem +coreutils diff --git a/util-vserver/distrib/fc3/pkgs/03 b/util-vserver/distrib/fc3/pkgs/03 new file mode 100644 index 0000000..64ab4a7 --- /dev/null +++ b/util-vserver/distrib/fc3/pkgs/03 @@ -0,0 +1,2 @@ +coreutils +setup diff --git a/util-vserver/distrib/fc3/yum.repos.d/fedora-devel.repo b/util-vserver/distrib/fc3/yum.repos.d/fedora-devel.repo new file mode 100644 index 0000000..fbd4edf --- /dev/null +++ b/util-vserver/distrib/fc3/yum.repos.d/fedora-devel.repo @@ -0,0 +1,5 @@ +[development] +name=Fedora Core 3 - Development Tree +#baseurl=http://download.fedora.redhat.com/pub/fedora/linux/core/development/$basearch/ +mirrorlist=http://fedora.redhat.com/download/mirrors/fedora-core-rawhide +enabled=0 diff --git a/util-vserver/distrib/fc3/yum.repos.d/fedora-updates-testing.repo b/util-vserver/distrib/fc3/yum.repos.d/fedora-updates-testing.repo new file mode 100644 index 0000000..f8e7cc4 --- /dev/null +++ b/util-vserver/distrib/fc3/yum.repos.d/fedora-updates-testing.repo @@ -0,0 +1,6 @@ +[updates-testing] +name=Fedora Core 3 - $basearch - Test Updates +#baseurl=http://download.fedora.redhat.com/pub/fedora/linux/core/updates/testing/3/$basearch/ +mirrorlist=http://fedora.redhat.com/download/mirrors/updates-testing-fc3 +enabled=0 +gpgcheck=1 diff --git a/util-vserver/distrib/fc3/yum.repos.d/fedora-updates.repo b/util-vserver/distrib/fc3/yum.repos.d/fedora-updates.repo new file mode 100644 index 0000000..086a6b0 --- /dev/null +++ b/util-vserver/distrib/fc3/yum.repos.d/fedora-updates.repo @@ -0,0 +1,6 @@ +[updates-released] +name=Fedora Core 3 - $basearch - Released Updates +#baseurl=http://download.fedora.redhat.com/pub/fedora/linux/core/updates/3/$basearch/ +mirrorlist=http://fedora.redhat.com/download/mirrors/updates-released-fc3 +enabled=1 +gpgcheck=1 diff --git a/util-vserver/distrib/fc3/yum.repos.d/fedora.repo b/util-vserver/distrib/fc3/yum.repos.d/fedora.repo new file mode 100644 index 0000000..f4ba735 --- /dev/null +++ b/util-vserver/distrib/fc3/yum.repos.d/fedora.repo @@ -0,0 +1,6 @@ +[base] +name=Fedora Core 3 - $basearch - Base +#baseurl=http://download.fedora.redhat.com/pub/fedora/linux/core/3/$basearch/os/ +mirrorlist=http://fedora.redhat.com/download/mirrors/fedora-core-3 +enabled=1 +gpgcheck=1 diff --git a/util-vserver/distrib/fc3/yum/yum.conf b/util-vserver/distrib/fc3/yum/yum.conf new file mode 100644 index 0000000..310ca68 --- /dev/null +++ b/util-vserver/distrib/fc3/yum/yum.conf @@ -0,0 +1,7 @@ +[main] +cachedir=@YUMCACHEDIR@ +reposdir=@YUMETCDIR@/yum.repos.d +debuglevel=1 +logfile=@YUMLOGDIR@/log +pkgpolicy=newest +distroverpkg=redhat-release diff --git a/util-vserver/scripts/vserver-build.functions.yum b/util-vserver/scripts/vserver-build.functions.yum new file mode 100644 index 0000000..56b6db6 --- /dev/null +++ b/util-vserver/scripts/vserver-build.functions.yum @@ -0,0 +1,74 @@ +# $Id$ --*- sh -*-- + +# Copyright (C) 2003 Enrico Scholz +# +# 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; version 2 of the License. +# +# 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; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +function yum.installBasePackages +{ + local name="$1" + local dir="$2" + + test "$dir" != / || return 0 + for filelist in "$dir"/*; do + test -f "$filelist" || continue + local idx=0 + local can_fail=false + local flags= + + set -- $(<$filelist) + while test "$#" -gt 0; do + case "$1" in + --reinstall) flags='';; + --can-fail) can_fail=true;; + *) break;; + esac + shift + done + "$_VYUM" "$name" -- -y install $flags $* || $can_fail + done +} + +function yum.initVariables +{ + findDir YUMREPOSDEFAULT \ + "$CONFDIR/.distributions/$DISTRIBUTION/yum.repos.d" \ + "$DISTRIBDIR/$DISTRIBUTION/yum.repos.d" \ + '' +} + +function yum.initFilesystem +{ + mkdir -p "$PKGCFGDIR"/yum/{etc,cache} + + populateDirectory "$PKGCFGDIR/yum/etc" \ + "$DISTRIBDIR/defaults/yum" \ + "$DISTRIBDIR/$DISTRIBUTION/yum" \ + "$CONFDIR/.distributions/$DISTRIBUTION/yum" + + ## workaround for yum's automatism to search the configuration in the chroot + local prefix='/../../../../../../../../../../../../' + local f="$PKGCFGDIR"/yum/etc/yum.conf + if test -e "$f"; then + $_SED -e "s!@YUMETCDIR@!$prefix$PKGCFGDIR/yum/etc!g; + s!@YUMCACHEDIR@!$prefix$PKGCFGDIR/yum/cache!g; + s!@YUMLOGDIR@!$prefix$PKGCFGDIR/yum!g; + " "$f" >"$f.tmp" + $_CMP -s "$f" "$f.tmp" || $_CAT "$f.tmp" >"$f" + $_RM -f "$f.tmp" + fi + + test -z "$YUMREPOSDEFAULT" -o -e "$PKGCFGDIR/yum/etc/yum.repos.d" || \ + $_LN_S "$YUMREPOSDEFAULT" "$PKGCFGDIR/yum/etc/yum.repos.d" +} diff --git a/util-vserver/scripts/vserver-build.yum b/util-vserver/scripts/vserver-build.yum new file mode 100644 index 0000000..f8df080 --- /dev/null +++ b/util-vserver/scripts/vserver-build.yum @@ -0,0 +1,57 @@ +# $Id$ --*- sh -*-- + +# Copyright (C) 2005 Enrico Scholz +# +# 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; version 2 of the License. +# +# 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; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +tmp=$(getopt -o +d: --long debug -n "$0" -- "$@") || exit 1 +eval set -- "$tmp" + +. "$_LIB_VSERVER_BUILD_FUNCTIONS_RPM" +. "$_LIB_VSERVER_BUILD_FUNCTIONS_YUM" +. "$_LIB_VSERVER_BUILD_FUNCTIONS_PKGMGMT" + +while true; do + case "$1" in + (-d) DISTRIBUTION=$2; shift;; + (--debug) set -x;; + (--) shift; break ;; + (*) echo "vserver-build.yum-rpm: internal error: unrecognized option '$1'" >&2 + exit 1 + ;; + esac + shift +done + +getDistribution + +base.initVariables +pkgmgmt.initVariables +rpm.initVariables +yum.initVariables + +base.initFilesystem "$OPTION_FORCE" +pkgmgmt.initFilesystem "$OPTION_FORCE" +rpm.initFilesystem +yum.initFilesystem + +setup_writeOption "$VSERVER_NAME" +setup_writeInitialFstab + +test -z "$BUILD_INITPRE" || "$BUILD_INITPRE" "$SETUP_CONFDIR" "$UTIL_VSERVER_VARS" +rpm.importGPGPubKeys "$SETUP_CONFDIR" "$CONFDIR/.distributions/$DISTRIBUTION/pubkeys" "$DISTRIBDIR/$DISTRIBUTION/pubkeys" +rpm.initDB "$SETUP_CONFDIR" +yum.installBasePackages "$SETUP_CONFDIR" "$PKGDIR" +$_VYUM "$SETUP_CONFDIR" -- clean all +test -z "$BUILD_INITPOST" || "$BUILD_INITPOST" "$SETUP_CONFDIR" "$UTIL_VSERVER_VARS" diff --git a/util-vserver/scripts/vsomething b/util-vserver/scripts/vsomething new file mode 100755 index 0000000..a2d497b --- /dev/null +++ b/util-vserver/scripts/vsomething @@ -0,0 +1,126 @@ +#! /bin/bash +# $Id$ + +# Copyright (C) 2005 Enrico Scholz +# +# 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; version 2 of the License. +# +# 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; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +: ${UTIL_VSERVER_VARS:=/usr/lib/util-vserver/util-vserver-vars} +test -e "$UTIL_VSERVER_VARS" || { + echo $"Can not find util-vserver installation (the file '$UTIL_VSERVER_VARS' would be expected); aborting..." >&2 + exit 1 +} +. "$UTIL_VSERVER_VARS" +. "$_LIB_FUNCTIONS" + + +function showHelp() +{ + echo \ +$"Usage: $0 [--quiet|-q] [--debug] [--] * [--all] -- + + +Execute * foreach vserver. + +Report bugs to <$PACKAGE_BUGREPORT>." + exit 0 +} + +function showVersion() +{ + echo \ +$"vsomething $PACKAGE_VERSION -- execute something for a set of vservers +This program is part of $PACKAGE_STRING + +Copyright (C) 2005 Enrico Scholz +This program is free software; you may redistribute it under the terms of +the GNU General Public License. This program has absolutely no warranty." + exit 0 +} + + +is_quiet= +declare -a vservers=() + +tmp=$(getopt -o +q --long help,version,debug,quiet -n "$0" -- "$@") || exit 1 +eval set -- "$tmp" + +while true; do + case "$1" in + (--help) showHelp $0 ;; + (--version) showVersion ;; + (--debug) set -x;; + (--quiet|-q) is_quiet=1 ;; + (--) shift; break;; + (*) echo $"vserver: internal error; arg=='$1'" >&2; exit 1;; + esac + shift +done + +test "$#" -ge 1 || \ + panic $"vsomething: no operation specified; try '--help' for more information" + +cmd=$1 +title=${VSOMETHING_TITLE:-$cmd} +shift + +while test "$#" -ge 1; do + case "$1" in + --) shift; break;; + --all) + getAllVservers tmp + vservers=( "${vservers[@]}" "${tmp[@]}" ) + ;; + *) vservers=( "${vservers[@]}" "$1" ) + esac + shift +done + + +test "${#vservers[@]}" -ne 1 || is_quiet=1 + + +cnt=0 +res=255 +for i in "${vservers[@]}"; do + cnt=$[ cnt + 1 ] + + test "$is_quiet" || { + colorize bold echo -n "$title: operating on vserver " + colorize bold colorize emph echo "$i" + xtermTitle "$title: operating on vserver '$i' [$cnt/${#vservers[@]}]" + } + + if test "$VSOMETHING_PKGMGMT"; then + if pkgmgmt.isInternal "$i"; then + $_VSERVER "$i" exec "$cmd" "$@" + else + callInNamespace "$i" \ + "$_VNAMESPACE" --new -- "$VSOMETHING_WORKER" "$i" "$@" + fi + else + "$cmd" "$i" "$@" + fi + + res=$? + + test $res -eq 0 -o "$is_quiet" || { + colorize error echo -n $"$title failed on vserver '$i' with errorcode $res" + echo + } + + test "$is_quiet" || echo +done + +test "$cnt" -ge 0 || warning $"No vservers specified" +exit $res diff --git a/util-vserver/scripts/vyum b/util-vserver/scripts/vyum new file mode 100755 index 0000000..1ae3fe8 --- /dev/null +++ b/util-vserver/scripts/vyum @@ -0,0 +1,72 @@ +#! /bin/bash +# $Id$ + +# Copyright (C) 2005 Enrico Scholz +# +# 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; version 2 of the License. +# +# 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; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +: ${UTIL_VSERVER_VARS:=/usr/lib/util-vserver/util-vserver-vars} +test -e "$UTIL_VSERVER_VARS" || { + echo $"Can not find util-vserver installation (the file '$UTIL_VSERVER_VARS' would be expected); aborting..." >&2 + exit 1 +} +. "$UTIL_VSERVER_VARS" +. "$_LIB_FUNCTIONS" + + +function showHelp() +{ + echo \ +$"Usage: $0 * [--all] -- + + +Report bugs to <$PACKAGE_BUGREPORT>." + exit 0 +} + +function showVersion() +{ + echo \ +$"vyum $PACKAGE_VERSION -- yum for vservers +This program is part of $PACKAGE_STRING + +Copyright (C) 2005 Enrico Scholz +This program is free software; you may redistribute it under the terms of +the GNU General Public License. This program has absolutely no warranty." + exit 0 +} + +tmp=$(getopt -o +q --long help,version,debug,quiet -n "$0" -- "$@") || exit 1 +eval set -- "$tmp" + +declare -a send_through + +while true; do + case "$1" in + (--help) showHelp $0 ;; + (--version) showVersion ;; + (--debug) send_through=( "${send_through[@]}" "$1" ); set -x;; + (--quiet|-q) send_through=( "${send_through[@]}" "$1" );; + (--) shift; break;; + (*) echo $"vyum: internal error; arg=='$1'" >&2; exit 1;; + esac + shift +done + +VSOMETHING_TITLE=vyum +VSOMETHING_WORKER=$_VYUM_WORKER +VSOMETHING_PKGMGMT=1 + +export VSOMETHING_TITLE VSOMETHING_WORKER VSOMETHING_PKGMGMT + +exec $_VSOMETHING "${send_through[@]}" yum "$@" diff --git a/util-vserver/scripts/vyum-worker b/util-vserver/scripts/vyum-worker new file mode 100755 index 0000000..18f6540 --- /dev/null +++ b/util-vserver/scripts/vyum-worker @@ -0,0 +1,38 @@ +#! /bin/bash +# $Id$ + +# Copyright (C) 2003 Enrico Scholz +# +# 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; version 2 of the License. +# +# 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; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +set -e + +: ${UTIL_VSERVER_VARS:=/usr/lib/util-vserver/util-vserver-vars} +test -e "$UTIL_VSERVER_VARS" || { + echo $"Can not find util-vserver installation (the file '$UTIL_VSERVER_VARS' would be expected); aborting..." >&2 + exit 1 +} +. "$UTIL_VSERVER_VARS" +. "$_LIB_FUNCTIONS" + +vserver="$1" +shift + +pkgInit "$vserver" rpm yum +rpmFake.init "$vserver" + +rpmFake.exec ${_YUM:-yum} \ + -c "$YUMETCDIR/yum.conf" \ + --installroot="$VDIR" \ + "$@" diff --git a/util-vserver/src/check-unixfile.c b/util-vserver/src/check-unixfile.c new file mode 100644 index 0000000..a17a064 --- /dev/null +++ b/util-vserver/src/check-unixfile.c @@ -0,0 +1,115 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2005 Enrico Scholz +// +// 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; version 2 of the License. +// +// 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; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "util.h" + +#include +#include +#include +#include +#include + +#define ENSC_WRAPPERS_PREFIX "check-unixfile: " +#define ENSC_WRAPPERS_FCNTL 1 +#define ENSC_WRAPPERS_UNISTD 1 +#include + +int wrapper_exit_code = 255; + +static void +showHelp(int fd, char const *cmd) +{ + WRITE_MSG(fd, "Usage: "); + WRITE_STR(fd, cmd); + WRITE_MSG(fd, + " [--] +\n\n" + "Please report bugs to " PACKAGE_BUGREPORT "\n"); + exit(0); +} + +static void +showVersion() +{ + WRITE_MSG(1, + "check-unixfile " VERSION " -- execute some basic fileformat checks\n" + "This program is part of " PACKAGE_STRING "\n\n" + "Copyright (C) 2005 Enrico Scholz\n" + VERSION_COPYRIGHT_DISCLAIMER); + exit(0); +} + +static bool +checkFile(char const *fname) +{ + int fd = Eopen(fname, O_RDONLY, 0); + off_t l = Elseek(fd, 0, SEEK_END); + char const * data = 0; + bool res = true; + + if (l>100*1024*1024) { + WRITE_MSG(2, "WARNING: '"); + WRITE_STR(2, fname); + WRITE_STR(2, "' is too large for a vserver configuration file\n"); + res = false; + } + else if (l>0) { + data = mmap(0, l, PROT_READ, MAP_PRIVATE, fd, 0); + if (data==0) { + perror("mmap()"); + exit(wrapper_exit_code); + } + + if (data[l-1]!='\n') { + WRITE_MSG(2, "WARNING: '"); + WRITE_STR(2, fname); + WRITE_MSG(2, "' does not end on newline\n"); + res = false; + } + + munmap(const_cast(char *)(data), l); + } + + Eclose(fd); + + return res; +} + +int main(int argc, char *argv[]) +{ + int idx = 1; + bool ok = true; + bool passed = false; + + if (argc>=2) { + if (strcmp(argv[1], "--help") ==0) showHelp(1, argv[0]); + if (strcmp(argv[1], "--version")==0) showVersion(); + if (strcmp(argv[1], "--") ==0) ++idx; + } + + for (; idx