Skip to content

Commit

Permalink
add cron handling for osx-ssl-certs sub command
Browse files Browse the repository at this point in the history
  • Loading branch information
mpapis committed Apr 8, 2013
1 parent d11dbd5 commit 851916f
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 8 deletions.
44 changes: 39 additions & 5 deletions scripts/functions/osx-ssl-certs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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"
41 changes: 38 additions & 3 deletions scripts/osx-ssl-certs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 851916f

Please sign in to comment.