diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/createpkg | 184 | ||||
-rwxr-xr-x | src/jail-update | 62 | ||||
-rwxr-xr-x | src/jail-upgrade | 107 | ||||
-rwxr-xr-x | src/lspkg | 68 | ||||
-rwxr-xr-x | src/metapkg | 60 | ||||
-rwxr-xr-x | src/mkjail | 100 | ||||
-rwxr-xr-x | src/rebuildpkg | 83 | ||||
-rwxr-xr-x | src/simplaret | 482 | ||||
-rwxr-xr-x | src/templatepkg | 90 |
9 files changed, 1236 insertions, 0 deletions
diff --git a/src/createpkg b/src/createpkg new file mode 100644 index 0000000..45fb329 --- /dev/null +++ b/src/createpkg @@ -0,0 +1,184 @@ +#!/bin/bash +# +# createpkg: package builder using http://slack.sarava.org/slackbuilds scripts +# feedback: rhatto at riseup.net | gpl +# +# createpkg 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 any later version. +# +# createpkg 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 +# +# /etc/simplepkg/slackbuildrc parameters: +# +# SLACKBUILDS="/folder/to/place/slackbuilds", defaults to /var/slackbuilds +# SVN="svn://repository", defaults do svn://slack.sarava.org/slackbuilds +# SYNC="yes|no", whether to always update the repository +# + +COMMON="/usr/libexec/simplepkg/common.sh" +SLACKBUILDRC="/etc/slackbuildrc" + +if [ -f "$COMMON" ]; then + source $COMMON +else + echo "error: file $COMMON found, check your `basename $0` installation" + exit 1 +fi + +function safe_exit { + + # exit codes + case $1 in + 2) echo Could not create folder $2;; + 3) echo Could not update the repository $2 ;; + 4) usage ;; + 5) echo Script not found;; + *) exit 1 + esac + + exit $1 + +} + +function build_repo { + + BASEDIR="`dirname $SLACKBUILDS`" + mkdir -p $BASEDIR || safe_exit 2 $BASEDIR + cd $BASEDIR + svn checkout $SVN + cd $SLACKBUILDS + +} + +function usage { + + echo "usage: createpkg [--install] package-name" + echo " createpkg --search package-name" + echo " createpkg --sync" + +} + +function check_config { + + if [ -f "$SLACKBUILDRC" ]; then + source $SLACKBUILDRC + fi + + TMP=${TMP:=/tmp} + REPOS=${REPOS:=$TMP} + SLACKBUILDS=${SLACKBUILDS:=/var/slackbuilds} + SVN=${SVN:=svn://slack.sarava.org/slackbuilds} + SYNC=${SYNC:=no} + BASEDIR="`dirname $SLACKBUILDS`" + +} + +function solve_dep { + + # TODO: solve dep with version checking + + pack="$1" + for candidate in `ls /var/log/packages/$pack* 2> /dev/null`; do + candidate="`package_name $candidate`" + if [ "$pack" == "$candidate" ]; then + found="1" + break + fi + done + + if [ "$found" != "1" ]; then + createpkg --install $pack + else + found="0" + fi + +} + +function check_repo { + + if [ ! -d "$SLACKBUILDS" ]; then + build_repo + fi + +} + +function sync_repo { + + cd $SLACKBUILDS + svn update || build_repo + +} + +function find_script { + + find $SLACKBUILDS | grep -v .svn | grep $1.SlackBuild + +} + +check_config +check_repo + +if [ -z "$1" ]; then + safe_exit 4 +elif [ "$1" == "--sync" ]; then + sync_repo + exit +elif [ "$1" == "--search" ]; then + find_script $2 + exit +elif [ "$1" == "--install" ]; then + PACKAGE="$2" + INSTALL="1" +else + PACKAGE="$1" +fi + +if [ "$SYNC" == "yes" ]; then + sync_repo +fi + +BUILD_SCRIPT="`find_script $PACKAGE`" + +if [ -z "$BUILD_SCRIPT" ]; then + safe_exit 5 +fi + +SCRIPT_BASE="`dirname $BUILD_SCRIPT`" + +if [ -f "$SCRIPT_BASE/$PACKAGE.slack-required" ]; then + SLACK_REQ="$SCRIPT_BASE/$PACKAGE.slack-required" +elif [ -f "$SCRIPT_BASE/slack-required" ]; then + SLACK_REQ="$SCRIPT_BASE/slack-required" +fi + +if [ ! -z "$SLACK_REQ" ]; then + + cat $SLACK_REQ | while read dep; do + dep="`echo $dep | sed -e 's/>=/equalorgreater/' -e 's/=</equalorless/' -e 's/</less/' -e 's/>/greater/' -e 's/=/equal/'`" + solve_dep $dep + done + +fi + +cd $SCRIPT_BASE +INTERACT=no ./`basename $BUILD_SCRIPT` + +VERSION="`grep -e '^VERSION=' $BUILD_SCRIPT | head -n 1 | sed -e "s/VERSION//g" -e 's/=//g' -e 's/-//g' | cut -d ":" -f 2 | cut -d "}" -f 1`" +BUILD="`grep -e '^BUILD=' $BUILD_SCRIPT | head -n 1 | sed -e "s/BUILD//g" -e 's/=//g' | cut -d ":" -f 2 | cut -d "}" -f 1`" +_ARCH="`grep -e '^ARCH' $BUILD_SCRIPT | head -n 1 | cut -d "=" -f 2 | sed -e 's/"//g'`" + +if [ "$_ARCH" == "noarch" ]; then + ARCH="noarch" +fi + +if [ "$INSTALL" == "1" ]; then + installpkg $REPOS/$PACKAGE-$VERSION-$ARCH-$BUILD.tgz +fi + diff --git a/src/jail-update b/src/jail-update new file mode 100755 index 0000000..f6635b5 --- /dev/null +++ b/src/jail-update @@ -0,0 +1,62 @@ +#!/bin/bash +# +# jail-update: update config files from a jail to a template +# feedback: rhatto@riseup.net | gpl +# +# Jail-update 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 any later version. +# +# Jail-update 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 +# + +COMMON="/usr/libexec/simplepkg/common.sh" + +if [ -f "$COMMON" ]; then + source $COMMON +else + echo "error: file $COMMON found, check your `basename $0` installation" + exit 1 +fi + +if [ -f $JAIL_LIST ]; then + for jailpath in `cat $JAIL_LIST`; do + jail="`basename $jailpath`" + echo updating $jailpath... + if [ -d "$BASE_CONF/$jail.d" ] || [ -a "$BASE_CONF/$jail.template" ]; then + templatepkg -a $jail $jailpath + cd $BASE_CONF/$jail.d + for file in `find`; do + if [[ -f "$file" && -f "$jailpath/$file" ]]; then + if ! diff $file $jailpath/$file; then + echo updating $file + cp -f $jailpath/$file $file + fi + fi + done + fi + done +fi + +# main jail +if [ -a "$BASE_CONF/main.template" ]; then + echo updating main installation... + templatepkg -a main +fi +if [ -d "$BASE_CONF/main.d" ]; then + cd $BASE_CONF/main.d + for file in `find`; do + if [[ -f "$file" && -f "/$file" ]]; then + if ! diff $file /$file; then + echo updating $file + cp -f /$file $file + fi + fi + done +fi diff --git a/src/jail-upgrade b/src/jail-upgrade new file mode 100755 index 0000000..b9567fd --- /dev/null +++ b/src/jail-upgrade @@ -0,0 +1,107 @@ +#!/bin/bash +# +# jail-upgrade v0.5: upgrade packages in jails +# feedback: rhatto@riseup.net | GPL +# +# Jail-upgrade 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 any later version. +# +# Jail-upgrade 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 +# + +COMMON="/usr/libexec/simplepkg/common.sh" + +function swaret_jail_upgrade { + + if [ ! -d "$PATCHES_DIR" ]; then + cd $PATCHES_DIR + for installed in `ls $1/var/log/packages/$pack* 2> /dev/null`; do + if [[ $pack == `package_name $installed.tgz` ]]; then + if [[ "`basename $installed`" != "`basename $file .tgz`" ]]; then + ROOT=$1 upgradepkg $file + fi + fi + done + fi +} + +function simplaret_jail_upgrade { + + echo upgrading jail $1... + + VERSION="`cat $1/etc/slackware-version | awk '{ print $2 }' | sed -e 's/.0$//'`" + ARCH="`cat $1/etc/slackware-version | awk '{ print $3 }' | sed -e 's/(//' -e 's/)//'`" + + if [ -z "$ARCH" ]; then + ARCH="i386" + fi + + if [ -d "$PATCHES_DIR/$ARCH/$VERSION" ]; then + cd $PATCHES_DIR/$ARCH/$VERSION + for file in `ls *tgz`; do + pack=`package_name $file` + for installed in `ls $1/var/log/packages/$pack* 2> /dev/null`; do + if [[ "$pack" == "`package_name $installed.tgz`" ]]; then + if [[ "`basename $installed`" != "`basename $file .tgz`" ]]; then + ROOT=$1 upgradepkg $file + fi + fi + done + done + else + echo error: cant upgrade for arch $ARCH and version $VERSION on $1: no such patch dir $PATCHES_DIR/$ARCH/$VERSION + fi + +} + +if [ -f "$COMMON" ]; then + source $COMMON + eval_config `basename $0` +else + echo "error: file $COMMON not found, check your `basename $0` installation" + exit 1 +fi + +if [ ! -z "$PATCHES" ]; then + if [ -d "$PATCHES" ]; then + PATCHES_DIR="$PATCHES" + else + echo "error: folder $PATCHES does not exist" + fi +fi + +if [ "$SIMPLARET" == "simplaret" ]; then + upgrade_method="simplaret_jail_upgrade" +elif [ "$SIMPLARET" == "swaret" ]; then + upgrade_method="swaret_jail_upgrade" +else + echo invalid value $SIMPLARET for SIMPLARET, please check your $CONF + exit 1 +fi + +if [ -z "$1" ]; then + if [ -d "/var/log/packages" ]; then + $upgrade_method / + fi + for vserver in `ls $JAIL_ROOT`; do + if [ -d "$JAIL_ROOT/$vserver/var/log/packages" ]; then + $upgrade_method $JAIL_ROOT/$vserver + fi + done +elif [ -d "$JAIL_ROOT/$1" ]; then + if [ -d "$JAIL_ROOT/$1/var/log/packages" ]; then + $upgrade_method $JAIL_ROOT/$1 + else + echo error: jail $JAIL_ROOT/$1 dont looks like a slackware system + fi +else + echo "error: jail $0 does not exist" + exit 1 +fi diff --git a/src/lspkg b/src/lspkg new file mode 100755 index 0000000..0eb5e77 --- /dev/null +++ b/src/lspkg @@ -0,0 +1,68 @@ +#!/bin/bash +# +# lspkg v0.2: view installed and contents of +# slackware packages +# +# feedback: rhatto at riseup.net | gpl +# +# Lspkg 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 any later version. +# +# Lspkg 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 +# +# +# -v, --view: view installed package contents +# -p, --print: print the contents of a package file +# -r, --remove: remove matching packages +# -s, --search: search a file under installed packages +# +# todo: +# +# -d, --description: show matching packages' descriptions +# -h, --help: show usage +# + +function usage { + echo "usage: $0 [-v|-d|-s|-p expression]" + exit 1 +} + +if [[ "$1" = "-v" ]]; then + if [[ ! -z "$2" ]]; then + if $(ls /var/log/packages/$2* &> /dev/null); then + for file in $(ls /var/log/packages/$2*); do + less $file + done + else echo $2: package not found on /var/log/packages + fi + else + usage + fi +elif [[ "$1" = "-p" ]]; then + if [ -f $2 ]; then + tar ztvf $2 + else echo $2: file not found + fi +elif [[ "$1" == "-r" ]]; then + if [ ! -z "$2" ]; then + if `ls /var/log/packages/$1* &> /dev/null`; then + removepkg /var/log/packages/$1* + fi + fi +elif [[ "$1" == "-s" ]]; then + if [[ ! -z "$2" ]]; then + grep $2 /var/log/packages/* + fi +else + if `ls /var/log/packages/$1* &> /dev/null`; then + ls /var/log/packages/$1* + else echo $1: package not found on /var/log/packages + fi +fi diff --git a/src/metapkg b/src/metapkg new file mode 100755 index 0000000..e83ee4d --- /dev/null +++ b/src/metapkg @@ -0,0 +1,60 @@ +#!/bin/bash +# +# metapkg v0.1: install or remove a pkgtool metapackage +# +# feedback: rhatto at riseup.net | GPL +# +# Metapkg 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 any later version. +# +# Metapkg 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 +# +# A metapackage is a file containing a list of packages. +# This script just installs all the packages in a metapackage. +# Remeber that mkjail template == metapkg metapackage. +# + +COMMON="/usr/libexec/simplepkg/common.sh" +ROOT="/" + +function usage { + echo "usage: [ROOT=/otherroot] `basename $0` --option [metapackage]" + echo "options: --install, --remove" + exit 1 +} + +if [ -f "$COMMON" ]; then + source $COMMON +else + echo "error: file $COMMON found, check your `basename $0` installation" + exit 1 +fi + +if [ -z "$2" ]; then + usage +else + eval_config `basename $0` -u +fi + +if [ ! -f "$BASE_CONF/$2.template" ]; then + echo error: template $2 not found + exit 1 +else + TEMPLATE="$BASE_CONF/$2.template" + unset server +fi + +if [[ "$1" == "--install" ]]; then + install_packages +elif [[ "$1" == "--remove" ]]; then + remove_packages +else + usage +fi diff --git a/src/mkjail b/src/mkjail new file mode 100755 index 0000000..d0d24a0 --- /dev/null +++ b/src/mkjail @@ -0,0 +1,100 @@ +#!/bin/bash +# +# mkjail v0.4: chroot jail maker +# +# feedback: rhatto at riseup.net | GPL +# +# Mkjail 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 any later version. +# +# Mkjail 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 +# +# Under the config file, adjust this to where your things live, for example: +# +# JAIL_ROOT="/vservers" # default folder where jails lives +# STORAGE="/var/simplaret" # place where simplaret host its packages +# SIMPLARET_CLEAN="1" # delete downloaded packages before installation +# SIMPLARET_DELETE_DOWN="1" # delete donwloaded packages after installation +# SIMPLARET_DELETE_DURING="1" # delete each package rigth after its installation +# SIMPLARET_UPDATE="0" # simplaret --update before get the packages +# SIMPLARET_PURGE_WEEKS="N" # purge cached packages older than N weeks +# PATCHES_DIR=/var/simplaret/patches" # where your patches lives +# +# todo: - list of packages that could not be installed +# - use swaret just for network mirrors +# - installation order +# - optionally execute chroot-upgrade after installation +# + +COMMON="/usr/libexec/simplepkg/common.sh" + +function usage { + echo "usage: [ROOT=/otherroot] `basename $0` <jail-name> [template]" + exit 1 +} + +if [ -f "$COMMON" ]; then + source $COMMON +else + echo "error: file $COMMON found, check your `basename $0` installation" + exit 1 +fi + +if [ -z "$1" ]; then + usage +else + server="$1" + eval_config `basename $0` -u +fi + +if [[ ! -z "$2" && -f "$BASE_CONF/$2.template" ]]; then + TEMPLATE="$BASE_CONF/$2.template" +elif [[ ! -z "$2" && ! -f "$BASE_CONF/$2.template" ]]; then + echo template $2 not found, using default template + TEMPLATE="$BASE_CONF/default.template" +elif [[ -z "$2" && -f "$BASE_CONF/default.template" ]]; then + TEMPLATE="$BASE_CONF/default.template" + echo using default template +else + echo $0 error: no templates found + echo please create a template using templatepkg + exit 1 +fi + +if [ ! -d "$JAIL_ROOT/$server" ]; then + mkdir -p $JAIL_ROOT/$server +else + if [ ! -z "`ls $JAIL_ROOT/$server | grep -v 'lost+found'`" ]; then + echo error: folder $JAIL_ROOT/$server already exists and seens to be not empty + echo probably the jail $1 already exists + exit 1 + fi +fi + +echo "instaling packages into $JAIL_ROOT/$server using $TEMPLATE..." +install_packages + +TEMPLATE="`echo $TEMPLATE | sed -e 's/\.template$//'`" +echo "copying template files..." +if [ -d "$TEMPLATE.d" ]; then + rsync -av $TEMPLATE.d/ $JAIL_ROOT/$server/ +fi + +echo "executing template scripts..." +if [ -d "$TEMPLATE.s" ]; then + for script in `ls $TEMPLATE.s/`; do + if [ -x "$TEMPLATE.s/$script" ]; then + exec $TEMPLATE.s/$script $JAIL_ROOT $server + fi + done +fi + +echo "$JAIL_ROOT/$server" >> $JAIL_LIST +echo "done creating $server jail" diff --git a/src/rebuildpkg b/src/rebuildpkg new file mode 100755 index 0000000..43c76cd --- /dev/null +++ b/src/rebuildpkg @@ -0,0 +1,83 @@ +#!/bin/bash +# +# rebuildpkg: build a package from a /var/log/packages entry +# +# feedback: rhatto at riseup.net | gpl +# +# Rebuildpkg 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 any later version. +# +# Rebuildpkg 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 +# + +COMMON="/usr/libexec/simplepkg/common.sh" +TMP="/tmp" + +function usage { + echo "usage: ROOT=/otherroot `basename $0` <package-name>" +} + +if [ -f "$COMMON" ]; then + source $COMMON +else + echo "error: file $COMMON found, check your `basename $0` installation" + exit 1 +fi + +if [ -z "$1" ]; then + usage + exit 1 +fi + +pack="$1" + +for file in `find $ROOT/var/log/packages -name $pack*`; do + if [[ "`package_name $file.tgz`" == "$pack" ]]; then + package_file="$file" + break + fi +done + +if [ -z "$package_file" ]; then + echo error: package $pack does not exist +fi + +if [ -d "$TMP/package-$pack" ]; then + rm -rf $TMP/package-$pack +fi + +mkdir $TMP/package-$pack +cd $TMP/package-$pack + +for file in `grep -v -e "^PACKAGE NAME:" -e "^UNCOMPRESSED PACKAGE SIZE:" \ + -e "^COMPRESSED PACKAGE SIZE:" -e "^PACKAGE LOCATION:" \ + -e "^PACKAGE DESCRIPTION:" -e "^$pack:" -e "^FILE LIST:" $package_file`; do + + if [ -d /$file ]; then + mkdir -p $TMP/package-$pack/$file + elif [ -f /$file ]; then + cp /$file $TMP/package-$pack/$file + else echo file /$file was not found, please add it manually, exploding and making the package again + fi + +done + +mkdir $TMP/package-$pack/install +grep "^$pack:" $package_file > $TMP/package-$pack/install/slack-desc + +package_name="`grep "PACKAGE NAME:" $package_file | awk '{ print $3 }'`" + +if [ -f "$ROOT/var/log/scripts/$package_name" ]; then + cp $ROOT/var/log/scripts/$package_name $TMP/package-$pack/install/doinst.sh +fi + +makepkg $package_name.tgz +mv $package_name.tgz $TMP/ +echo "done: package rebuilt and stored at $TMP/$package_name.tgz" diff --git a/src/simplaret b/src/simplaret new file mode 100755 index 0000000..ed98402 --- /dev/null +++ b/src/simplaret @@ -0,0 +1,482 @@ +#!/bin/bash +# +# simplaret v0.1.1: simplepkg's package grabber +# feedback: rhatto at riseup.net | gpl +# +# Simplaret 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 any later version. +# +# Simplaret 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 +# +# config file simplepkg.conf: +# +# DEFAULT_ARCH="i386" +# DEFAULT=VERSION="10.2" +# STORAGE="/storage/packages" +# PASSIVE_FTP="1" +# +# config file repos.conf: +# +# ROOT-i386="http://slack.sarava.org/packages/slackware" +# REPOS-i386-10.2="slack.sarava.org%http://slack.sarava.org/packages/slackware/slackware-10.2/" +# ROOT-x86_64="http://darkstar.ist.utl.pt/pub/slamd64/" +# REPOS-x86_64-10.2="slack.sarava.org%http://slack.sarava.org/packages/slamd64/slamd64-10.2/" +# +# usage: +# +# --update: baixa lista de pacotes de cada repositorio +# --search: busca +# --get [-a]: baixa um unico pacote +# --get-pacthes: baixa os patches e faz o checksum / gpg +# --purge [-w N]: remove o cache +# +# precedence: +# +# - checa antes o repositorio raiz, caso o pacote nao seja encontrado segue na ordem das +# definicoes REPOS do arquivo de configuracao +# + +SIMPLARET_CONF="/etc/simplepkg/simplepkg.conf" +REPOS_CONF="/etc/simplepkg/repos.conf" +COMMON="/usr/libexec/simplepkg/common.sh" + +function simplaret_usage { + + echo "usage: [ARCH=otherarch] [VERSION=otherversion] `basename $0` <OPTION> package-name" + echo -e "\t OPTIONS: --update, --search, --get, --get-patches" + exit 1 + +} + +function simplaret_eval_config { + + if grep -qe "^DEFAULT_ARCH=" $SIMPLARET_CONF; then + DEFAULT_ARCH="`grep -e "^DEFAULT_ARCH=" $SIMPLARET_CONF | cut -d = -f 2 | sed -e 's/"//g' -e "s/'//g" | cut -d "#" -f 1`" + else + DEFAULT_ARCH="i386" + fi + + if grep -qe "^DEFAULT_VERSION=" $SIMPLARET_CONF; then + DEFAULT_VERSION="`grep -e "^DEFAULT_VERSION=" $SIMPLARET_CONF | cut -d = -f 2 | sed -e 's/"//g' -e "s/'//g" | cut -d "#" -f 1`" + else + DEFAULT_VERSION="10.2" + fi + + if grep -qe "^STORAGE=" $SIMPLARET_CONF; then + STORAGE="`grep -e "^STORAGE=" $SIMPLARET_CONF | cut -d = -f 2 | sed -e 's/"//g' -e "s/'//g" | cut -d "#" -f 1`" + else + STORAGE="/var/simplaret" + fi + + if grep -qe "^PASSIVE_FTP=" $SIMPLARET_CONF; then + PASSIVE_FTP="`grep -e "^PASSIVE_FTP=" $SIMPLARET_CONF | cut -d = -f 2 | sed -e 's/"//g' -e "s/'//g" | cut -d "#" -f 1`" + else + PASSIVE_FTP="0" + fi + + if grep -qe "^WARNING=" $SIMPLARET_CONF; then + WARNING="`grep -e "^WARNING=" $SIMPLARET_CONF | cut -d = -f 2 | sed -e 's/"//g' -e "s/'//g" | cut -d "#" -f 1`" + else + WARNING="0" + fi + +} + +function simplaret_get_index { + + for file in FILELIST.TXT CHECKSUMS.md5 CHECKSUMS.md5.asc; do + simplaret_download $1 $file $2 + done + +} + +function simplaret_backup_index { + + for file in FILELIST.TXT CHECKSUMS.md5 CHECKSUMS.md5.asc; do + if [ -f "$1/$file" ]; then + mv $1/$file $1/$file.old + fi + done + +} + +function simplaret_check_index { + + for file in FILELIST.TXT CHECKSUMS.md5 CHECKSUMS.md5.asc; do + if [ ! -f "$1/$file" ] && [ -f "$1/$file" ]; then + echo restoring old $file to $1... + mv $1/$file.old $1/$file + else + rm -f $1/$file.old + fi + done + +} + +function simplaret_download { + + # downloads a file from a repo to a folder + # usage: simplaret <repos_url> <package> <destination-folder> + + protocol="`echo $1 | cut -d : -f 1`" + + if [ ! -d "$3" ]; then + mkdir -p $3 + fi + + if [ "$protocol" == "http" ]; then + (cd $3 && wget $1/$2) + elif [ "$protocol" == "ftp" ]; then + if [ "$PASSIVE_FTP" == "1" ]; then + passive_ftp="--passive-ftp" + fi + (cd $3 && wget $passive_ftp $1/$2) + elif [ "$protocol" == "file" ]; then + url="`echo $1 | sed -e 's/file:\/\///'`" + cp $url/$2 $3 2> /dev/null + fi + +} + +function simplaret_repos_name { + + if echo $repos | grep -qe %; then + repos_name="`echo $repos | cut -d % -f 1`" + if [ -z "$repos_name" ]; then + echo you should set a name for the repository $repos for arch $ARCH and version $VERSION + echo please correct your $REPOS_CONF so this repository definition looks like this: + echo REPOS-$ARCH-$VERSION=\"repository-name%repository-url\" + exit 1 + fi + else + echo you should set a name for the repository $repos for arch $ARCH and version $VERSION + echo please correct your $REPOS_CONF so this repository definition looks like this: + echo REPOS-$ARCH-$VERSION=\"repository-name%$repos_url\" + exit 1 + fi + +} + +function simplaret_repos_url { + + if echo $repos | grep -qe %; then + repos_url="`echo $repos | cut -d % -f 2`" + if [ -z "$repos_url" ]; then + echo you should set a url for the repository $repos for arch $ARCH and version $VERSION + echo please correct your $REPOS_CONF so this repository definition looks like this: + echo REPOS-$ARCH-$VERSION=\"repository-name%repository-url\" + exit 1 + fi + else + echo you should set a url for the repository $repos for arch $ARCH and version $VERSION + echo please correct your $REPOS_CONF so this repository definition looks like this: + echo REPOS-$ARCH-$VERSION=\"repository-name%repository-url\" + exit 1 + fi + +} + +function simplaret_root_url { + + root_url="`grep -e "^ROOT-$ARCH=" $REPOS_CONF | cut -d = -f 2 | sed -e 's/"//g' -e "s/'//g" | cut -d "#" -f 1`" + +} + +function simplaret_update { + + echo updating package information for arch $ARCH and version $VERSION... + + if [ ! -d "$STORAGE/$ARCH/$VERSION" ]; then + mkdir -p $STORAGE/$ARCH/$VERSION + else + simplaret_backup_index $STORAGE/$ARCH/$VERSION + fi + + simplaret_root_url + simplaret_get_index "$root_url/$DISTRO_FOLDER/$extra_folder" $STORAGE/$ARCH/$VERSION + simplaret_check_index $STORAGE/$ARCH/$VERSION + + for repos in `grep -e "^REPOS-$ARCH-$VERSION=" $REPOS_CONF | cut -d = -f 2 | sed -e 's/"//g' -e "s/'//g" | cut -d "#" -f 1`; do + + simplaret_repos_name + simplaret_repos_url + + if [ ! -d "$STORAGE/$ARCH/$VERSION/$repos_name" ]; then + mkdir -p $STORAGE/$ARCH/$VERSION/$repos_name + else + simplaret_backup_index $STORAGE/$ARCH/$VERSION/$repos_name + fi + + simplaret_get_index $repos_url $STORAGE/$ARCH/$VERSION/$repos_name + simplaret_check_index $STORAGE/$ARCH/$VERSION/$repos_name + + unset repos_name repos_url repos_protocol + + done + +} + +function simplaret_search { + + if [ ! -f "$STORAGE/$ARCH/$VERSION/FILELIST.TXT" ]; then + if [ "$WARNING" != "0" ] || [ ! -z "$SILENT" ]; then + echo warning: no file list for root repository on arch $ARCH version $VERSION, please do a simplaret --update + fi + else + for file in `grep $1 $STORAGE/$ARCH/$VERSION/FILELIST.TXT | awk '{ print $8 }' | grep -e ".tgz$"`; do + if echo $file | grep -q "patches"; then + patch="(patch)" + fi + if [ "$2" == "-silent" ]; then + echo `basename $file` + else + echo root repos, arch: $ARCH, version: $VERSION: `basename $file` $patch + fi + unset patch + done + fi + + for repos in `grep -e "^REPOS-$ARCH-$VERSION=" $REPOS_CONF | cut -d = -f 2 | sed -e 's/"//g' -e "s/'//g" | cut -d "#" -f 1`; do + + simplaret_repos_name + + if [ ! -f "$STORAGE/$ARCH/$VERSION/$repos_name/FILELIST.TXT" ]; then + if [ "$WARNING" != "0" ] || [ ! -z "$SILENT" ]; then + echo warning: no file list for $repos_name repository on arch $ARCH version $VERSION, please do a simplaret --update + fi + else + for file in `grep $1 $STORAGE/$ARCH/$VERSION/$repos_name/FILELIST.TXT | awk '{ print $8 }' | grep -e ".tgz$"`; do + if echo $file | grep -q "patches"; then + patch="(patch)" + fi + if [ "$2" == "-silent" ]; then + echo `basename $file` + else + echo $repos_name, arch: $ARCH, version: $VERSION: `basename $file` $patch + fi + done + fi + + done + +} + +function simplaret_purge { + + if [ "$2" == "-w" ] && [ ! -z "$3" ]; then + if [ -z "$SILENT" ]; then + echo purging all packages older than $3 weeks for arch $ARCH and version $VERSION + fi + mtime="`echo "$3*7" | bc -l`" + for file in `find $STORAGE/$ARCH/$VERSION/ -mtime +$mtime | bc -l 2> /dev/null`; do + for extension in tgz asc; do + if echo $file | grep -qe ".$extension$"; then + rm $file + fi + done + done + else + if [ -z "$SILENT" ]; then + echo purging all packages for arch $ARCH and version $VERSION + fi + for file in `find $STORAGE/$ARCH/$VERSION/ 2> /dev/null`; do + for extension in tgz asc; do + if echo $file | grep -qe ".$extension$"; then + rm $file + fi + done + done + fi + + if [ -z "$SILENT" ]; then + echo done purging simplaret cache, please run simplaret --update to retrieve new package listings on this arch and version + fi + +} + +function simplaret_get { + + # search for an already downloaded package + for file in `find $STORAGE/$ARCH/$VERSION/ -name $1*tgz 2> /dev/null`; do + candidate="`basename $file`" + if [ "`package_name $candidate`" == "$1" ]; then + echo package $candidate already downloaded and stored at `dirname $file` + exit 0 + fi + done + + # first search for the package in the root repository + if [ ! -f "$STORAGE/$ARCH/$VERSION/FILELIST.TXT" ]; then + if [ "$WARNING" != "0" ] || [ ! -z "$SILENT" ]; then + echo warning: no file list for root repository on arch $ARCH version $VERSION, please do a simplaret --update + fi + else + for file in `grep $1 $STORAGE/$ARCH/$VERSION/FILELIST.TXT | awk '{ print $8 }' | grep -e ".tgz$"`; do + candidate="`basename $file`" + if [ "`package_name $candidate`" == "$1" ]; then + simplaret_root_url + simplaret_download $root_url/$DISTRO_FOLDER/$extra_folder $file $STORAGE/$ARCH/$VERSION + if [ ! -f "$STORAGE/$ARCH/$VERSION/$candidate" ]; then + echo error downloading $candidate from root repository $root_url, please check your settings + exit 1 + else + echo package $candidate stored at $STORAGE/$ARCH/$VERSION + simplaret_checksum $STORAGE/$ARCH/$VERSION/CHECKSUMS.md5 $STORAGE/$ARCH/$VERSION/$candidate + exit 0 + fi + fi + done + fi + + # then search for the package in contrib repos + for repos in `grep -e "^REPOS-$ARCH-$VERSION=" $REPOS_CONF | cut -d = -f 2 | sed -e 's/"//g' -e "s/'//g" | cut -d "#" -f 1`; do + simplaret_repos_name + simplaret_repos_url + if [ ! -f "$STORAGE/$ARCH/$VERSION/$repos_name/FILELIST.TXT" ]; then + if [ "$WARNING" != "0" ] || [ ! -z "$SILENT" ]; then + echo warning: no file list for $repos_name repository on arch $ARCH version $VERSION, please do a simplaret --update + fi + else + for file in `grep $1 $STORAGE/$ARCH/$VERSION/$repos_name/FILELIST.TXT | awk '{ print $8 }' | grep -e ".tgz$"`; do + candidate="`basename $file`" + if [ "`package_name $candidate`" == "$1" ]; then + simplaret_download $repos_url $file $STORAGE/$ARCH/$VERSION/$repos_name + if [ ! -f "$STORAGE/$ARCH/$VERSION/$repos_name/$candidate" ]; then + echo error downloading $candidate from repository $repos_url, please check your settings + echo will try to fetch from the next repo, if exists... + else + echo package $candidate stored at $STORAGE/$ARCH/$VERSION/$repos_name + simplaret_checksum $STORAGE/$ARCH/$VERSION/$repos_name/CHECKSUMS.md5 $STORAGE/$ARCH/$VERSION/$repos_name/$candidate + exit 0 + fi + fi + done + fi + done + +} + +function simplaret_get_patches { + + if [ ! -d "$PATCHES_DIR/$ARCH/$VERSION" ]; then + mkdir -p $PATCHES_DIR/$ARCH/$VERSION + fi + + echo fetching patches for arch $ARCH and version $VERSION... + + # check for the downloaded patches + for patch in `ls $PATCHES_DIR/$ARCH/$VERSION/*tgz 2> /dev/null`; do + file="`find $STORAGE/$ARCH/$VERSION/ -name $patch 2> /dev/null`" + if [ ! -f "$file" ]; then + rm $patch + else + ln -sf $file $PATCHES_DIR/$ARCH/$VERSION/ + fi + done + + # grab new patches + for patch in `simplaret_search patches -silent`; do + simplaret --get `package_name $patch` + file="`find $STORAGE/$ARCH/$VERSION/ | grep "$patch" 2> /dev/null`" + if [ ! -f "$file" ]; then + echo error downloading package $file + exit 1 + else + ln -sf $file $PATCHES_DIR/$ARCH/$VERSION/ + echo patch stored as a symlink on $PATCHES_DIR/$ARCH/$VERSION/ + fi + done + +} + +function simplaret_checksum { + + # simplaret_checksum <md5file> <file-name> + + if [ ! -f "$1" ] || [ ! -f "$2" ]; then + echo checksum error: file not found + exit 1 + fi + + pack="`basename $2`" + checksum="`grep -e "$pack\$" $1 | awk '{ print $1 }'`" + + if [ -z "$checksum" ]; then + echo file $2 not in checksum $1 + exit 1 + elif [ "$checksum" != "`md5sum $2 | awk '{ print $1 }'`" ]; then + echo checksum mismatch for file `basename $file` + else + echo checksum ok for file `basename $file` + fi + +} + +if [ -f "$COMMON" ]; then + source $COMMON +else + echo "error: file $COMMON found, check your `basename $0` installation" + exit 1 +fi + +if [ -z "$1" ]; then + simplaret_usage + exit 1 +else + server="$1" + eval_config `basename $0` + simplaret_eval_config +fi + +if [ ! -d "$STORAGE" ]; then + mkdir -p $STORAGE +fi + +if [ -z "$ARCH" ]; then + ARCH="$DEFAULT_ARCH" +fi + +if [ -z "$VERSION" ]; then + VERSION="$DEFAULT_VERSION" +fi + +if [ "$ARCH" == "i386" ]; then + DISTRO="slackware" + DISTRO_FOLDER="$DISTRO-$VERSION" +elif [ "$ARCH" == "x86_64" ]; then + # extra_folder="tree" + DISTRO="slamd64" + DISTRO_FOLDER="$DISTRO-$VERSION" +elif [ "$ARCH" == "s390" ]; then + DISTRO="slack390" + DISTRO_FOLDER="$DISTRO-$VERSION" +elif [ "$ARCH" == "x86_uclibc" ]; then + DISTRO="ucslack" + DISTRO_FOLDER="$DISTRO-$VERSION" +elif [ "$ARCH" == "arm" ]; then + DISTRO="armedslack" + DISTRO_FOLDER="$DISTRO-$VERSION" +elif [ "$ARCH" == "powerpc" ]; then + DISTRO="slackintosh" + DISTRO_FOLDER="$VERSION" +elif [ "$ARCH" == "sparc" ]; then + DISTRO="splack" + DISTRO_FOLDER="tree-$VERSION" +fi + +case $1 in + --update) simplaret_update ;; + --search) simplaret_search $2 ;; + --get) simplaret_get $2 ;; + --get-patches) simplaret_get_patches ;; + --purge) simplaret_purge ;; + *) simplaret_usage ;; +esac + diff --git a/src/templatepkg b/src/templatepkg new file mode 100755 index 0000000..9c1f8bc --- /dev/null +++ b/src/templatepkg @@ -0,0 +1,90 @@ +#!/bin/bash +# +# templatepkg v0.2: create a simplepkg package list from +# a legacy slackware /var/log/packages +# +# feedback: rhatto at riseup.net | gpl +# +# Templatepkg 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 any later version. +# +# Templatepkg 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 +# + +COMMON="/usr/libexec/simplepkg/common.sh" + +if [ -f "$COMMON" ]; then + source $COMMON + eval_config `basename $0` +else + echo "error: file $COMMON found, check your `basename $0` installation" + exit 1 +fi + +APPEND="0" +if [[ ! -z "$3" && "$1" == "-a" ]]; then + ROOT="$3" + TEMPLATE="$BASE_CONF/$2.template" + APPEND="1" +elif [[ ! -z "$2" && "$1" == "-a" ]]; then + ROOT="/" + TEMPLATE="$BASE_CONF/$2.template" + APPEND="1" +elif [[ ! -z "$2" ]]; then + ROOT="$2" + TEMPLATE="$BASE_CONF/$1.template" +elif [[ ! -z "$1" ]]; then + TEMPLATE="$BASE_CONF/$1.template" + ROOT="/" +else + echo "usage: `basename $0` [-a] <template> [root-dir]" + echo -e "\t-a: append packages into <$BASE_CONF/template.template>" + exit 1 +fi + +if [ ! -d "$ROOT/var/log/packages" ]; then + echo $ROOT/var/log/packages: directory not found + exit 1 +elif [[ -f "$TEMPLATE" && "$APPEND" == "0" ]]; then + rm -f $TEMPLATE +fi + +for package in `ls -1 $ROOT/var/log/packages/`; do + pack=`package_name $package` + if [ -f $TEMPLATE ]; then + if ! `grep -v -e "^#" $TEMPLATE | cut -d : -f 1 | grep -q -e "^$pack\$"`; then + package_name $package >> $TEMPLATE + fi + else + package_name $package >> $TEMPLATE + fi +done + +# checks if each package from the template is installed +grep -v -e "^#" $TEMPLATE | cut -d : -f 1 | while read pack; do + + if [ ! -z "$pack" ]; then + unset found + for candidate in `ls $ROOT/var/log/packages/$pack* 2> /dev/null`; do + candidate="`package_name $candidate`" + if [ "$pack" == "$candidate" ]; then + found="1" + break + fi + done + if [ "$found" != "1" ]; then + # removes a non-installed package from the template + sed "/^$pack$/d" $TEMPLATE | sed "/^$pack $/d" | sed "/^$pack:*/d" > $TEMPLATE.tmp + cat $TEMPLATE.tmp > $TEMPLATE + rm -f $TEMPLATE.tmp + fi + fi + +done |