From 851916ff286ad2611df7a22f14db47ad04abd717 Mon Sep 17 00:00:00 2001 From: Michal Papis Date: Mon, 8 Apr 2013 08:17:49 +0200 Subject: [PATCH] add cron handling for osx-ssl-certs sub command --- scripts/functions/osx-ssl-certs | 44 +++++++++++++++++++++++++++++---- scripts/osx-ssl-certs | 41 +++++++++++++++++++++++++++--- 2 files changed, 77 insertions(+), 8 deletions(-) diff --git a/scripts/functions/osx-ssl-certs b/scripts/functions/osx-ssl-certs index 20ce02473d..5615c8ea0a 100755 --- a/scripts/functions/osx-ssl-certs +++ b/scripts/functions/osx-ssl-certs @@ -46,16 +46,30 @@ __rvm_osx_ssl_certs_update_for_path() cert_file="$( __rvm_osx_ssl_certs_file_for_ruby )" ssl_dir="${cert_file%/*}" - printf "%b" "Updating certificates for ${cert_file}: " + if (( ${rvm_silent_flag:-0} == 0 )) + then printf "%b" "Updating certificates for ${cert_file}: " + fi if requirements_osx_update_openssl_cert_old then - if requirements_osx_update_openssl_cert_run - then printf "%b" "Updated.\n" - else printf "%b" "Failed.\n" + if + requirements_osx_update_openssl_cert_run + then + if (( ${rvm_silent_flag:-0} == 0 )) + then printf "%b" "Updated.\n" + fi + else + typeset result=$? + if (( ${rvm_silent_flag:-0} == 0 )) + then printf "%b" "Failed.\n" + else printf "%b" "Updating certificates for ${cert_file}: Failed.\n" + fi + return $result fi else - printf "%b" "Already are up to date.\n" + if (( ${rvm_silent_flag:-0} == 0 )) + then printf "%b" "Already are up to date.\n" + fi fi } @@ -81,3 +95,23 @@ __rvm_osx_ssl_certs_file_from_openssl() { "${1:-openssl}" version -d | awk -F'"' '{print $2"/cert.pem"}' } + +__rvm_cron_find() +{ + EDITOR=\cat crontab -e 2>/dev/null | GREP_OPTIONS="" \grep "$1" >/dev/null || return $? +} + +__rvm_cron_uninstall() +{ + EDITOR=\cat crontab -e 2>/dev/null | GREP_OPTIONS="" \grep -v "$1" | crontab - +} + +__rvm_cron_install() +{ + { + EDITOR=\cat crontab -e 2>/dev/null + echo "@daily $1" + } | crontab - +} + +export RVM_OSX_SSL_UPDATER="$rvm_path/bin/rvm --silent osx-ssl-certs update all" diff --git a/scripts/osx-ssl-certs b/scripts/osx-ssl-certs index d86f17e016..231699d7e5 100755 --- a/scripts/osx-ssl-certs +++ b/scripts/osx-ssl-certs @@ -62,17 +62,52 @@ __rvm_osx_ssl_certs_update() __rvm_osx_ssl_certs_cron_status() { - rvm_fail "NYI" + if __rvm_cron_find "$RVM_OSX_SSL_UPDATER" + then rvm_log "Automatic certs updating installed." + else rvm_warn "Automatic certs updating not installed." + fi } __rvm_osx_ssl_certs_cron_install() { - rvm_fail "NYI" + if + __rvm_cron_find "$RVM_OSX_SSL_UPDATER" + then + __rvm_cron_uninstall "$RVM_OSX_SSL_UPDATER" || + { + typeset result=$? + rvm_error "Automatic certs updating failed uninstalling." + return $result + } + fi + if + __rvm_cron_install "$RVM_OSX_SSL_UPDATER" + then + rvm_log "Automatic certs updating installed." + else + typeset result=$? + rvm_error "Automatic certs updating failed installing." + return $result + fi } __rvm_osx_ssl_certs_cron_uninstall() { - rvm_fail "NYI" + if + __rvm_cron_find "$RVM_OSX_SSL_UPDATER" + then + if + __rvm_cron_uninstall "$RVM_OSX_SSL_UPDATER" + then + rvm_log "Automatic certs updating uninstalled." + else + typeset result=$? + rvm_error "Automatic certs updating failed uninstalling." + return $result + fi + else + rvm_log "Automatic certs updating already uninstalled." + fi } __rvm_osx_ssl_certs_cron()