Skip to content

Instantly share code, notes, and snippets.

@qzwpq
Created September 22, 2015 17:38
Show Gist options
  • Save qzwpq/be59c521c552735e6903 to your computer and use it in GitHub Desktop.
Save qzwpq/be59c521c552735e6903 to your computer and use it in GitHub Desktop.
SoftEtherVPNをアップデートするやつ
#!/bin/bash
update() {
local VPN_TYPE="$1"
local PRODUCT_NAME="$2"
local FORCE="$3"
local INSTALL="$4"
local VPN_DIR="/usr/local/${VPN_TYPE}"
local VPN_BIN="${VPN_DIR}/${VPN_TYPE}"
local VPN_CMD="${VPN_DIR}/vpncmd"
local LOCAL_VERSION=$(: | ${VPN_CMD} | awk 'NR==3{print $2"-"$4}')
local ADDRESS="http://jp.softether-download.com/files/softether/"
local LATEST_BUILD=$(curl -s ${ADDRESS} | awk 'NR==3{l=split($0, arr, "<A[^>]*>"); print gensub(/(.+)-tree<\/A>.+/, "\\1", 1, arr[l-1])}')
local LATEST_VERSION=$(echo ${LATEST_BUILD} | awk '{print gensub(/v([0-9]+\.[0-9]+-[0-9]+).+/, "\\1", 1)}')
echo "Local version : ${LOCAL_VERSION}"
echo "Latest version : ${LATEST_VERSION}"
if [ "${FORCE}" = "false" -a "${LOCAL_VERSION}" = "${LATEST_VERSION}" ]; then
echo "Already up-to-date."
exit 0
fi
echo "Latest version is available."
echo "Retriving latest binary..."
local BIN_ADDRESS="${ADDRESS}${LATEST_BUILD}-tree/Linux/${PRODUCT_NAME}/64bit_-_Intel_x64_or_AMD64/softether-${VPN_TYPE}-${LATEST_BUILD}-linux-x64-64bit.tar.gz"
curl -s ${BIN_ADDRESS} | tar zxvf -
cd ${VPN_TYPE}
make
# *** YOU MUST READ AND AGREE THE LICENSE AGREEMENT!!! ***
# make i_read_and_agree_the_license_agreement
[ "${INSTALL}" = "false" ] && rm lang.config 2> /dev/null
cd ..
sudo ${VPN_BIN} stop > /dev/null
sudo cp -rf ${VPN_TYPE} $(dirname ${VPN_DIR})
rm -rf ${VPN_TYPE}
}
usage() {
echo "Usage: ./vpn_updater.sh TYPE [OPTION]"
echo "TYPE:"
echo " -c | --client Update VPN Client"
echo " -s | --server Update VPN Server"
echo " -b | --bridge Update VPN Bridge"
echo " -h | --help Display this help"
echo "OPTION:"
echo " -f | --force Force mode (update even if current version is latest)"
echo " -i | --install Install mode (do not remove lang.config)"
echo "EXAMPLE:"
echo "./vpn_updater.sh -c Update SoftEtherVPNClient"
}
case "$1" in
"-c" | "--client" )
VPN_TYPE="vpnclient"
PRODUCT_NAME="SoftEther_VPN_Client"
;;
"-s" | "--server" )
VPN_TYPE="vpnserver"
PRODUCT_NAME="SoftEther_VPN_Server"
;;
"-b" | "--bridge" )
VPN_TYPE="vpnbridge"
PRODUCT_NAME="SoftEther_VPN_Bridge"
;;
"-h" | "--help" | * )
usage
exit 0
esac
case "$2" in
"-f" | "--force" )
FORCE=true
INSTALL=false
;;
"-i" | "--install" )
FORCE=false
INSTALL=true
;;
* )
FORCE=false
INSTALL=false
esac
update ${VPN_TYPE} ${PRODUCT_NAME} ${FORCE} ${INSTALL}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment