Compare commits
90 Commits
54647e5c19
...
master
Author | SHA1 | Date | |
---|---|---|---|
67fabf0ce1 | |||
fe56c50bfb | |||
eb14aa46ff | |||
c59d1b374d | |||
1a99d2e2a1 | |||
1d03f7be64 | |||
994e44d8f1 | |||
f016a452cd | |||
c17b9a0e42 | |||
a91d5d6011 | |||
3a0902fe8e | |||
9baae5bccc | |||
7b837fdba7 | |||
283b7538e6 | |||
14ae6e5dad | |||
87608f9bfb | |||
5903932328 | |||
96193196cc | |||
0186421fc6 | |||
714feda225 | |||
3d834933e7 | |||
dd72a873ab | |||
81cd3a1c1c | |||
b52f1d4486 | |||
42239ef54d | |||
256a79e427 | |||
b36f98e5e9 | |||
2f33daaaa7 | |||
4e9ae9109e | |||
0071b7407d | |||
b014dd1990 | |||
13e0deb5f5 | |||
b5b1b88763 | |||
90414af2dc | |||
e1b05fbc51 | |||
a614d63d1c | |||
ca14cb1988 | |||
e36265403e | |||
0ef3f8d8d6 | |||
706a917dbf | |||
7f950148e0 | |||
a54f68ded0 | |||
29be307377 | |||
02c84ef45f | |||
399372294c | |||
0b0237ede5 | |||
2df1590a6d | |||
18d3ed8890 | |||
25bf1a9ebc | |||
1852b1a119 | |||
3618a34c41 | |||
a6cb4ae626 | |||
fb02109d68 | |||
b58142a45f | |||
26dac6550c | |||
6b9afb0ed0 | |||
7765af850a | |||
cb76cbd190 | |||
7a5c84f5c0 | |||
ecaa7e3a73 | |||
a2478d0a7a | |||
71cf24869a | |||
d1b32a0296 | |||
aff9e6d985 | |||
7b7c540e12 | |||
dc0bdf6755 | |||
c5359ed8f5 | |||
3d04f2f24c | |||
cc1cc6e39f | |||
6619193dc6 | |||
963770b974 | |||
d54100edf8 | |||
28aed09fd1 | |||
824ca7168c | |||
0da7c1ade1 | |||
b2d3908d6f | |||
91ae087bd4 | |||
ee152b0562 | |||
56b6f58f4e | |||
fb3c902d9a | |||
9f0df0dbdf | |||
3daa8a84dc | |||
a1ff2b40d7 | |||
0b8ea6b7bf | |||
2c5ddd1280 | |||
219aac45e5 | |||
8808aa7b93 | |||
d3901ba519 | |||
d99860148b | |||
9a740b9873 |
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023-2024 Warén Group
|
||||
Copyright (c) 2023-2025 Warén Group
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
16
README.md
16
README.md
@ -1 +1,15 @@
|
||||
# Warén Group - WX
|
||||
# Warén Group - Warén CLI (wx)
|
||||
|
||||
## Install
|
||||
```
|
||||
mkdir $HOME/bin &> /dev/null
|
||||
curl https://git.waren.io/warengroup/wx/raw/branch/master/wx -o $HOME/bin/wx &> /dev/null
|
||||
chmod +x $HOME/bin/wx &> /dev/null
|
||||
export PATH=$HOME/bin:$PATH
|
||||
```
|
||||
|
||||
## Schedule
|
||||
```
|
||||
# Warén CLI
|
||||
*/30 * * * * $HOME/bin/wx auto
|
||||
```
|
||||
|
10
config.yml
10
config.yml
@ -1,10 +0,0 @@
|
||||
---
|
||||
warengroup:
|
||||
domain: waren.io
|
||||
folder: warengroup
|
||||
cwinfo:
|
||||
domain: cwinfo.net
|
||||
folder: cwinfo
|
||||
cwchristerw:
|
||||
domain: christerwaren.fi
|
||||
folder: cwchristerw
|
@ -6,28 +6,32 @@ $base = file_get_contents(__DIR__."/src/base.sh");
|
||||
$dirs = [
|
||||
__DIR__.'/src/commands/*.sh',
|
||||
__DIR__.'/src/commands/*/*.sh',
|
||||
__DIR__.'/src/commands/*/*/*.sh'
|
||||
__DIR__.'/src/commands/*/*/*.sh',
|
||||
__DIR__.'/src/functions/*.sh'
|
||||
];
|
||||
|
||||
$codes = [];
|
||||
|
||||
foreach($dirs as $dir){
|
||||
foreach(glob($dir) as $file){
|
||||
$codes[$file] = file_get_contents($file);
|
||||
if(str_contains($dir, "functions")){
|
||||
$codes['functions'][$file] = file_get_contents($file);
|
||||
}
|
||||
if(str_contains($dir, "commands")){
|
||||
$codes['commands'][$file] = file_get_contents($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$code = str_replace("{{ COMMANDS }}", implode("\n", $codes), $base);
|
||||
$code = str_replace("{{ FUNCTIONS }}", implode("\n", $codes['functions']), $base);
|
||||
$code = str_replace("{{ COMMANDS }}", implode("\n", $codes['commands']), $code);
|
||||
|
||||
try {
|
||||
$file = __DIR__.'/wx';
|
||||
$file = __DIR__.'/wx.tmp';
|
||||
$file = fopen($file, "w");
|
||||
fwrite($file, $code);
|
||||
fclose($file);
|
||||
|
||||
echo "Status: Successful";
|
||||
} catch (\Error $e) {
|
||||
echo "Status: Failed";
|
||||
}
|
||||
|
||||
?>
|
||||
|
13
maintainer.sh
Executable file
13
maintainer.sh
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ ! "$BASH_VERSION" ] ; then
|
||||
bash $0 $1 $2 $3 $4 $5 $6 $7 $8 $9
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -f "./wx" ]] && [[ -d "./src" ]]
|
||||
then
|
||||
podman run -it --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp docker.io/library/php:8-cli php generator.php &> /dev/null
|
||||
mv wx.tmp wx &> /dev/null
|
||||
chmod +x wx &> /dev/null
|
||||
fi
|
60
src/base.sh
60
src/base.sh
@ -5,49 +5,27 @@ if [ ! "$BASH_VERSION" ] ; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
warencli-syntax-line-douple() {
|
||||
echo -n "
|
||||
==============================
|
||||
"
|
||||
}
|
||||
wxRed=$(tput setaf 196)
|
||||
wxGreen=$(tput setaf 46)
|
||||
wxYellow=$(tput setaf 226)
|
||||
wxBlue=$(tput setaf 21)
|
||||
wxPurple=$(tput setaf 165)
|
||||
wxTurquoise=$(tput setaf 14)
|
||||
wxPink=$(tput setaf 198)
|
||||
wxOrange=$(tput setaf 202)
|
||||
wxUnderline=$(tput smul)
|
||||
wxBold=$(tput bold)
|
||||
wxNormal=$(tput sgr0)
|
||||
|
||||
warencli-syntax-line-single() {
|
||||
echo -n "
|
||||
------------------------------
|
||||
"
|
||||
}
|
||||
|
||||
warencli-start() {
|
||||
warencli-syntax-line-douple
|
||||
echo -n "Warén CLI "
|
||||
warencli-syntax-line-douple
|
||||
}
|
||||
|
||||
warencli-stop () {
|
||||
echo " "
|
||||
exit 1
|
||||
}
|
||||
|
||||
warencli-update() {
|
||||
if [[ -d "./src" ]]; then
|
||||
echo ">>> Building... <<<"
|
||||
podman run -it --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp docker.io/library/php:8-cli php generator.php
|
||||
else
|
||||
echo ">>> Updating... <<<"
|
||||
sudo curl https://git.waren.io/warengroup/wx/raw/branch/master/wx -o /opt/wx &> /dev/null
|
||||
if [[ -d "/usr/bin" ]]; then
|
||||
sudo ln -sf /opt/wx /usr/bin/wx &> /dev/null
|
||||
fi
|
||||
sudo chmod +x /usr/bin/wx &> /dev/null
|
||||
fi
|
||||
}
|
||||
declare -Ax config
|
||||
|
||||
{{ FUNCTIONS }}
|
||||
{{ COMMANDS }}
|
||||
|
||||
COMMAND=$1
|
||||
|
||||
warencli-start
|
||||
if [[ ! -z $1 ]]; then
|
||||
warencli-$1 $2 $3 $4 $5 $6 $7 $8 $9
|
||||
if [[ ! -z $1 ]] && [[ $(type -t wx-$1) == function ]]
|
||||
then
|
||||
wx-$1 $2 $3 $4 $5 $6 $7 $8 $9
|
||||
else
|
||||
wx-welcome
|
||||
fi
|
||||
warencli-stop
|
||||
wx-stop
|
||||
|
@ -1,3 +1,164 @@
|
||||
warencli-login() {
|
||||
echo ">>> Authentication: Login";
|
||||
wx-login(){
|
||||
if [[ ! -z $1 ]]
|
||||
then
|
||||
ORG=$1
|
||||
jq '.org = "'$ORG'"' $HOME/.warengroup/config.json 1> $HOME/.warengroup/config.json.tmp
|
||||
mv $HOME/.warengroup/config.json.tmp $HOME/.warengroup/config.json &> /dev/null
|
||||
elif [[ $(hostname -d) = *"devices.waren.io" ]]
|
||||
then
|
||||
ORG=warengroup
|
||||
elif [[ $(hostname -d) = *"devices.cwinfo.net" ]]
|
||||
then
|
||||
ORG=cwinfo
|
||||
elif [[ $(hostname -d) = *"devices.christerwaren.fi" ]]
|
||||
then
|
||||
ORG=cwchristerw
|
||||
elif [[ $USER != "root" && $USER != "local" && -f "$HOME/.warengroup/config.json" && $(cat $HOME/.warengroup/config.json | jq -r .org) != "null" ]]
|
||||
then
|
||||
ORG=$(cat $HOME/.warengroup/config.json | jq -r .org)
|
||||
else
|
||||
wx-header "Login"
|
||||
echo "Status: Organization Required"
|
||||
wx-stop
|
||||
fi
|
||||
|
||||
if [[ $ORG == "warengroup" ]]
|
||||
then
|
||||
DOMAIN=waren.io
|
||||
elif [[ $ORG == "cwinfo" ]]
|
||||
then
|
||||
DOMAIN=cwinfo.net
|
||||
elif [[ $ORG == "cwchristerw" ]]
|
||||
then
|
||||
DOMAIN=christerwaren.fi
|
||||
else
|
||||
wx-header "Login"
|
||||
echo "Status: Organization Unsupported"
|
||||
wx-stop
|
||||
fi
|
||||
|
||||
FOLDER=$ORG
|
||||
DEVICE_DOMAIN="devices.$DOMAIN"
|
||||
IDM_DOMAIN="idm.waren.io"
|
||||
VAULT_DOMAIN="vault.cwinfo.net"
|
||||
|
||||
if [[ -z $USER || $USER == "root" || $USER == "local" ]]
|
||||
then
|
||||
if [[ -z $SUDO_USER ]]
|
||||
then
|
||||
if [[ -z LOGNAME ]]
|
||||
then
|
||||
wx-header "Login"
|
||||
echo "Status: Username Required"
|
||||
wx-stop
|
||||
else
|
||||
USERNAME=$LOGNAME
|
||||
fi
|
||||
else
|
||||
USERNAME=$SUDO_USER
|
||||
fi
|
||||
else
|
||||
USERNAME=$USER
|
||||
fi
|
||||
|
||||
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/sys/health)
|
||||
if [[ $VAULT_STATUS -eq 200 ]]
|
||||
then
|
||||
|
||||
if [[ $USER != "root" && $USER != "local" && -f "$HOME/.warengroup/config.json" ]]
|
||||
then
|
||||
if [[ $(cat $HOME/.warengroup/config.json | jq -r .login.$ORG.username) != "null" ]]
|
||||
then
|
||||
USERNAME="$(cat $HOME/.warengroup/config.json | jq -r .login.$ORG.username)"
|
||||
fi
|
||||
TOKEN="$(cat $HOME/.warengroup/config.json | jq -r .login.$ORG.token)"
|
||||
fi
|
||||
|
||||
VAULT_LOGIN=$(curl https://$VAULT_DOMAIN/v1/auth/token/renew -X POST --header "X-Vault-Token: $TOKEN" -d '{ "token": "'$TOKEN'" }' -s | jq -r '.auth.client_token')
|
||||
if [[ ! -z $VAULT_LOGIN && ${#VAULT_LOGIN} == 95 ]]
|
||||
then
|
||||
config["login",${ORG}]=$VAULT_LOGIN
|
||||
if [[ $USER != "root" && $USER != "local" ]]
|
||||
then
|
||||
jq '.login.'$ORG'.token = "'$VAULT_LOGIN'"' $HOME/.warengroup/config.json 1> $HOME/.warengroup/config.json.tmp
|
||||
mv $HOME/.warengroup/config.json.tmp $HOME/.warengroup/config.json &> /dev/null
|
||||
fi
|
||||
else
|
||||
IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN)
|
||||
if [[ $IDM_STATUS -eq 301 ]]
|
||||
then
|
||||
wx-header "Login"
|
||||
echo $wxBold$ORG$wxNormal
|
||||
|
||||
if [[ -z $USERNAME || $USERNAME == "root" || $USERNAME == "local" || $USERNAME == "nobody" ]]
|
||||
then
|
||||
echo -n "Username: "
|
||||
read USERNAME
|
||||
else
|
||||
echo "Username: $USERNAME"
|
||||
fi
|
||||
|
||||
jq '.login.'$ORG'.username = "'$USERNAME'"' $HOME/.warengroup/config.json 1> $HOME/.warengroup/config.json.tmp
|
||||
mv $HOME/.warengroup/config.json.tmp $HOME/.warengroup/config.json &> /dev/null
|
||||
|
||||
echo -n "Password: "
|
||||
read -s PASSWORD
|
||||
echo "****************"
|
||||
|
||||
if [[ -z $USERNAME || -z $PASSWORD ]]
|
||||
then
|
||||
echo "Status: Username & Password Required"
|
||||
wx-stop
|
||||
else
|
||||
VAULT_LOGIN=$(curl https://$VAULT_DOMAIN/v1/auth/ldap/login/$USERNAME -X POST -d '{ "password": "'$PASSWORD'" }' -s | jq -r '.auth.client_token')
|
||||
if [[ -z $VAULT_LOGIN || ${#VAULT_LOGIN} -lt 95 || ${#VAULT_LOGIN} -gt 95 ]]
|
||||
then
|
||||
echo "Status: Login Failed"
|
||||
wx-stop
|
||||
fi
|
||||
|
||||
config["login",${ORG}]=$VAULT_LOGIN
|
||||
|
||||
if [[ $USER != "root" && $USER != "local" ]]
|
||||
then
|
||||
jq '.login.'$ORG'.token = "'$VAULT_LOGIN'"' $HOME/.warengroup/config.json &> $HOME/.warengroup/config.json.tmp
|
||||
mv $HOME/.warengroup/config.json.tmp $HOME/.warengroup/config.json &> /dev/null
|
||||
fi
|
||||
fi
|
||||
else
|
||||
wx-header "Login"
|
||||
echo $wxBold$ORG$wxNormal
|
||||
|
||||
echo -n "Token: "
|
||||
read -s TOKEN
|
||||
echo "****************"
|
||||
|
||||
if [[ -z $TOKEN || ${#TOKEN} -lt 95 || ${#TOKEN} -gt 95 ]]
|
||||
then
|
||||
echo "Status: Vault Token Required"
|
||||
wx-stop
|
||||
fi
|
||||
|
||||
VAULT_LOGIN=$(curl https://$VAULT_DOMAIN/v1/auth/token/renew -X POST --header "X-Vault-Token: $TOKEN" -d '{ "token": "'$TOKEN'" }' -s | jq -r '.auth.client_token')
|
||||
if [[ -z $VAULT_LOGIN || ${#VAULT_LOGIN} -lt 95 || ${#VAULT_LOGIN} -gt 95 ]]
|
||||
then
|
||||
echo "Status: Login Failed"
|
||||
wx-stop
|
||||
fi
|
||||
|
||||
config["login",${ORG}]=$VAULT_LOGIN
|
||||
|
||||
if [[ $USER != "root" && $USER != "local" ]]
|
||||
then
|
||||
jq '.login.'$ORG'.token = "'$VAULT_LOGIN'"' $HOME/.warengroup/config.json &> $HOME/.warengroup/config.json.tmp
|
||||
mv $HOME/.warengroup/config.json.tmp $HOME/.warengroup/config.json &> /dev/null
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
else
|
||||
wx-header "Login"
|
||||
echo $wxBold$ORG$wxNormal
|
||||
echo "Status: Vault Offline"
|
||||
wx-stop
|
||||
fi
|
||||
}
|
||||
|
@ -1,3 +1,13 @@
|
||||
warencli-logout() {
|
||||
echo ">>> Authentication: Logout";
|
||||
wx-logout(){
|
||||
wx-header "Logout"
|
||||
if [[ $USER != "root" && $USER != "local" && -f "$HOME/.warengroup/config.json" ]]
|
||||
then
|
||||
VAULT_LOGIN=$(cat $HOME/.warengroup/config.json | jq -r .login)
|
||||
if [[ $VAULT_LOGIN != null && $VAULT_LOGIN != "{}" ]]
|
||||
then
|
||||
wx-clean &> /dev/null
|
||||
jq '.login = {}' $HOME/.warengroup/config.json &> $HOME/.warengroup/config.json.tmp
|
||||
mv $HOME/.warengroup/config.json.tmp $HOME/.warengroup/config.json &> /dev/null
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
@ -1,22 +1,40 @@
|
||||
warencli-help() {
|
||||
echo "
|
||||
wx-help(){
|
||||
|
||||
wx-header "Help"
|
||||
|
||||
echo -n "
|
||||
Usage: $0 COMMAND [OPTIONS]
|
||||
|
||||
Common Commands:
|
||||
init Init
|
||||
help Help
|
||||
ssh SSH
|
||||
config Config
|
||||
sign Certificates
|
||||
edit Edit
|
||||
save Save
|
||||
sync Sync
|
||||
clean Clean
|
||||
keys Keys
|
||||
generate Generate
|
||||
sign Sign
|
||||
retrieve Retrieve
|
||||
save Save
|
||||
sync Sync
|
||||
delete Delete
|
||||
clean Clean
|
||||
|
||||
Authentication Commands:
|
||||
login Login
|
||||
logout Logout
|
||||
|
||||
Management Commands:
|
||||
auto Auto
|
||||
clean Clean
|
||||
settings Settings
|
||||
|
||||
Maintenance Commands:
|
||||
install Install
|
||||
update Update
|
||||
";
|
||||
}
|
||||
|
||||
}
|
||||
|
75
src/commands/infra.sh
Normal file
75
src/commands/infra.sh
Normal file
@ -0,0 +1,75 @@
|
||||
wx-infra(){
|
||||
wx-login
|
||||
wx-auto &> /dev/null
|
||||
|
||||
wx-header "Infra"
|
||||
wx-restricted
|
||||
|
||||
case $USERNAME in
|
||||
cwchristerw)
|
||||
if [[ -d "$HOME/Desktop/Work in Progress/Programming/warengroup/infra" ]]
|
||||
then
|
||||
INFRA_PATH="$HOME/Desktop/Work in Progress/Programming/warengroup/infra"
|
||||
else
|
||||
if [[ -d "$HOME/.warengroup/infra" ]]
|
||||
then
|
||||
INFRA_PATH="$HOME/.warengroup/infra"
|
||||
else
|
||||
INFRA_PATH="$HOME/.warengroup/infra"
|
||||
mkdir -p "$INFRA_PATH" &> /dev/null
|
||||
git clone ssh://git@git.waren.io:2222/warengroup-private/infra.git --config core.sshCommand="ssh -i $HOME/.ssh/keys/warengroup-legacy -o ProxyJump=none" "$INFRA_PATH" &> /dev/null
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ ! -f "$INFRA_PATH/vault/cwchristerw" || ! -f "$INFRA_PATH/vault/warengroup" ]]
|
||||
then
|
||||
mkdir -p "$INFRA_PATH/vault" &> /dev/null
|
||||
|
||||
curl \
|
||||
-H "X-Vault-Token: ${config["login",$ORG]}" \
|
||||
-X GET \
|
||||
https://$VAULT_DOMAIN/v1/cli/data/cwchristerw/settings/infra -s | jq -r '.data.data.cwchristerw' > "$INFRA_PATH/vault/cwchristerw"
|
||||
|
||||
curl \
|
||||
-H "X-Vault-Token: ${config["login",$ORG]}" \
|
||||
-X GET \
|
||||
https://$VAULT_DOMAIN/v1/cli/data/cwchristerw/settings/infra -s | jq -r '.data.data.warengroup' > "$INFRA_PATH/vault/warengroup"
|
||||
fi
|
||||
|
||||
if [[ -z $1 ]]
|
||||
then
|
||||
echo "Tag Required"
|
||||
else
|
||||
if [[ $1 == "init" ]]
|
||||
then
|
||||
if [[ -z $2 ]]
|
||||
then
|
||||
2=init
|
||||
fi
|
||||
|
||||
cd "$INFRA_PATH"
|
||||
git pull &> /dev/null
|
||||
ansible-galaxy collection install -r requirements.yml --upgrade &> /dev/null
|
||||
ansible-playbook --vault-id warengroup@vault/warengroup --vault-id cwchristerw@vault/cwchristerw playbooks/init.yml -t $2 $3 $4 $5 $6 $7 $8 $9
|
||||
cd "$OLDPWD"
|
||||
elif [[ $1 == "manager" ]]
|
||||
then
|
||||
cd "$INFRA_PATH"
|
||||
git pull &> /dev/null
|
||||
ansible-galaxy collection install -r requirements.yml --upgrade &> /dev/null
|
||||
ansible-playbook --vault-id warengroup@vault/warengroup --vault-id cwchristerw@vault/cwchristerw manager.yml $2 $3 $4 $5 $6 $7 $8 $9
|
||||
cd "$OLDPWD"
|
||||
else
|
||||
cd "$INFRA_PATH"
|
||||
git pull &> /dev/null
|
||||
ansible-galaxy collection install -r requirements.yml --upgrade &> /dev/null
|
||||
ansible-playbook --vault-id warengroup@vault/warengroup --vault-id cwchristerw@vault/cwchristerw playbooks.yml -t $1 $2 $3 $4 $5 $6 $7 $8 $9
|
||||
cd "$OLDPWD"
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "User Unsupported"
|
||||
;;
|
||||
esac
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
warencli-install() {
|
||||
echo ">>> Install";
|
||||
}
|
19
src/commands/maintenance/install.sh
Normal file
19
src/commands/maintenance/install.sh
Normal file
@ -0,0 +1,19 @@
|
||||
wx-install(){
|
||||
if [[ -z $1 ]]
|
||||
then
|
||||
wx-header "Install"
|
||||
fi
|
||||
|
||||
wx-restricted
|
||||
|
||||
if [[ -f "./wx" ]] && [[ -d "./src" ]]
|
||||
then
|
||||
podman run -it --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp docker.io/library/php:8-cli php generator.php &> /dev/null
|
||||
mv wx.tmp wx &> /dev/null
|
||||
chmod +x wx &> /dev/null
|
||||
fi
|
||||
|
||||
mkdir $HOME/bin &> /dev/null
|
||||
curl https://git.waren.io/warengroup/wx/raw/branch/master/wx -o $HOME/bin/wx &> /dev/null
|
||||
chmod +x $HOME/bin/wx &> /dev/null
|
||||
}
|
8
src/commands/maintenance/uninstall.sh
Normal file
8
src/commands/maintenance/uninstall.sh
Normal file
@ -0,0 +1,8 @@
|
||||
wx-uninstall(){
|
||||
wx-header "Uninstall"
|
||||
wx-logout
|
||||
if [[ ! -d "$HOME/.warengroup" ]]
|
||||
then
|
||||
rm "$HOME/.warengroup" -rf
|
||||
fi
|
||||
}
|
4
src/commands/maintenance/update.sh
Normal file
4
src/commands/maintenance/update.sh
Normal file
@ -0,0 +1,4 @@
|
||||
wx-update(){
|
||||
wx-header "Update"
|
||||
wx-install --update
|
||||
}
|
8
src/commands/management/auto.sh
Normal file
8
src/commands/management/auto.sh
Normal file
@ -0,0 +1,8 @@
|
||||
wx-auto(){
|
||||
wx-login
|
||||
wx-header "Auto"
|
||||
|
||||
wx-ssh-config-sync
|
||||
wx-ssh-keys-sync
|
||||
wx-ssh-keys-sign
|
||||
}
|
6
src/commands/management/clean.sh
Normal file
6
src/commands/management/clean.sh
Normal file
@ -0,0 +1,6 @@
|
||||
wx-clean(){
|
||||
wx-login
|
||||
wx-header "Clean"
|
||||
wx-ssh-config-clean
|
||||
wx-ssh-keys-clean
|
||||
}
|
4
src/commands/management/settings.sh
Normal file
4
src/commands/management/settings.sh
Normal file
@ -0,0 +1,4 @@
|
||||
wx-settings(){
|
||||
wx-login
|
||||
wx-header "Settings"
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
warencli-settings() {
|
||||
echo ">>> Settings";
|
||||
}
|
@ -1,3 +1,16 @@
|
||||
warencli-ssh() {
|
||||
echo ">>> SSH";
|
||||
wx-ssh(){
|
||||
wx-login
|
||||
|
||||
case $1 in
|
||||
keys)
|
||||
wx-ssh-keys $2 $3
|
||||
;;
|
||||
config)
|
||||
wx-ssh-config $2
|
||||
;;
|
||||
*)
|
||||
wx-header "SSH"
|
||||
wx-stop
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
@ -1,3 +1,63 @@
|
||||
warencli-ssh-config(){
|
||||
echo ">>> SSH: Config"
|
||||
wx-ssh-config(){
|
||||
wx-restricted
|
||||
|
||||
case $1 in
|
||||
edit)
|
||||
wx-ssh-config-sync
|
||||
wx-ssh-config-edit
|
||||
wx-ssh-config-save
|
||||
;;
|
||||
save)
|
||||
wx-ssh-config-save
|
||||
;;
|
||||
sync)
|
||||
wx-ssh-config-sync
|
||||
;;
|
||||
clean)
|
||||
wx-ssh-config-clean
|
||||
;;
|
||||
*)
|
||||
wx-ssh-config-sync
|
||||
wx-stop
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
wx-ssh-config-edit(){
|
||||
wx-header "SSH / Config / Edit"
|
||||
wx-restricted
|
||||
nano ~/.ssh/config
|
||||
}
|
||||
|
||||
wx-ssh-config-save(){
|
||||
wx-header "SSH / Config / Save"
|
||||
wx-restricted
|
||||
curl https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/config -X POST --header "X-Vault-Token: ${config["login",$ORG]}" -d "{ \"data\": { \"data\": \"$(cat ~/.ssh/config | base64 -w 0)\" } }" -s &> /dev/null
|
||||
}
|
||||
|
||||
wx-ssh-config-sync(){
|
||||
wx-header "SSH / Config / Sync"
|
||||
wx-restricted
|
||||
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/config -X GET --header "X-Vault-Token: ${config["login",$ORG]}")
|
||||
if [[ $VAULT_STATUS -eq 200 ]]
|
||||
then
|
||||
touch ~/.ssh/config
|
||||
SSH1_CONFIG_MD5=$(curl https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/config -X GET --header "X-Vault-Token: ${config["login",$ORG]}" -s | jq -r '.data.data.data' | base64 -d | md5sum | base64)
|
||||
SSH2_CONFIG_MD5=$(cat ~/.ssh/config | md5sum | base64)
|
||||
if [[ $SSH1_CONFIG_MD5 != $SSH2_CONFIG_MD5 ]]
|
||||
then
|
||||
echo $(curl https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/config -X GET --header "X-Vault-Token: ${config["login",$ORG]}" -s | jq -r '.data.data.data') | base64 -d > ~/.ssh/config 2>&1
|
||||
chmod 700 ~/.ssh/config
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
wx-ssh-config-clean(){
|
||||
wx-header "SSH / Config / Clean"
|
||||
wx-restricted
|
||||
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/config -X GET --header "X-Vault-Token: ${config["login",$ORG]}")
|
||||
if [[ -f "$HOME/.ssh/config" && $VAULT_STATUS -eq 200 ]]
|
||||
then
|
||||
rm "$HOME/.ssh/config"
|
||||
fi
|
||||
}
|
||||
|
169
src/commands/ssh/keys.sh
Normal file
169
src/commands/ssh/keys.sh
Normal file
@ -0,0 +1,169 @@
|
||||
wx-ssh-keys(){
|
||||
wx-restricted
|
||||
|
||||
case $1 in
|
||||
generate)
|
||||
wx-ssh-keys-retrieve $2
|
||||
wx-ssh-keys-generate $2
|
||||
wx-ssh-keys-save $2
|
||||
;;
|
||||
sign)
|
||||
wx-ssh-keys-sign
|
||||
;;
|
||||
retrieve)
|
||||
wx-ssh-keys-retrieve $2
|
||||
;;
|
||||
save)
|
||||
wx-ssh-keys-save $2
|
||||
;;
|
||||
sync)
|
||||
wx-ssh-keys-sync $2
|
||||
;;
|
||||
delete)
|
||||
wx-ssh-keys-delete $2
|
||||
;;
|
||||
clean)
|
||||
wx-ssh-keys-clean $2
|
||||
;;
|
||||
*)
|
||||
wx-stop
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
wx-ssh-keys-generate(){
|
||||
wx-header "SSH / Keys / Generate"
|
||||
wx-restricted
|
||||
if [[ ! -z $1 ]]
|
||||
then
|
||||
if [[ ! -f "$HOME/.ssh/keys/$1" ]]
|
||||
then
|
||||
ssh-keygen -t ed25519 -f $HOME/.ssh/keys/$1 -q -N "" -C "$USERNAME" &> /dev/null
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
wx-ssh-keys-sign(){
|
||||
wx-header "SSH / Keys / Sign"
|
||||
wx-restricted
|
||||
|
||||
if [[ $ORG == "warengroup" && $USERNAME != "cwchristerw" ]]
|
||||
then
|
||||
wx-ssh-keys-sign-create warengroup sysadmin 3600
|
||||
elif [[ $ORG == "cwinfo" && $USERNAME != "cwchristerw" ]]
|
||||
then
|
||||
wx-ssh-keys-sign-create cwinfo sysadmin 3600
|
||||
elif [[ $ORG == "cwchristerw" || $USERNAME == "cwchristerw" ]]
|
||||
then
|
||||
wx-ssh-keys-sign-create warengroup sysadmin 3600
|
||||
wx-ssh-keys-sign-create cwinfo sysadmin 3600
|
||||
wx-ssh-keys-sign-create cwchristerw sysadmin 3600
|
||||
fi
|
||||
}
|
||||
|
||||
wx-ssh-keys-sign-create(){
|
||||
wx-restricted
|
||||
|
||||
NAME=$1
|
||||
ROLE=$2
|
||||
PRINCIPALS=$2
|
||||
TTL=$3
|
||||
|
||||
if [[ ! -f "$HOME/.ssh/keys/$NAME" ]]
|
||||
then
|
||||
ssh-keygen -t ed25519 -f $HOME/.ssh/keys/$NAME -q -N "" -C "$USERNAME" &> /dev/null
|
||||
fi
|
||||
|
||||
if [[ -f "$HOME/.ssh/keys/$NAME" ]]
|
||||
then
|
||||
echo "$NAME/$ROLE"
|
||||
echo $(curl https://$VAULT_DOMAIN/v1/ssh/sign/$ROLE -X POST --header "X-Vault-Token: ${config["login",$ORG]}" -d "{ \"public_key\": \"$(cat $HOME/.ssh/keys/$NAME.pub)\", \"valid_principals\": \"$PRINCIPALS,$USERNAME\", \"ttl\": \"$TTL\" }" -s | jq -r '.data.signed_key') > ~/.ssh/keys/$NAME.sig 2>&1
|
||||
fi
|
||||
}
|
||||
|
||||
wx-ssh-keys-retrieve(){
|
||||
if [[ -z $2 ]]
|
||||
then
|
||||
wx-header "SSH / Keys / Retrieve"
|
||||
fi
|
||||
|
||||
wx-restricted
|
||||
if [[ ! -z $1 ]]
|
||||
then
|
||||
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/keys/$1 -X GET --header "X-Vault-Token: ${config["login",$ORG]}")
|
||||
if [[ $VAULT_STATUS -eq 200 ]]
|
||||
then
|
||||
echo $(curl https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/keys/$1 -X GET --header "X-Vault-Token: ${config["login",$ORG]}" -s | jq -r '.data.data.private') | base64 -d > ~/.ssh/keys/$1 2>&1
|
||||
chmod 700 ~/.ssh/keys/$1
|
||||
echo $(curl https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/keys/$1 -X GET --header "X-Vault-Token: ${config["login",$ORG]}" -s | jq -r '.data.data.public') | base64 -d > ~/.ssh/keys/$1.pub 2>&1
|
||||
chmod 700 ~/.ssh/keys/$1.pub
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
wx-ssh-keys-save(){
|
||||
wx-header "SSH / Keys / Save"
|
||||
wx-restricted
|
||||
if [[ ! -z $1 ]]
|
||||
then
|
||||
if [[ -f "$HOME/.ssh/keys/$1" ]]
|
||||
then
|
||||
curl https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/keys/$1 -X POST --header "X-Vault-Token: ${config["login",$ORG]}" -d "{ \"data\": { \"private\": \"$(cat ~/.ssh/keys/$1 | base64 -w 0)\", \"public\": \"$(cat ~/.ssh/keys/$1.pub | base64 -w 0)\" } }" -s &> /dev/null
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
wx-ssh-keys-sync(){
|
||||
wx-header "SSH / Keys / Sync"
|
||||
wx-restricted
|
||||
|
||||
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/cli/metadata/$USERNAME/settings/ssh/keys -X LIST --header "X-Vault-Token: ${config["login",$ORG]}")
|
||||
if [[ $VAULT_STATUS -eq 200 ]]
|
||||
then
|
||||
for name in $(curl https://$VAULT_DOMAIN/v1/cli/metadata/$USERNAME/settings/ssh/keys -X LIST --header "X-Vault-Token: ${config["login",$ORG]}" -s | jq -r '.data.keys | @sh' | tr -d \')
|
||||
do
|
||||
echo $name
|
||||
wx-ssh-keys-retrieve $name --multiple
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
wx-ssh-keys-clean(){
|
||||
if [[ -z $1 ]]
|
||||
then
|
||||
wx-header "SSH / Keys / Clean"
|
||||
fi
|
||||
wx-restricted
|
||||
|
||||
if [[ ! -z $1 ]]
|
||||
then
|
||||
if [[ -f "$HOME/.ssh/keys/$1" && $(basename "$HOME/.ssh/keys/$1") != "legacy" ]]
|
||||
then
|
||||
rm "$HOME/.ssh/keys/$1" &> /dev/null
|
||||
rm "$HOME/.ssh/keys/$1.pub" &> /dev/null
|
||||
rm "$HOME/.ssh/keys/$1.sig" &> /dev/null
|
||||
fi
|
||||
else
|
||||
if [[ $ORG == "warengroup" && $USERNAME != "cwchristerw" ]]
|
||||
then
|
||||
wx-ssh-keys-clean warengroup
|
||||
elif [[ $ORG == "cwinfo" && $USERNAME != "cwchristerw" ]]
|
||||
then
|
||||
wx-ssh-keys-clean cwinfo
|
||||
elif [[ $ORG == "cwchristerw" || $USERNAME == "cwchristerw" ]]
|
||||
then
|
||||
wx-ssh-keys-clean warengroup
|
||||
wx-ssh-keys-clean cwinfo
|
||||
wx-ssh-keys-clean cwchristerw
|
||||
fi
|
||||
|
||||
for file in ~/.ssh/keys/*
|
||||
do
|
||||
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/keys/$(basename "$file" .pub) -X GET --header "X-Vault-Token: ${config["login",$ORG]}")
|
||||
if [[ $(basename "$file") != "legacy" && $VAULT_STATUS -eq 200 ]]
|
||||
then
|
||||
rm "$file" &> /dev/null
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
warencli-ssh-sign(){
|
||||
echo ">>> SSH: Certificates"
|
||||
}
|
3
src/commands/welcome.sh
Normal file
3
src/commands/welcome.sh
Normal file
@ -0,0 +1,3 @@
|
||||
wx-welcome(){
|
||||
wx-header "Welcome"
|
||||
}
|
24
src/functions/header.sh
Normal file
24
src/functions/header.sh
Normal file
@ -0,0 +1,24 @@
|
||||
wx-header(){
|
||||
if [[ $2 == "h1" ]]
|
||||
then
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo "=============================="
|
||||
wx-repeat " " $((30/2-${#1}/2))
|
||||
echo -n "$wxBold"
|
||||
echo -n "$1"
|
||||
echo -n "$wxNormal"
|
||||
echo ""
|
||||
echo "=============================="
|
||||
fi
|
||||
|
||||
if [[ $2 == "h2" || -z $2 ]]
|
||||
then
|
||||
wx-start
|
||||
wx-repeat " " $((30/2-6/2-${#1}/2))
|
||||
echo -n ">> $1 <<"
|
||||
echo ""
|
||||
echo "------------------------------"
|
||||
fi
|
||||
}
|
5
src/functions/repeat.sh
Normal file
5
src/functions/repeat.sh
Normal file
@ -0,0 +1,5 @@
|
||||
wx-repeat() {
|
||||
local str=$1 n=$2 spaces
|
||||
printf -v spaces "%*s" $n " "
|
||||
printf "%s" "${spaces// /$str}"
|
||||
}
|
10
src/functions/restricted.sh
Normal file
10
src/functions/restricted.sh
Normal file
@ -0,0 +1,10 @@
|
||||
wx-restricted(){
|
||||
if [[ $USER == "root" || $USER == "local" ]]
|
||||
then
|
||||
echo "Status: Command Restricted"
|
||||
echo " "
|
||||
echo " "
|
||||
echo " "
|
||||
exit 1
|
||||
fi
|
||||
}
|
15
src/functions/start.sh
Normal file
15
src/functions/start.sh
Normal file
@ -0,0 +1,15 @@
|
||||
wx-start(){
|
||||
wx-header "Warén CLI" h1
|
||||
|
||||
mkdir -p $HOME/.warengroup &> /dev/null
|
||||
|
||||
if [[ ! -f "$HOME/.warengroup/config.json" || $(jq -e . < $HOME/.warengroup/config.json &>/dev/null; echo $?) -gt 0 ]]
|
||||
then
|
||||
echo '{}' | jq > $HOME/.warengroup/config.json
|
||||
fi
|
||||
|
||||
mkdir -p $HOME/.ssh/keys
|
||||
chmod 700 -R $HOME/.ssh/keys
|
||||
mkdir -p $HOME/.ssh/multiplex
|
||||
chmod 700 -R $HOME/.ssh/multiplex
|
||||
}
|
14
src/functions/stop.sh
Normal file
14
src/functions/stop.sh
Normal file
@ -0,0 +1,14 @@
|
||||
wx-stop (){
|
||||
echo " "
|
||||
echo " "
|
||||
echo " "
|
||||
|
||||
wx-install --auto
|
||||
|
||||
if [[ $USERNAME != $USER && $USERNAME != $SUDO_USER && $USERNAME != $LOGNAME ]]
|
||||
then
|
||||
wx-logout
|
||||
fi
|
||||
|
||||
exit 1
|
||||
}
|
737
wx
737
wx
@ -5,99 +5,704 @@ if [ ! "$BASH_VERSION" ] ; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
warencli-syntax-line-douple() {
|
||||
echo -n "
|
||||
==============================
|
||||
"
|
||||
wxRed=$(tput setaf 196)
|
||||
wxGreen=$(tput setaf 46)
|
||||
wxYellow=$(tput setaf 226)
|
||||
wxBlue=$(tput setaf 21)
|
||||
wxPurple=$(tput setaf 165)
|
||||
wxTurquoise=$(tput setaf 14)
|
||||
wxPink=$(tput setaf 198)
|
||||
wxOrange=$(tput setaf 202)
|
||||
wxUnderline=$(tput smul)
|
||||
wxBold=$(tput bold)
|
||||
wxNormal=$(tput sgr0)
|
||||
|
||||
declare -Ax config
|
||||
|
||||
wx-header(){
|
||||
if [[ $2 == "h1" ]]
|
||||
then
|
||||
echo ""
|
||||
echo ""
|
||||
echo ""
|
||||
echo "=============================="
|
||||
wx-repeat " " $((30/2-${#1}/2))
|
||||
echo -n "$wxBold"
|
||||
echo -n "$1"
|
||||
echo -n "$wxNormal"
|
||||
echo ""
|
||||
echo "=============================="
|
||||
fi
|
||||
|
||||
if [[ $2 == "h2" || -z $2 ]]
|
||||
then
|
||||
wx-start
|
||||
wx-repeat " " $((30/2-6/2-${#1}/2))
|
||||
echo -n ">> $1 <<"
|
||||
echo ""
|
||||
echo "------------------------------"
|
||||
fi
|
||||
}
|
||||
|
||||
warencli-syntax-line-single() {
|
||||
echo -n "
|
||||
------------------------------
|
||||
"
|
||||
wx-repeat() {
|
||||
local str=$1 n=$2 spaces
|
||||
printf -v spaces "%*s" $n " "
|
||||
printf "%s" "${spaces// /$str}"
|
||||
}
|
||||
|
||||
warencli-start() {
|
||||
warencli-syntax-line-douple
|
||||
echo -n "Warén CLI "
|
||||
warencli-syntax-line-douple
|
||||
}
|
||||
|
||||
warencli-stop () {
|
||||
wx-restricted(){
|
||||
if [[ $USER == "root" || $USER == "local" ]]
|
||||
then
|
||||
echo "Status: Command Restricted"
|
||||
echo " "
|
||||
echo " "
|
||||
echo " "
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
wx-start(){
|
||||
wx-header "Warén CLI" h1
|
||||
|
||||
mkdir -p $HOME/.warengroup &> /dev/null
|
||||
|
||||
if [[ ! -f "$HOME/.warengroup/config.json" || $(jq -e . < $HOME/.warengroup/config.json &>/dev/null; echo $?) -gt 0 ]]
|
||||
then
|
||||
echo '{}' | jq > $HOME/.warengroup/config.json
|
||||
fi
|
||||
|
||||
mkdir -p $HOME/.ssh/keys
|
||||
chmod 700 -R $HOME/.ssh/keys
|
||||
mkdir -p $HOME/.ssh/multiplex
|
||||
chmod 700 -R $HOME/.ssh/multiplex
|
||||
}
|
||||
|
||||
wx-stop (){
|
||||
echo " "
|
||||
echo " "
|
||||
echo " "
|
||||
|
||||
wx-install --auto
|
||||
|
||||
if [[ $USERNAME != $USER && $USERNAME != $SUDO_USER && $USERNAME != $LOGNAME ]]
|
||||
then
|
||||
wx-logout
|
||||
fi
|
||||
|
||||
exit 1
|
||||
}
|
||||
|
||||
warencli-update() {
|
||||
if [[ -d "./src" ]]; then
|
||||
echo ">>> Building... <<<"
|
||||
podman run -it --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp docker.io/library/php:8-cli php generator.php
|
||||
else
|
||||
echo ">>> Updating... <<<"
|
||||
sudo curl https://git.waren.io/warengroup/wx/raw/branch/master/wx -o /opt/wx &> /dev/null
|
||||
if [[ -d "/usr/bin" ]]; then
|
||||
sudo ln -sf /opt/wx /usr/bin/wx &> /dev/null
|
||||
fi
|
||||
sudo chmod +x /usr/bin/wx &> /dev/null
|
||||
fi
|
||||
}
|
||||
wx-help(){
|
||||
|
||||
warencli-help() {
|
||||
echo "
|
||||
wx-header "Help"
|
||||
|
||||
echo -n "
|
||||
Usage: $0 COMMAND [OPTIONS]
|
||||
|
||||
Common Commands:
|
||||
init Init
|
||||
help Help
|
||||
ssh SSH
|
||||
config Config
|
||||
sign Certificates
|
||||
edit Edit
|
||||
save Save
|
||||
sync Sync
|
||||
clean Clean
|
||||
keys Keys
|
||||
generate Generate
|
||||
sign Sign
|
||||
retrieve Retrieve
|
||||
save Save
|
||||
sync Sync
|
||||
delete Delete
|
||||
clean Clean
|
||||
|
||||
Authentication Commands:
|
||||
login Login
|
||||
logout Logout
|
||||
|
||||
Management Commands:
|
||||
auto Auto
|
||||
clean Clean
|
||||
settings Settings
|
||||
|
||||
Maintenance Commands:
|
||||
install Install
|
||||
update Update
|
||||
";
|
||||
|
||||
}
|
||||
|
||||
wx-infra(){
|
||||
wx-login
|
||||
wx-auto &> /dev/null
|
||||
|
||||
wx-header "Infra"
|
||||
wx-restricted
|
||||
|
||||
case $USERNAME in
|
||||
cwchristerw)
|
||||
if [[ -d "$HOME/Desktop/Work in Progress/Programming/warengroup/infra" ]]
|
||||
then
|
||||
INFRA_PATH="$HOME/Desktop/Work in Progress/Programming/warengroup/infra"
|
||||
else
|
||||
if [[ -d "$HOME/.warengroup/infra" ]]
|
||||
then
|
||||
INFRA_PATH="$HOME/.warengroup/infra"
|
||||
else
|
||||
INFRA_PATH="$HOME/.warengroup/infra"
|
||||
mkdir -p "$INFRA_PATH" &> /dev/null
|
||||
git clone ssh://git@git.waren.io:2222/warengroup-private/infra.git --config core.sshCommand="ssh -i $HOME/.ssh/keys/warengroup-legacy -o ProxyJump=none" "$INFRA_PATH" &> /dev/null
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ ! -f "$INFRA_PATH/vault/cwchristerw" || ! -f "$INFRA_PATH/vault/warengroup" ]]
|
||||
then
|
||||
mkdir -p "$INFRA_PATH/vault" &> /dev/null
|
||||
|
||||
curl \
|
||||
-H "X-Vault-Token: ${config["login",$ORG]}" \
|
||||
-X GET \
|
||||
https://$VAULT_DOMAIN/v1/cli/data/cwchristerw/settings/infra -s | jq -r '.data.data.cwchristerw' > "$INFRA_PATH/vault/cwchristerw"
|
||||
|
||||
curl \
|
||||
-H "X-Vault-Token: ${config["login",$ORG]}" \
|
||||
-X GET \
|
||||
https://$VAULT_DOMAIN/v1/cli/data/cwchristerw/settings/infra -s | jq -r '.data.data.warengroup' > "$INFRA_PATH/vault/warengroup"
|
||||
fi
|
||||
|
||||
if [[ -z $1 ]]
|
||||
then
|
||||
echo "Tag Required"
|
||||
else
|
||||
if [[ $1 == "init" ]]
|
||||
then
|
||||
if [[ -z $2 ]]
|
||||
then
|
||||
2=init
|
||||
fi
|
||||
|
||||
cd "$INFRA_PATH"
|
||||
git pull &> /dev/null
|
||||
ansible-galaxy collection install -r requirements.yml --upgrade &> /dev/null
|
||||
ansible-playbook --vault-id warengroup@vault/warengroup --vault-id cwchristerw@vault/cwchristerw playbooks/init.yml -t $2 $3 $4 $5 $6 $7 $8 $9
|
||||
cd "$OLDPWD"
|
||||
elif [[ $1 == "manager" ]]
|
||||
then
|
||||
cd "$INFRA_PATH"
|
||||
git pull &> /dev/null
|
||||
ansible-galaxy collection install -r requirements.yml --upgrade &> /dev/null
|
||||
ansible-playbook --vault-id warengroup@vault/warengroup --vault-id cwchristerw@vault/cwchristerw manager.yml $2 $3 $4 $5 $6 $7 $8 $9
|
||||
cd "$OLDPWD"
|
||||
else
|
||||
cd "$INFRA_PATH"
|
||||
git pull &> /dev/null
|
||||
ansible-galaxy collection install -r requirements.yml --upgrade &> /dev/null
|
||||
ansible-playbook --vault-id warengroup@vault/warengroup --vault-id cwchristerw@vault/cwchristerw playbooks.yml -t $1 $2 $3 $4 $5 $6 $7 $8 $9
|
||||
cd "$OLDPWD"
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "User Unsupported"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
wx-ssh(){
|
||||
wx-login
|
||||
|
||||
case $1 in
|
||||
keys)
|
||||
wx-ssh-keys $2 $3
|
||||
;;
|
||||
config)
|
||||
wx-ssh-config $2
|
||||
;;
|
||||
*)
|
||||
wx-header "SSH"
|
||||
wx-stop
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
wx-welcome(){
|
||||
wx-header "Welcome"
|
||||
}
|
||||
|
||||
wx-login(){
|
||||
if [[ ! -z $1 ]]
|
||||
then
|
||||
ORG=$1
|
||||
jq '.org = "'$ORG'"' $HOME/.warengroup/config.json 1> $HOME/.warengroup/config.json.tmp
|
||||
mv $HOME/.warengroup/config.json.tmp $HOME/.warengroup/config.json &> /dev/null
|
||||
elif [[ $(hostname -d) = *"devices.waren.io" ]]
|
||||
then
|
||||
ORG=warengroup
|
||||
elif [[ $(hostname -d) = *"devices.cwinfo.net" ]]
|
||||
then
|
||||
ORG=cwinfo
|
||||
elif [[ $(hostname -d) = *"devices.christerwaren.fi" ]]
|
||||
then
|
||||
ORG=cwchristerw
|
||||
elif [[ $USER != "root" && $USER != "local" && -f "$HOME/.warengroup/config.json" && $(cat $HOME/.warengroup/config.json | jq -r .org) != "null" ]]
|
||||
then
|
||||
ORG=$(cat $HOME/.warengroup/config.json | jq -r .org)
|
||||
else
|
||||
wx-header "Login"
|
||||
echo "Status: Organization Required"
|
||||
wx-stop
|
||||
fi
|
||||
|
||||
if [[ $ORG == "warengroup" ]]
|
||||
then
|
||||
DOMAIN=waren.io
|
||||
elif [[ $ORG == "cwinfo" ]]
|
||||
then
|
||||
DOMAIN=cwinfo.net
|
||||
elif [[ $ORG == "cwchristerw" ]]
|
||||
then
|
||||
DOMAIN=christerwaren.fi
|
||||
else
|
||||
wx-header "Login"
|
||||
echo "Status: Organization Unsupported"
|
||||
wx-stop
|
||||
fi
|
||||
|
||||
FOLDER=$ORG
|
||||
DEVICE_DOMAIN="devices.$DOMAIN"
|
||||
IDM_DOMAIN="idm.waren.io"
|
||||
VAULT_DOMAIN="vault.cwinfo.net"
|
||||
|
||||
if [[ -z $USER || $USER == "root" || $USER == "local" ]]
|
||||
then
|
||||
if [[ -z $SUDO_USER ]]
|
||||
then
|
||||
if [[ -z LOGNAME ]]
|
||||
then
|
||||
wx-header "Login"
|
||||
echo "Status: Username Required"
|
||||
wx-stop
|
||||
else
|
||||
USERNAME=$LOGNAME
|
||||
fi
|
||||
else
|
||||
USERNAME=$SUDO_USER
|
||||
fi
|
||||
else
|
||||
USERNAME=$USER
|
||||
fi
|
||||
|
||||
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/sys/health)
|
||||
if [[ $VAULT_STATUS -eq 200 ]]
|
||||
then
|
||||
|
||||
if [[ $USER != "root" && $USER != "local" && -f "$HOME/.warengroup/config.json" ]]
|
||||
then
|
||||
if [[ $(cat $HOME/.warengroup/config.json | jq -r .login.$ORG.username) != "null" ]]
|
||||
then
|
||||
USERNAME="$(cat $HOME/.warengroup/config.json | jq -r .login.$ORG.username)"
|
||||
fi
|
||||
TOKEN="$(cat $HOME/.warengroup/config.json | jq -r .login.$ORG.token)"
|
||||
fi
|
||||
|
||||
VAULT_LOGIN=$(curl https://$VAULT_DOMAIN/v1/auth/token/renew -X POST --header "X-Vault-Token: $TOKEN" -d '{ "token": "'$TOKEN'" }' -s | jq -r '.auth.client_token')
|
||||
if [[ ! -z $VAULT_LOGIN && ${#VAULT_LOGIN} == 95 ]]
|
||||
then
|
||||
config["login",${ORG}]=$VAULT_LOGIN
|
||||
if [[ $USER != "root" && $USER != "local" ]]
|
||||
then
|
||||
jq '.login.'$ORG'.token = "'$VAULT_LOGIN'"' $HOME/.warengroup/config.json 1> $HOME/.warengroup/config.json.tmp
|
||||
mv $HOME/.warengroup/config.json.tmp $HOME/.warengroup/config.json &> /dev/null
|
||||
fi
|
||||
else
|
||||
IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN)
|
||||
if [[ $IDM_STATUS -eq 301 ]]
|
||||
then
|
||||
wx-header "Login"
|
||||
echo $wxBold$ORG$wxNormal
|
||||
|
||||
if [[ -z $USERNAME || $USERNAME == "root" || $USERNAME == "local" || $USERNAME == "nobody" ]]
|
||||
then
|
||||
echo -n "Username: "
|
||||
read USERNAME
|
||||
else
|
||||
echo "Username: $USERNAME"
|
||||
fi
|
||||
|
||||
jq '.login.'$ORG'.username = "'$USERNAME'"' $HOME/.warengroup/config.json 1> $HOME/.warengroup/config.json.tmp
|
||||
mv $HOME/.warengroup/config.json.tmp $HOME/.warengroup/config.json &> /dev/null
|
||||
|
||||
echo -n "Password: "
|
||||
read -s PASSWORD
|
||||
echo "****************"
|
||||
|
||||
if [[ -z $USERNAME || -z $PASSWORD ]]
|
||||
then
|
||||
echo "Status: Username & Password Required"
|
||||
wx-stop
|
||||
else
|
||||
VAULT_LOGIN=$(curl https://$VAULT_DOMAIN/v1/auth/ldap/login/$USERNAME -X POST -d '{ "password": "'$PASSWORD'" }' -s | jq -r '.auth.client_token')
|
||||
if [[ -z $VAULT_LOGIN || ${#VAULT_LOGIN} -lt 95 || ${#VAULT_LOGIN} -gt 95 ]]
|
||||
then
|
||||
echo "Status: Login Failed"
|
||||
wx-stop
|
||||
fi
|
||||
|
||||
config["login",${ORG}]=$VAULT_LOGIN
|
||||
|
||||
if [[ $USER != "root" && $USER != "local" ]]
|
||||
then
|
||||
jq '.login.'$ORG'.token = "'$VAULT_LOGIN'"' $HOME/.warengroup/config.json &> $HOME/.warengroup/config.json.tmp
|
||||
mv $HOME/.warengroup/config.json.tmp $HOME/.warengroup/config.json &> /dev/null
|
||||
fi
|
||||
fi
|
||||
else
|
||||
wx-header "Login"
|
||||
echo $wxBold$ORG$wxNormal
|
||||
|
||||
echo -n "Token: "
|
||||
read -s TOKEN
|
||||
echo "****************"
|
||||
|
||||
if [[ -z $TOKEN || ${#TOKEN} -lt 95 || ${#TOKEN} -gt 95 ]]
|
||||
then
|
||||
echo "Status: Vault Token Required"
|
||||
wx-stop
|
||||
fi
|
||||
|
||||
VAULT_LOGIN=$(curl https://$VAULT_DOMAIN/v1/auth/token/renew -X POST --header "X-Vault-Token: $TOKEN" -d '{ "token": "'$TOKEN'" }' -s | jq -r '.auth.client_token')
|
||||
if [[ -z $VAULT_LOGIN || ${#VAULT_LOGIN} -lt 95 || ${#VAULT_LOGIN} -gt 95 ]]
|
||||
then
|
||||
echo "Status: Login Failed"
|
||||
wx-stop
|
||||
fi
|
||||
|
||||
config["login",${ORG}]=$VAULT_LOGIN
|
||||
|
||||
if [[ $USER != "root" && $USER != "local" ]]
|
||||
then
|
||||
jq '.login.'$ORG'.token = "'$VAULT_LOGIN'"' $HOME/.warengroup/config.json &> $HOME/.warengroup/config.json.tmp
|
||||
mv $HOME/.warengroup/config.json.tmp $HOME/.warengroup/config.json &> /dev/null
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
else
|
||||
wx-header "Login"
|
||||
echo $wxBold$ORG$wxNormal
|
||||
echo "Status: Vault Offline"
|
||||
wx-stop
|
||||
fi
|
||||
}
|
||||
|
||||
wx-logout(){
|
||||
wx-header "Logout"
|
||||
if [[ $USER != "root" && $USER != "local" && -f "$HOME/.warengroup/config.json" ]]
|
||||
then
|
||||
VAULT_LOGIN=$(cat $HOME/.warengroup/config.json | jq -r .login)
|
||||
if [[ $VAULT_LOGIN != null && $VAULT_LOGIN != "{}" ]]
|
||||
then
|
||||
wx-clean &> /dev/null
|
||||
jq '.login = {}' $HOME/.warengroup/config.json &> $HOME/.warengroup/config.json.tmp
|
||||
mv $HOME/.warengroup/config.json.tmp $HOME/.warengroup/config.json &> /dev/null
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
wx-install(){
|
||||
if [[ -z $1 ]]
|
||||
then
|
||||
wx-header "Install"
|
||||
fi
|
||||
|
||||
wx-restricted
|
||||
|
||||
if [[ -f "./wx" ]] && [[ -d "./src" ]]
|
||||
then
|
||||
podman run -it --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp docker.io/library/php:8-cli php generator.php &> /dev/null
|
||||
mv wx.tmp wx &> /dev/null
|
||||
chmod +x wx &> /dev/null
|
||||
fi
|
||||
|
||||
mkdir $HOME/bin &> /dev/null
|
||||
curl https://git.waren.io/warengroup/wx/raw/branch/master/wx -o $HOME/bin/wx &> /dev/null
|
||||
chmod +x $HOME/bin/wx &> /dev/null
|
||||
}
|
||||
|
||||
wx-uninstall(){
|
||||
wx-header "Uninstall"
|
||||
wx-logout
|
||||
if [[ ! -d "$HOME/.warengroup" ]]
|
||||
then
|
||||
rm "$HOME/.warengroup" -rf
|
||||
fi
|
||||
}
|
||||
|
||||
wx-update(){
|
||||
wx-header "Update"
|
||||
wx-install --update
|
||||
}
|
||||
|
||||
wx-auto(){
|
||||
wx-login
|
||||
wx-header "Auto"
|
||||
|
||||
wx-ssh-config-sync
|
||||
wx-ssh-keys-sync
|
||||
wx-ssh-keys-sign
|
||||
}
|
||||
|
||||
wx-clean(){
|
||||
wx-login
|
||||
wx-header "Clean"
|
||||
wx-ssh-config-clean
|
||||
wx-ssh-keys-clean
|
||||
}
|
||||
|
||||
wx-settings(){
|
||||
wx-login
|
||||
wx-header "Settings"
|
||||
}
|
||||
|
||||
wx-ssh-config(){
|
||||
wx-restricted
|
||||
|
||||
case $1 in
|
||||
edit)
|
||||
wx-ssh-config-sync
|
||||
wx-ssh-config-edit
|
||||
wx-ssh-config-save
|
||||
;;
|
||||
save)
|
||||
wx-ssh-config-save
|
||||
;;
|
||||
sync)
|
||||
wx-ssh-config-sync
|
||||
;;
|
||||
clean)
|
||||
wx-ssh-config-clean
|
||||
;;
|
||||
*)
|
||||
wx-ssh-config-sync
|
||||
wx-stop
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
wx-ssh-config-edit(){
|
||||
wx-header "SSH / Config / Edit"
|
||||
wx-restricted
|
||||
nano ~/.ssh/config
|
||||
}
|
||||
|
||||
wx-ssh-config-save(){
|
||||
wx-header "SSH / Config / Save"
|
||||
wx-restricted
|
||||
curl https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/config -X POST --header "X-Vault-Token: ${config["login",$ORG]}" -d "{ \"data\": { \"data\": \"$(cat ~/.ssh/config | base64 -w 0)\" } }" -s &> /dev/null
|
||||
}
|
||||
|
||||
wx-ssh-config-sync(){
|
||||
wx-header "SSH / Config / Sync"
|
||||
wx-restricted
|
||||
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/config -X GET --header "X-Vault-Token: ${config["login",$ORG]}")
|
||||
if [[ $VAULT_STATUS -eq 200 ]]
|
||||
then
|
||||
touch ~/.ssh/config
|
||||
SSH1_CONFIG_MD5=$(curl https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/config -X GET --header "X-Vault-Token: ${config["login",$ORG]}" -s | jq -r '.data.data.data' | base64 -d | md5sum | base64)
|
||||
SSH2_CONFIG_MD5=$(cat ~/.ssh/config | md5sum | base64)
|
||||
if [[ $SSH1_CONFIG_MD5 != $SSH2_CONFIG_MD5 ]]
|
||||
then
|
||||
echo $(curl https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/config -X GET --header "X-Vault-Token: ${config["login",$ORG]}" -s | jq -r '.data.data.data') | base64 -d > ~/.ssh/config 2>&1
|
||||
chmod 700 ~/.ssh/config
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
wx-ssh-config-clean(){
|
||||
wx-header "SSH / Config / Clean"
|
||||
wx-restricted
|
||||
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/config -X GET --header "X-Vault-Token: ${config["login",$ORG]}")
|
||||
if [[ -f "$HOME/.ssh/config" && $VAULT_STATUS -eq 200 ]]
|
||||
then
|
||||
rm "$HOME/.ssh/config"
|
||||
fi
|
||||
}
|
||||
|
||||
wx-ssh-keys(){
|
||||
wx-restricted
|
||||
|
||||
case $1 in
|
||||
generate)
|
||||
wx-ssh-keys-retrieve $2
|
||||
wx-ssh-keys-generate $2
|
||||
wx-ssh-keys-save $2
|
||||
;;
|
||||
sign)
|
||||
wx-ssh-keys-sign
|
||||
;;
|
||||
retrieve)
|
||||
wx-ssh-keys-retrieve $2
|
||||
;;
|
||||
save)
|
||||
wx-ssh-keys-save $2
|
||||
;;
|
||||
sync)
|
||||
wx-ssh-keys-sync $2
|
||||
;;
|
||||
delete)
|
||||
wx-ssh-keys-delete $2
|
||||
;;
|
||||
clean)
|
||||
wx-ssh-keys-clean $2
|
||||
;;
|
||||
*)
|
||||
wx-stop
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
wx-ssh-keys-generate(){
|
||||
wx-header "SSH / Keys / Generate"
|
||||
wx-restricted
|
||||
if [[ ! -z $1 ]]
|
||||
then
|
||||
if [[ ! -f "$HOME/.ssh/keys/$1" ]]
|
||||
then
|
||||
ssh-keygen -t ed25519 -f $HOME/.ssh/keys/$1 -q -N "" -C "$USERNAME" &> /dev/null
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
wx-ssh-keys-sign(){
|
||||
wx-header "SSH / Keys / Sign"
|
||||
wx-restricted
|
||||
|
||||
if [[ $ORG == "warengroup" && $USERNAME != "cwchristerw" ]]
|
||||
then
|
||||
wx-ssh-keys-sign-create warengroup sysadmin 3600
|
||||
elif [[ $ORG == "cwinfo" && $USERNAME != "cwchristerw" ]]
|
||||
then
|
||||
wx-ssh-keys-sign-create cwinfo sysadmin 3600
|
||||
elif [[ $ORG == "cwchristerw" || $USERNAME == "cwchristerw" ]]
|
||||
then
|
||||
wx-ssh-keys-sign-create warengroup sysadmin 3600
|
||||
wx-ssh-keys-sign-create cwinfo sysadmin 3600
|
||||
wx-ssh-keys-sign-create cwchristerw sysadmin 3600
|
||||
fi
|
||||
}
|
||||
|
||||
wx-ssh-keys-sign-create(){
|
||||
wx-restricted
|
||||
|
||||
NAME=$1
|
||||
ROLE=$2
|
||||
PRINCIPALS=$2
|
||||
TTL=$3
|
||||
|
||||
if [[ ! -f "$HOME/.ssh/keys/$NAME" ]]
|
||||
then
|
||||
ssh-keygen -t ed25519 -f $HOME/.ssh/keys/$NAME -q -N "" -C "$USERNAME" &> /dev/null
|
||||
fi
|
||||
|
||||
if [[ -f "$HOME/.ssh/keys/$NAME" ]]
|
||||
then
|
||||
echo "$NAME/$ROLE"
|
||||
echo $(curl https://$VAULT_DOMAIN/v1/ssh/sign/$ROLE -X POST --header "X-Vault-Token: ${config["login",$ORG]}" -d "{ \"public_key\": \"$(cat $HOME/.ssh/keys/$NAME.pub)\", \"valid_principals\": \"$PRINCIPALS,$USERNAME\", \"ttl\": \"$TTL\" }" -s | jq -r '.data.signed_key') > ~/.ssh/keys/$NAME.sig 2>&1
|
||||
fi
|
||||
}
|
||||
|
||||
wx-ssh-keys-retrieve(){
|
||||
if [[ -z $2 ]]
|
||||
then
|
||||
wx-header "SSH / Keys / Retrieve"
|
||||
fi
|
||||
|
||||
wx-restricted
|
||||
if [[ ! -z $1 ]]
|
||||
then
|
||||
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/keys/$1 -X GET --header "X-Vault-Token: ${config["login",$ORG]}")
|
||||
if [[ $VAULT_STATUS -eq 200 ]]
|
||||
then
|
||||
echo $(curl https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/keys/$1 -X GET --header "X-Vault-Token: ${config["login",$ORG]}" -s | jq -r '.data.data.private') | base64 -d > ~/.ssh/keys/$1 2>&1
|
||||
chmod 700 ~/.ssh/keys/$1
|
||||
echo $(curl https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/keys/$1 -X GET --header "X-Vault-Token: ${config["login",$ORG]}" -s | jq -r '.data.data.public') | base64 -d > ~/.ssh/keys/$1.pub 2>&1
|
||||
chmod 700 ~/.ssh/keys/$1.pub
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
wx-ssh-keys-save(){
|
||||
wx-header "SSH / Keys / Save"
|
||||
wx-restricted
|
||||
if [[ ! -z $1 ]]
|
||||
then
|
||||
if [[ -f "$HOME/.ssh/keys/$1" ]]
|
||||
then
|
||||
curl https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/keys/$1 -X POST --header "X-Vault-Token: ${config["login",$ORG]}" -d "{ \"data\": { \"private\": \"$(cat ~/.ssh/keys/$1 | base64 -w 0)\", \"public\": \"$(cat ~/.ssh/keys/$1.pub | base64 -w 0)\" } }" -s &> /dev/null
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
wx-ssh-keys-sync(){
|
||||
wx-header "SSH / Keys / Sync"
|
||||
wx-restricted
|
||||
|
||||
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/cli/metadata/$USERNAME/settings/ssh/keys -X LIST --header "X-Vault-Token: ${config["login",$ORG]}")
|
||||
if [[ $VAULT_STATUS -eq 200 ]]
|
||||
then
|
||||
for name in $(curl https://$VAULT_DOMAIN/v1/cli/metadata/$USERNAME/settings/ssh/keys -X LIST --header "X-Vault-Token: ${config["login",$ORG]}" -s | jq -r '.data.keys | @sh' | tr -d \')
|
||||
do
|
||||
echo $name
|
||||
wx-ssh-keys-retrieve $name --multiple
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
wx-ssh-keys-clean(){
|
||||
if [[ -z $1 ]]
|
||||
then
|
||||
wx-header "SSH / Keys / Clean"
|
||||
fi
|
||||
wx-restricted
|
||||
|
||||
if [[ ! -z $1 ]]
|
||||
then
|
||||
if [[ -f "$HOME/.ssh/keys/$1" && $(basename "$HOME/.ssh/keys/$1") != "legacy" ]]
|
||||
then
|
||||
rm "$HOME/.ssh/keys/$1" &> /dev/null
|
||||
rm "$HOME/.ssh/keys/$1.pub" &> /dev/null
|
||||
rm "$HOME/.ssh/keys/$1.sig" &> /dev/null
|
||||
fi
|
||||
else
|
||||
if [[ $ORG == "warengroup" && $USERNAME != "cwchristerw" ]]
|
||||
then
|
||||
wx-ssh-keys-clean warengroup
|
||||
elif [[ $ORG == "cwinfo" && $USERNAME != "cwchristerw" ]]
|
||||
then
|
||||
wx-ssh-keys-clean cwinfo
|
||||
elif [[ $ORG == "cwchristerw" || $USERNAME == "cwchristerw" ]]
|
||||
then
|
||||
wx-ssh-keys-clean warengroup
|
||||
wx-ssh-keys-clean cwinfo
|
||||
wx-ssh-keys-clean cwchristerw
|
||||
fi
|
||||
|
||||
for file in ~/.ssh/keys/*
|
||||
do
|
||||
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/cli/data/$USERNAME/settings/ssh/keys/$(basename "$file" .pub) -X GET --header "X-Vault-Token: ${config["login",$ORG]}")
|
||||
if [[ $(basename "$file") != "legacy" && $VAULT_STATUS -eq 200 ]]
|
||||
then
|
||||
rm "$file" &> /dev/null
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
warencli-install() {
|
||||
echo ">>> Install";
|
||||
}
|
||||
|
||||
warencli-settings() {
|
||||
echo ">>> Settings";
|
||||
}
|
||||
|
||||
warencli-ssh() {
|
||||
echo ">>> SSH";
|
||||
}
|
||||
|
||||
warencli-login() {
|
||||
echo ">>> Authentication: Login";
|
||||
}
|
||||
|
||||
warencli-logout() {
|
||||
echo ">>> Authentication: Logout";
|
||||
}
|
||||
|
||||
warencli-ssh-config(){
|
||||
echo ">>> SSH: Config"
|
||||
}
|
||||
|
||||
warencli-ssh-sign(){
|
||||
echo ">>> SSH: Certificates"
|
||||
}
|
||||
|
||||
|
||||
COMMAND=$1
|
||||
|
||||
warencli-start
|
||||
if [[ ! -z $1 ]]; then
|
||||
warencli-$1 $2 $3 $4 $5 $6 $7 $8 $9
|
||||
if [[ ! -z $1 ]] && [[ $(type -t wx-$1) == function ]]
|
||||
then
|
||||
wx-$1 $2 $3 $4 $5 $6 $7 $8 $9
|
||||
else
|
||||
wx-welcome
|
||||
fi
|
||||
warencli-stop
|
||||
wx-stop
|
||||
|
Reference in New Issue
Block a user