Compare commits

..

4 Commits

Author SHA1 Message Date
Christer Warén
56b6f58f4e Docs Update 2024-04-27 20:09:05 +03:00
Christer Warén
fb3c902d9a Generator Update 2024-04-27 20:08:52 +03:00
Christer Warén
9f0df0dbdf Build Update 2024-04-27 20:08:43 +03:00
Christer Warén
3daa8a84dc Source Update 2024-04-27 20:08:15 +03:00
14 changed files with 274 additions and 241 deletions

View File

@ -1 +1,8 @@
# Warén Group - WX
## Install
```
sudo curl https://git.waren.io/warengroup/wx/raw/branch/master/wx -o /opt/wx &> /dev/null
sudo ln -sf /opt/wx /usr/bin/wx &> /dev/null
sudo chmod +x /usr/bin/wx &> /dev/null
```

View File

@ -6,18 +6,31 @@ $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',
__DIR__.'/src/elements.sh'
];
$codes = [];
foreach($dirs as $dir){
foreach(glob($dir) as $file){
$codes[$file] = file_get_contents($file);
if(str_contains($dir, "elements")){
echo $dir;
$codes['elements'][$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("{{ ELEMENTS }}", implode("\n", $codes['elements']), $base);
$code = str_replace("{{ FUNCTIONS }}", implode("\n", $codes['functions']), $code);
$code = str_replace("{{ COMMANDS }}", implode("\n", $codes['commands']), $code);
try {
$file = __DIR__.'/wx.tmp';

View File

@ -5,192 +5,17 @@ if [ ! "$BASH_VERSION" ] ; then
exit 1
fi
syntax-line-douple() {
echo -n "
==============================
"
}
syntax-line-single() {
echo -n "
------------------------------
"
}
start() {
syntax-line-douple
echo -n "Warén CLI "
syntax-line-douple
}
login() {
echo ">>> Login <<<"
ORG=$2
if [[ -z "$HOSTNAME" || ${#HOSTNAME} -lt 5 ]]; then
stop
fi
if [[ $(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 [[ -z $ORG ]]
then
echo "Organization: Required"
exit 1
fi
if [[ $ORG == "warengroup" ]]
then
DOMAIN=waren.io
elif [[ $ORG == "cwinfo" ]]
then
DOMAIN=cwinfo.net
elif [[ $ORG == "cwchristerw" ]]
then
DOMAIN=christerwaren.fi
else
echo "Organization: Unsupported"
exit 1
fi
FOLDER=$ORG
DEVICE_DOMAIN="devices.$DOMAIN"
IDM_DOMAIN="idm.cwinfo.net"
VAULT_DOMAIN="vault.cwinfo.net"
GIT_DOMAIN="git.cwinfo.net"
if [[ $(hostname -d) ]]
then
HOSTNAME=$(hostname --fqdn)
elif [[ -z $(hostname -d) ]] && [[ ! -z $2 ]]
then
HOSTNAME="$2.$DEVICE_DOMAIN"
else
echo "Hostname: Required"
exit 1
fi
if [[ -z $USER ]]
then
if [[ -z $SUDO_USER ]]
then
if [[ -z LOGNAME ]]
then
echo "Username: Required"
exit 1
else
USER=$LOGNAME
fi
else
USER=$SUDO_USER
fi
fi
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/sys/health)
if [[ $VAULT_STATUS -eq 200 ]]
then
IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN)
if [[ $IDM_STATUS -eq 301 ]]
then
echo "Organization: $ORG"
if [[ -z $USER || $USER == "root" || $USER == "local" ]]
then
echo -n "Username: "
read USERNAME
else
echo "Username: $USER"
USERNAME=$USER
fi
echo -n "Password: "
read -s PASSWORD
echo -n "****************"
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"
exit 1
fi
else
echo "Organization: $ORG"
echo "Status: IDM Offline"
exit 1
fi
else
echo "Organization: $ORG"
echo "Status: Vault Offline"
exit 1
fi
# VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://vault.$DOMAIN/v1/sys/health)
# if [[ $VAULT_STATUS -eq 200 ]]; then
# export VAULT_ADDR="https://vault.$DOMAIN"
# VAULT_LOGIN=$(vault token lookup -address=https://vault.$DOMAIN 2> /dev/null)
# if [[ -z $VAULT_LOGIN ]]; then
# IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://idm.$DOMAIN)
# if [[ $IDM_STATUS -eq 301 ]]; then
# echo "vault.$DOMAIN - Login"
# echo "Username: $USER"
# echo -n "Password: "
# export VAULT_ADDR="https://vault.$DOMAIN"
# VAULT_LOGIN=$(vault login -address=https://vault.$DOMAIN -method=ldap username=$USER 2> /dev/null)
# echo ""
# if [[ -z $VAULT_LOGIN ]]; then
# exit 1
# fi
# else
# echo "vault.$DOMAIN - Login"
# echo -n "Token: "
# export VAULT_ADDR="https://vault.$DOMAIN"
# VAULT_LOGIN=$(vault login -address=https://vault.$DOMAIN -method=token 2> /dev/null)
# echo ""
# if [[ -z $VAULT_LOGIN || ${#VAULT_TOKEN} -lt 95 || ${#VAULT_TOKEN} -gt 95 ]]; then
# exit 1
# fi
# fi
# fi
# fi
# if [[ $USER == "root" || $USER == "local" ]]
# then
# echo "Status: Login Failed"
# fi
start
}
stop () {
if [[ -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
else
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
echo " "
echo " "
exit 1
}
{{ ELEMENTS }}
{{ FUNCTIONS }}
{{ COMMANDS }}
start
if [[ ! -z $1 ]] && [[ $(type -t warencli-$1) == function ]]
wx-start
if [[ ! -z $1 ]] && [[ $(type -t wx-$1) == function ]]
then
warencli-$1 $2 $3 $4 $5 $6 $7 $8 $9
wx-login
wx-start
wx-$1 $2 $3 $4 $5 $6 $7 $8 $9
else
wx-welcome
fi
stop
wx-stop

View File

@ -1,4 +1,5 @@
warencli-help() {
wx-help() {
echo -n ">>> Help <<<";
echo "
Usage: $0 COMMAND [OPTIONS]

View File

@ -1,3 +1,3 @@
warencli-settings() {
echo ">>> Settings <<<";
wx-settings() {
echo -n ">>> Settings <<<";
}

View File

@ -1,3 +1,3 @@
warencli-ssh() {
echo ">>> SSH <<<";
wx-ssh() {
echo -n ">>> SSH <<<";
}

View File

@ -1,3 +1,3 @@
warencli-ssh-config(){
echo ">>> SSH: Config <<<"
wx-ssh-config(){
echo -n ">>> SSH: Config <<<"
}

View File

@ -1,3 +1,3 @@
warencli-ssh-sign(){
echo ">>> SSH: Certificates <<<"
wx-ssh-sign(){
echo -n ">>> SSH: Certificates <<<"
}

3
src/commands/welcome.sh Normal file
View File

@ -0,0 +1,3 @@
wx-welcome() {
echo -n ">>> Welcome <<<"
}

6
src/elements.sh Normal file
View File

@ -0,0 +1,6 @@
wx-elements-line-douple () {
echo "=============================="
}
wx-elements-line-single () {
echo "------------------------------"
}

143
src/functions/login.sh Normal file
View File

@ -0,0 +1,143 @@
wx-login() {
echo ">>> Login <<<"
ORG=$2
if [[ -z "$HOSTNAME" || ${#HOSTNAME} -lt 5 ]]; then
stop
fi
if [[ $(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 [[ -z $ORG ]]
then
echo "Organization: Required"
stop
fi
if [[ $ORG == "warengroup" ]]
then
DOMAIN=waren.io
elif [[ $ORG == "cwinfo" ]]
then
DOMAIN=cwinfo.net
elif [[ $ORG == "cwchristerw" ]]
then
DOMAIN=christerwaren.fi
else
echo "Organization: Unsupported"
stop
fi
FOLDER=$ORG
DEVICE_DOMAIN="devices.$DOMAIN"
IDM_DOMAIN="idm.cwinfo.net"
VAULT_DOMAIN="vault.cwinfo.net"
GIT_DOMAIN="git.cwinfo.net"
if [[ $(hostname -d) ]]
then
HOSTNAME=$(hostname --fqdn)
elif [[ -z $(hostname -d) ]] && [[ ! -z $2 ]]
then
HOSTNAME="$2.$DEVICE_DOMAIN"
else
echo "Hostname: Required"
stop
fi
if [[ -z $USER ]]
then
if [[ -z $SUDO_USER ]]
then
if [[ -z LOGNAME ]]
then
echo "Username: Required"
stop
else
USER=$LOGNAME
fi
else
USER=$SUDO_USER
fi
fi
VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$VAULT_DOMAIN/v1/sys/health)
if [[ $VAULT_STATUS -eq 200 ]]
then
IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN)
if [[ $IDM_STATUS -eq 301 ]]
then
echo "Organization: $ORG"
if [[ -z $USER || $USER == "root" || $USER == "local" ]]
then
echo -n "Username: "
read USERNAME
else
echo "Username: $USER"
USERNAME=$USER
fi
echo -n "Password: "
read -s PASSWORD
echo "****************"
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"
stop
fi
echo ""
else
echo "Organization: $ORG"
echo "Status: IDM Offline"
stop
fi
else
echo "Organization: $ORG"
echo "Status: Vault Offline"
stop
fi
# VAULT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://vault.$DOMAIN/v1/sys/health)
# if [[ $VAULT_STATUS -eq 200 ]]; then
# export VAULT_ADDR="https://vault.$DOMAIN"
# VAULT_LOGIN=$(vault token lookup -address=https://vault.$DOMAIN 2> /dev/null)
# if [[ -z $VAULT_LOGIN ]]; then
# IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://idm.$DOMAIN)
# if [[ $IDM_STATUS -eq 301 ]]; then
# echo "vault.$DOMAIN - Login"
# echo "Username: $USER"
# echo -n "Password: "
# export VAULT_ADDR="https://vault.$DOMAIN"
# VAULT_LOGIN=$(vault login -address=https://vault.$DOMAIN -method=ldap username=$USER 2> /dev/null)
# echo ""
# if [[ -z $VAULT_LOGIN ]]; then
stop
# fi
# else
# echo "vault.$DOMAIN - Login"
# echo -n "Token: "
# export VAULT_ADDR="https://vault.$DOMAIN"
# VAULT_LOGIN=$(vault login -address=https://vault.$DOMAIN -method=token 2> /dev/null)
# echo ""
# if [[ -z $VAULT_LOGIN || ${#VAULT_TOKEN} -lt 95 || ${#VAULT_TOKEN} -gt 95 ]]; then
# stop
# fi
# fi
# fi
# fi
# if [[ $USER == "root" || $USER == "local" ]]
# then
# echo "Status: Login Failed"
# fi
}

8
src/functions/start.sh Normal file
View File

@ -0,0 +1,8 @@
wx-start() {
echo ""
echo ""
echo ""
wx-elements-line-douple
echo "Warén CLI"
wx-elements-line-douple
}

19
src/functions/stop.sh Normal file
View File

@ -0,0 +1,19 @@
wx-stop () {
echo " "
echo " "
echo " "
if [[ -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
else
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
exit 1
}

96
wx
View File

@ -5,25 +5,14 @@ if [ ! "$BASH_VERSION" ] ; then
exit 1
fi
syntax-line-douple() {
echo -n "
==============================
"
wx-elements-line-douple () {
echo "=============================="
}
wx-elements-line-single () {
echo "------------------------------"
}
syntax-line-single() {
echo -n "
------------------------------
"
}
start() {
syntax-line-douple
echo -n "Warén CLI "
syntax-line-douple
}
login() {
wx-login() {
echo ">>> Login <<<"
ORG=$2
@ -43,7 +32,7 @@ login() {
elif [[ -z $ORG ]]
then
echo "Organization: Required"
exit 1
stop
fi
if [[ $ORG == "warengroup" ]]
@ -57,7 +46,7 @@ login() {
DOMAIN=christerwaren.fi
else
echo "Organization: Unsupported"
exit 1
stop
fi
FOLDER=$ORG
@ -74,7 +63,7 @@ login() {
HOSTNAME="$2.$DEVICE_DOMAIN"
else
echo "Hostname: Required"
exit 1
stop
fi
if [[ -z $USER ]]
@ -84,7 +73,7 @@ login() {
if [[ -z LOGNAME ]]
then
echo "Username: Required"
exit 1
stop
else
USER=$LOGNAME
fi
@ -111,21 +100,22 @@ login() {
echo -n "Password: "
read -s PASSWORD
echo -n "****************"
echo "****************"
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"
exit 1
stop
fi
echo ""
else
echo "Organization: $ORG"
echo "Status: IDM Offline"
exit 1
stop
fi
else
echo "Organization: $ORG"
echo "Status: Vault Offline"
exit 1
stop
fi
@ -144,7 +134,7 @@ login() {
# VAULT_LOGIN=$(vault login -address=https://vault.$DOMAIN -method=ldap username=$USER 2> /dev/null)
# echo ""
# if [[ -z $VAULT_LOGIN ]]; then
# exit 1
stop
# fi
# else
# echo "vault.$DOMAIN - Login"
@ -153,7 +143,7 @@ login() {
# VAULT_LOGIN=$(vault login -address=https://vault.$DOMAIN -method=token 2> /dev/null)
# echo ""
# if [[ -z $VAULT_LOGIN || ${#VAULT_TOKEN} -lt 95 || ${#VAULT_TOKEN} -gt 95 ]]; then
# exit 1
# stop
# fi
# fi
# fi
@ -164,10 +154,21 @@ login() {
# then
# echo "Status: Login Failed"
# fi
start
}
stop () {
wx-start() {
echo ""
echo ""
echo ""
wx-elements-line-douple
echo "Warén CLI"
wx-elements-line-douple
}
wx-stop () {
echo " "
echo " "
echo " "
if [[ -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
@ -181,12 +182,11 @@ stop () {
fi
sudo chmod +x /usr/bin/wx &> /dev/null
fi
echo " "
echo " "
exit 1
}
warencli-help() {
wx-help() {
echo -n ">>> Help <<<";
echo "
Usage: $0 COMMAND [OPTIONS]
@ -200,26 +200,34 @@ Management Commands:
";
}
warencli-settings() {
echo ">>> Settings <<<";
wx-settings() {
echo -n ">>> Settings <<<";
}
warencli-ssh() {
echo ">>> SSH <<<";
wx-ssh() {
echo -n ">>> SSH <<<";
}
warencli-ssh-config(){
echo ">>> SSH: Config <<<"
wx-welcome() {
echo -n ">>> Welcome <<<"
}
warencli-ssh-sign(){
echo ">>> SSH: Certificates <<<"
wx-ssh-config(){
echo -n ">>> SSH: Config <<<"
}
wx-ssh-sign(){
echo -n ">>> SSH: Certificates <<<"
}
start
if [[ ! -z $1 ]] && [[ $(type -t warencli-$1) == function ]]
wx-start
if [[ ! -z $1 ]] && [[ $(type -t wx-$1) == function ]]
then
warencli-$1 $2 $3 $4 $5 $6 $7 $8 $9
wx-login
wx-start
wx-$1 $2 $3 $4 $5 $6 $7 $8 $9
else
wx-welcome
fi
stop
wx-stop