-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from szymonos/dev
merge dev to main
- Loading branch information
Showing
4 changed files
with
217 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/usr/bin/env bash | ||
: ' | ||
sudo .assets/provision/install_fzf.sh >/dev/null | ||
' | ||
if [ $EUID -ne 0 ]; then | ||
printf '\e[31;1mRun the script as root.\e[0m\n' >&2 | ||
exit 1 | ||
fi | ||
|
||
# determine system id | ||
SYS_ID="$(sed -En '/^ID.*(alpine|arch|fedora|debian|ubuntu|opensuse).*/{s//\1/;p;q}' /etc/os-release)" | ||
# check if package installed already using package manager | ||
APP='fzf' | ||
case $SYS_ID in | ||
alpine) | ||
apk -e info $APP &>/dev/null && exit 0 || true | ||
;; | ||
arch) | ||
pacman -Qqe $APP &>/dev/null && exit 0 || true | ||
;; | ||
fedora | opensuse) | ||
rpm -q $APP &>/dev/null && exit 0 || true | ||
;; | ||
debian | ubuntu) | ||
dpkg -s $APP &>/dev/null && exit 0 || true | ||
;; | ||
esac | ||
|
||
# dotsource file with common functions | ||
. .assets/provision/source.sh | ||
|
||
# define variables | ||
REL=$1 | ||
retry_count=0 | ||
# get latest release if not provided as a parameter | ||
[ -z "$REL" ] && REL="$(get_gh_release_latest --owner 'junegunn' --repo 'fzf')" | ||
# return latest release | ||
echo $REL | ||
|
||
if type $APP &>/dev/null; then | ||
VER=$(rg --version | sed -En 's/.*\s([0-9\.]+)/\1/p') | ||
if [ "$REL" = "$VER" ]; then | ||
printf "\e[32m$APP v$VER is already latest\e[0m\n" >&2 | ||
exit 0 | ||
fi | ||
fi | ||
|
||
printf "\e[92minstalling \e[1m$APP\e[22m v$REL\e[0m\n" >&2 | ||
case $SYS_ID in | ||
alpine) | ||
apk add --no-cache $APP >&2 2>/dev/null | ||
;; | ||
arch) | ||
pacman -Sy --needed --noconfirm $APP >&2 2>/dev/null || binary=true | ||
;; | ||
fedora) | ||
dnf install -y $APP >&2 2>/dev/null || binary=true | ||
;; | ||
debian | ubuntu) | ||
export DEBIAN_FRONTEND=noninteractive | ||
apt-get update >&2 && apt-get install -y $APP >&2 2>/dev/null || binary=true | ||
;; | ||
opensuse) | ||
zypper in -y $APP >&2 2>/dev/null || binary=true | ||
;; | ||
*) | ||
binary=true | ||
;; | ||
esac | ||
|
||
if [ "$binary" = true ] && [ -n "$REL" ]; then | ||
echo 'Installing via script.' >&2 | ||
# create temporary dir for the downloaded binary | ||
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf | ||
~/.fzf/install | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env bash | ||
: ' | ||
sudo .assets/provision/install_kubectx.sh >/dev/null | ||
' | ||
if [ $EUID -ne 0 ]; then | ||
printf '\e[31;1mRun the script as root.\e[0m\n' >&2 | ||
exit 1 | ||
fi | ||
|
||
# dotsource file with common functions | ||
. .assets/provision/source.sh | ||
|
||
# define variables | ||
APP='kubectx' | ||
REL=$1 | ||
retry_count=0 | ||
# get latest release if not provided as a parameter | ||
if [ -z "$REL" ]; then | ||
if REL="$(get_gh_release_latest --owner 'ahmetb' --repo 'kubectx')"; then | ||
# return latest release | ||
echo $REL | ||
else | ||
exit 1 | ||
fi | ||
fi | ||
|
||
if type $APP &>/dev/null; then | ||
VER=$(kubectx version -s | sed -En 's/.*v([0-9\.]+)$/\1/p') | ||
if [ "$REL" = "$VER" ]; then | ||
printf "\e[32m$APP v$VER is already latest\e[0m\n" >&2 | ||
exit 0 | ||
fi | ||
fi | ||
|
||
printf "\e[92minstalling \e[1m$APP\e[22m v$REL\e[0m\n" >&2 | ||
# create temporary dir for the downloaded binary | ||
TMP_DIR=$(mktemp -dp "$PWD") | ||
# *install kubectx | ||
# calculate download uri | ||
URL="https://github.com/ahmetb/kubectx/releases/download/v${REL}/${APP}_v${REL}_linux_x86_64.tar.gz" | ||
# download and install file | ||
if download_file --uri $URL --target_dir $TMP_DIR; then | ||
tar -zxf "$TMP_DIR/$(basename $URL)" -C "$TMP_DIR" | ||
mkdir -p /opt/$APP | ||
install -m 0755 "$TMP_DIR/$APP" /opt/$APP/ | ||
[ -f /usr/bin/$APP ] || ln -s /opt/$APP/$APP /usr/bin/$APP | ||
fi | ||
# *install kubens | ||
# calculate download uri | ||
URL="https://github.com/ahmetb/kubectx/releases/download/v${REL}/kubens_v${REL}_linux_x86_64.tar.gz" | ||
# download and install file | ||
if download_file --uri $URL --target_dir $TMP_DIR; then | ||
tar -zxf "$TMP_DIR/$(basename $URL)" -C "$TMP_DIR" | ||
install -m 0755 "$TMP_DIR/kubens" /opt/$APP/ | ||
[ -f /usr/bin/kubens ] || ln -s /opt/$APP/kubens /usr/bin/kubens | ||
fi | ||
# remove temporary dir | ||
rm -fr "$TMP_DIR" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/usr/bin/pwsh -nop | ||
#Requires -PSEdition Core | ||
<# | ||
.SYNOPSIS | ||
Get root and intermediate certificates in PEM format from the certificate chain. | ||
.PARAMETER Uri | ||
Uri to get the certificate chain from. | ||
.EXAMPLE | ||
.assets/tools/cert_chain_pem.ps1 | ||
# :specify custom Uri | ||
$Uri = 'www.powershellgallery.com' | ||
.assets/tools/cert_chain_pem.ps1 $Uri | ||
#> | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Position = 0)] | ||
[ValidateNotNullOrEmpty()] | ||
[string]$Uri = 'www.google.com' | ||
) | ||
|
||
begin { | ||
$ErrorActionPreference = 'Stop' | ||
|
||
$tcpClient = [System.Net.Sockets.TcpClient]::new($Uri, 443) | ||
$chain = [System.Security.Cryptography.X509Certificates.X509Chain]::new() | ||
$sslStream = [System.Net.Security.SslStream]::new($tcpClient.GetStream()) | ||
|
||
# instantiate list for storing PEM encoded certificates | ||
$pems = [System.Collections.Generic.List[PSCustomObject]]::new() | ||
} | ||
|
||
process { | ||
try { | ||
$sslStream.AuthenticateAsClient($Uri) | ||
$certificate = $sslStream.RemoteCertificate | ||
} finally { | ||
$sslStream.Close() | ||
} | ||
# check certificate chain | ||
$isChainValid = $chain.Build($certificate) | ||
if ($isChainValid) { | ||
# build certificate chain | ||
$certificate = $chain.ChainElements.Certificate | ||
for ($i = 1; $i -lt $certificate.Count; $i++) { | ||
# convert certificate to base64 | ||
$base64 = [System.Convert]::ToBase64String($certificate[$i].RawData) | ||
# build PEM encoded X.509 certificate | ||
$builder = [System.Text.StringBuilder]::new() | ||
$builder.AppendLine('-----BEGIN CERTIFICATE-----') | Out-Null | ||
for ($j = 0; $j -lt $base64.Length; $j += 64) { | ||
$length = [System.Math]::Min(64, $base64.Length - $j) | ||
$builder.AppendLine($base64.Substring($j, $length)) | Out-Null | ||
} | ||
$builder.AppendLine('-----END CERTIFICATE-----') | Out-Null | ||
# create pem object with parsed common information and PEM encoded certificate | ||
$pem = @{ | ||
Issuer = $certificate[$i].Issuer | ||
Subject = $certificate[$i].Subject | ||
SerialNumber = $certificate[$i].SerialNumber | ||
Thumbprint = $certificate[$i].Thumbprint | ||
PEM = $builder.ToString().Replace("`r`n", "`n") | ||
} | ||
# check if CN available, otherwise add OU as label | ||
$cn = [regex]::Match($pem.Subject, '(?<=CN=)(.)+?(?=,|$)').Value.Trim().Trim('"') | ||
if ($cn) { | ||
$pem.Label = $cn | ||
} else { | ||
$pem.Label = [regex]::Match($pem.Subject, '(?<=OU=)(.)+?(?=,|$)').Value.Trim().Trim('"') | ||
} | ||
$pems.Add([PSCustomObject]$pem) | ||
} | ||
} else { | ||
Write-Warning 'SSL certificate chain validation failed.' | ||
} | ||
} | ||
|
||
end { | ||
return $pems | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters