diff options
-rwxr-xr-x | src/simplaret | 101 |
1 files changed, 74 insertions, 27 deletions
diff --git a/src/simplaret b/src/simplaret index 19e1ad6..e08d9ba 100755 --- a/src/simplaret +++ b/src/simplaret @@ -281,7 +281,7 @@ function simplaret_search { local priority message pattern - if [ ! -z "$1" ]; then + if [ ! -z "$1" ] && ! echo $1 | grep -q -e "^-"; then pattern="$1" else pattern="-all" @@ -428,25 +428,80 @@ function simplaret_get { } +function simplaret_search_and_download_patch { + + # check if the patch was already downloaded + if echo $DOWNLOADED_PATCHES | grep -q " $candidate "; then + return + fi + + # search if its installed in the jail + installed_packs="`ls /$root/var/log/packages/$candidate* 2> /dev/null`" + if [ ! -z "$installed_packs" ]; then + + for installed in $installed_packs; do + if [[ "$candidate" == "`package_name $installed.tgz`" ]]; then + echo "package $candidate already installed in $root ($installed)" + package_installed="1" + break + fi + done + + # if the package is installed, download the patch + if [[ "$package_installed" != "1" ]]; then + simplaret_get $candidate + DOWNLOADED_PATCHES="$DOWNLOADED_PATCHES $candidate " # the ending space is important + fi + + fi + + unset package_installed + +} + function simplaret_get_jail_patches { # get patches from a jail # usage: simplaret_get_jail_patches <jail-folder> - # TODO: - # - pega a arquitetura e a versao da jaula - # - verifica os patches disponiveis para aquela arquitetura e versao - # - caso haja na jaula um pacote instalado cujo patch estah disponivel, baixa-o - - local root oldarch oldversion + local oldarch oldversion root="$1" + # save current arch and version oldarch="$ARCH" oldversion="$VERSION" VERSION="`cat $root/etc/slackware-version | awk '{ print $2 }' | sed -e 's/.0$//'`" ARCH="`cat $root/etc/slackware-version | awk '{ print $3 }' | sed -e 's/(//' -e 's/)//'`" + # in case there's something wrong with the jail, abort + if [ -z "$VERSION" ] && [ -z "$ARCH" ]; then + return + fi + + # erase the downloaded patches array + DOWNLOADED_PATCHES="" + + echo fetching patches for arch $ARCH and version $VERSION for jail $root + + # list all available patches in PATCHES repositories + for candidate in `simplaret_search -formatted | grep PATCHES`; do + simplaret_search_and_download_patch + done + + # list all available patches in ROOT repositories + for candidate in `simplaret_search patches -formatted | grep ROOT`; do + simplaret_search_and_download_patch + done + + # grab patches from every other places + if [ "$CONSIDER_ALL_PACKAGES_AS_PATCHES" == "1" ]; then + for candidate in `simplaret_search patches | grep -v PATCHES | grep -v ROOT`; do + simplaret_search_and_download_patch + done + fi + + # restore arch and version ARCH="$oldarch" VERSION="$oldversion" @@ -454,28 +509,19 @@ function simplaret_get_jail_patches { function simplaret_get_patches { - if [ ! -d "$PATCHES_DIR/$ARCH/$VERSION" ]; then - mkdir -p $PATCHES_DIR/$ARCH/$VERSION - fi + local jailpath - # TODO: new format - # chama o simplaret_get_jail_patches, primeiro para a instalacao principal - # e depois para as jaulas do /etc/simplepkg/jailist + # first get patches from the root system + simplaret_get_jail_patches / - echo fetching patches for arch $ARCH and version $VERSION... - - # grab new patches - for patch in `simplaret_search patches -basename_only`; 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 + # then get the needed patches for each installed jail + if [ -s "$JAIL_LIST" ]; then + for jailpath in `cat $JAIL_LIST`; do + if [ -d "/$jailpath/var/log/packages" ]; then + simplaret_get_jail_patches /$jailpath + fi + done + fi } @@ -559,6 +605,7 @@ case $1 in --get) simplaret_get $2 ;; --get-patches) simplaret_get_patches ;; --purge) shift ; simplaret_purge $* ;; + --upgrade) simplaret_get_patches ; jail-upgrade ;; *) simplaret_usage ;; esac |