]> git.nbdom.net Git - nb.git/commitdiff
openssh.sh
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 7 Sep 2016 10:17:23 +0000 (12:17 +0200)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 7 Sep 2016 10:17:23 +0000 (12:17 +0200)
etc/profile.d/functions
etc/profile.d/mac.sh
etc/profile.d/openssl.sh [new file with mode: 0644]

index d11f3e03db722700c7a6bfc54310bcf721256a4c..dfd70316e9fc2606cba80008d1084610d41a335e 100644 (file)
@@ -579,6 +579,27 @@ is_prompt() {
 
 url2nc() {
   local in="cat";
-  [ -n "$@" ] && in="echo $@";
-  $in | perl -MURI::Split -ne 'BEGIN{%port=("ssh"=>22,"https"=>443,"http"=>80);}; chomp($_); m,^\w+://, or $_="ssh://$_"; s,:([a-zAZ]),/$1,; @_=URI::Split::uri_split($_) or next; $_=$_[1]; s/^[^@]+@//; s/:/ / or $_.=" ".$port{$_[0]||"ssh"}; print "$_\n"'
+  [ -n "$*" ] && in="echo $*";
+  local IFS=$'\n'
+  eval $in | perl -MURI::Split -ne 'BEGIN{%port=("ssh"=>22,"https"=>443,"http"=>80);};
+    chomp($_);
+
+    if (/^([\.\w-_]+)\s+(\d+)$/) {
+      @_ = ($2,$1);
+    } else {
+      s,:([a-zAZ]),/$1,;
+      m,^\w+://, or $_="ssh://$_";
+      @_ = URI::Split::uri_split($_) or next;
+    }
+
+    $_=$_[1];
+    s/^[^@]+@//;
+
+    if ($_[0] =~ /^\d+$/) {
+      $_ .= " $_[0]";
+    } else {
+      s/:/ / or $_.=" ".$port{$_[0]||"ssh"};
+    }
+    print "$_\n"
+  '
 }
index 7231056ca5489f4b6204532672a75c1043f0385b..cd0db6200188311b291e5dddc451f9e4f249b73c 100644 (file)
@@ -51,3 +51,9 @@ mac_install_dmg() {
   sudo installer --verbose -pkg "${MOUNTDIR}/"*.pkg -target /
   sudo hdiutil detach "${MOUNTDIR}"
 }
+
+mac_keychain_add() {
+  local in="cat";
+  [ -n "$*" ] && in="echo $*";
+  eval $in | sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain
+}
diff --git a/etc/profile.d/openssl.sh b/etc/profile.d/openssl.sh
new file mode 100644 (file)
index 0000000..44e5fbc
--- /dev/null
@@ -0,0 +1,3 @@
+openssl_site2pem() {
+  openssl s_client -connect $(url2nc $@|sed 's/ /:/') -showcerts </dev/null 2>/dev/null | openssl x509 -outform PEM
+}