浏览代码

Added cert-chain-check and UpdateGOGS scripts

Fred Damstra 9 年之前
父节点
当前提交
2bf8ef2804
共有 2 个文件被更改,包括 106 次插入0 次删除
  1. 39 0
      UpdateGOGS.sh
  2. 67 0
      cert-chain-check.sh

+ 39 - 0
UpdateGOGS.sh

@@ -0,0 +1,39 @@
+#!/bin/bash
+# 
+# Updates the gogs server.
+GOGS_USER=fdamstra
+GOGS_PARENT_DIR=$GOPATH/src/github.com/gogits/
+GOGS_DIR=$GOGS_PARENT_DIR/gogs
+VERSION=$($GOGS_DIR/gogs -v | awk '{print $3}')
+
+if [ "`whoami`" != "$GOGS_USER" ]; then
+	echo "Script must be run as the GOGS user: $GOGS_USER."
+	exit -1
+fi
+
+echo UPGRADEGOGS: Making full backup of $GOGS_DIR into $GOGS_PARENT_DIR/gogs.$VERSION
+cp -r $GOGS_DIR $GOGS_PARENT_DIR/gogs.`$GOGS_DIR/gogs -v`
+echo UPGRADEGOGS: Backup completed.
+
+echo "UPGRADEGOGS: Updating source..."
+go get -u github.com/gogits/gogs
+echo "UPGRADEGOGS: Source updated."
+
+cd $GOGS_DIR
+echo UPGRADEGOGS: Renaming gogs executable to gogs.$VERSION
+mv gogs gogs.$VERSION
+echo UPGRADEGOGS: Done.
+
+echo UPGRADEGOGS: Building gogs.
+go build
+echo UPGRADEGOGS: Completed
+
+echo 'UPGRADEGOGS: Restarting supervisor (using sudo):'
+sudo service supervisor restart
+echo 'UPGRADEGOGS: Done'
+
+NEW_VERSION=$($GOGS_DIR/gogs -v | awk '{print $3}')
+echo ""
+echo "UPGRADEGOS COMPLETE: Old version: $VERSION; New Version: $NEW_VERSION"
+
+

+ 67 - 0
cert-chain-check.sh

@@ -0,0 +1,67 @@
+#!/bin/bash
+# This Works is placed under the terms of the Copyright Less License,
+# see file COPYRIGHT.CLL.  USE AT OWN RISK, ABSOLUTELY NO WARRANTY. 
+#
+# COPYRIGHT.CLL can be found at http://permalink.de/tino/cll
+# (CLL is CC0 as long as not covered by any Copyright)
+
+OOPS() { echo "OOPS: $*" >&2; exit 23; }
+
+[ -z "`pidof openssl`" ] || OOPS "openssl running, consider: killall openssl"
+
+PID=
+kick() { [ -n "$PID" ] && kill "$PID" && sleep .2; PID=; }
+trap 'kick' 0
+
+serve()
+{
+kick
+PID=
+openssl s_server -key "$KEY" -cert "$CRT" "$@" -www &
+PID=$!
+sleep .5    # give it time to startup
+}
+
+check()
+{
+while read -r line
+do
+    case "$line" in
+    'Verify return code: 0 (ok)')   return 0;;
+    'Verify return code: '*)    return 1;;
+#   *)  echo "::: $line :::";;
+    esac
+done < <(echo | openssl s_client -verify 8 -CApath /etc/ssl/certs/)
+OOPS "Something failed, verification output not found!"
+return 2
+}
+
+ARG="${1%.}"
+KEY="$ARG.key"
+CRT="$ARG.crt"
+BND="$ARG.bundle"
+
+for a in "$KEY" "$CRT" "$BND"
+do
+    [ -s "$a" ] || OOPS "missing $a"
+done
+
+serve
+check && echo "!!! =========> CA-Bundle is not needed! <========"
+echo
+serve -CAfile "$BND"
+check
+ret=$?
+kick
+
+echo
+case $ret in
+0)  echo "EVERYTHING OK"
+    echo "SSLCertificateKeyFile $KEY"
+    echo "SSLCertificateFile    $CRT"
+    echo "SSLCACertificateFile  $BND"
+    ;;
+*)  echo "!!! =========> something is wrong, verification failed! <======== ($ret)";;
+esac
+
+exit $ret