Skip to content

Instantly share code, notes, and snippets.

@tyano
Created December 3, 2018 10:06
Show Gist options
  • Save tyano/bdbe7c0f1c92e212d1122fc1ed8e1d11 to your computer and use it in GitHub Desktop.
Save tyano/bdbe7c0f1c92e212d1122fc1ed8e1d11 to your computer and use it in GitHub Desktop.
sdkmanでインストールしたjdkに証明書をインストールするスクリプト
#!/usr/bin/env bash
function check_error() {
ret=$?
msg=$1
code=$2
if [[ $RET -ne 0 ]]
then
echo "error: $1" >&2
exit $code
fi
}
SDK_VERSION=${1:-current}
cd ~/Downloads
curl --fail -O "https://www.amazontrust.com/repository/AmazonRootCA1.cer"
check_error "AmazonRootCA1" 1
curl --fail -O "https://www.amazontrust.com/repository/AmazonRootCA2.cer"
check_error "AmazonRootCA2" 2
curl --fail -O "https://www.amazontrust.com/repository/AmazonRootCA3.cer"
check_error "AmazonRootCA3" 3
curl --fail -O "https://www.amazontrust.com/repository/AmazonRootCA4.cer"
check_error "AmazonRootCA4" 4
curl --fail -O "https://secure.globalsign.net/cacert/Root-R1.crt"
check_error "globalSign Root-R1" 5
curl --fail -O "https://secure.globalsign.net/cacert/Root-R3.crt"
check_error "globalSign Root-R3" 6
cd "${HOME}/.sdkman/candidates/java/${SDK_VERSION}/lib/security"
if [[ ! -f cacerts.org ]]
then
cp -p cacerts cacerts.org
check_error "Could not create a backup file for cacerts." 7
fi
keytool -importcert -cacerts -file ~/Downloads/AmazonRootCA1.cer -alias amazonrootca1
check_error "Could not install AmazonRootCA1.cer" 8
keytool -importcert -cacerts -file ~/Downloads/AmazonRootCA2.cer -alias amazonrootca2
check_error "Could not install AmazonRootCA1.cer" 9
keytool -importcert -cacerts -file ~/Downloads/AmazonRootCA3.cer -alias amazonrootca3
check_error "Could not install AmazonRootCA1.cer" 10
keytool -importcert -cacerts -file ~/Downloads/AmazonRootCA4.cer -alias amazonrootca4
check_error "Could not install AmazonRootCA1.cer" 11
keytool -importcert -cacerts -file ~/Downloads/Root-R1.crt -alias globalsignrootr1
check_error "Could not install GlobalSign Root-R1.crt" 12
keytool -importcert -cacerts -file ~/Downloads/Root-R3.crt -alias globalsignrootr3
check_error "Could not install GlobalSign Root-R3.crt" 13
echo "Finished."
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment