Compare commits

..

5 Commits

Author SHA1 Message Date
Christer Warén
d3277f8632 Sync Login function from WX 2026-01-22 20:25:22 +02:00
Christer Warén
40db0d7c04 Update copyright year in LICENSE 2026-01-05 02:22:29 +02:00
Christer Warén
68cda952e2 Use new Init playbook location 2025-12-30 02:03:20 +02:00
Christer Warén
655c86e508 Fix Hostname in Init script 2025-12-07 17:34:11 +02:00
Christer Warén
b544f7af1e Update Device Types feature in Init script 2025-12-07 17:19:58 +02:00
4 changed files with 47 additions and 23 deletions

View File

@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2023-2025 Warén Group
Copyright (c) 2023-2026 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

32
init.sh
View File

@@ -19,7 +19,7 @@ wx-init(){
if [[ ! -z ${args['hostname']} && ${#args['hostname']} -gt 5 ]]
then
HOSTNAME="${args['hostname']}.$DEVICE_DOMAIN"
HOSTNAME="${args['hostname']}.devices.$DOMAIN"
elif [[ $(hostname -d) ]]
then
HOSTNAME=$(hostname --fqdn)
@@ -30,9 +30,12 @@ wx-init(){
if [[ ! -z ${args['device-type']} ]]
then
if [[ ${args['device-type']} == "server" || ${args['device-type']} == "workstation" ]]
if [[ ${args['device-type']} == "server" ]]
then
DEVICE_TYPE="${args['device-type']}"
DEVICE_TYPE="Server"
elif [[ ${args['device-type']} == "workstation" ]]
then
DEVICE_TYPE="Workstation"
else
wxi-content status "Device Type" "Invalid"
wxi-stop
@@ -66,7 +69,7 @@ wx-init(){
echo "---" > ~/.ansible/vars.yml
echo "hostname: $HOSTNAME" >> ~/.ansible/vars.yml
echo "info:" >> ~/.ansible/vars.yml
echo " type: $TYPE" >> ~/.ansible/vars.yml
echo " type: $DEVICE_TYPE" >> ~/.ansible/vars.yml
echo "config:" >> ~/.ansible/vars.yml
echo " identity:" >> ~/.ansible/vars.yml
echo " vault:" >> ~/.ansible/vars.yml
@@ -81,7 +84,7 @@ wx-init(){
/opt/ansible/bin/ansible-galaxy collection install ansible.posix ansible.utils ansible.windows community.crypto community.dns community.docker community.general community.grafana community.hashi_vault community.libvirt community.mongodb community.mysql community.postgresql community.windows containers.podman --upgrade &> /dev/null
/opt/ansible/bin/ansible-pull -U ssh://git@$GIT_DOMAIN:$GIT_PORT/$GIT_REPOSITORY -d ~/.ansible/pull/infra --accept-host-key --private-key ~/.ssh/keys/init --extra-vars @~/.ansible/vars.yml playbooks/init.yml -t init
/opt/ansible/bin/ansible-pull -U ssh://git@$GIT_DOMAIN:$GIT_PORT/$GIT_REPOSITORY -d ~/.ansible/pull/infra --accept-host-key --private-key ~/.ssh/keys/init --extra-vars @~/.ansible/vars.yml init.yml -t init
unset HVT
}
@@ -100,7 +103,7 @@ wx-login(){
elif [[ ! -z ${args['token']} ]]
then
AUTH_METHOD=token
elif [[ -f "$HOME/.warengroup/config.json" && $(cat $HOME/.warengroup/config.json | jq -r .login.$ORG.token) != 'null' && $(cat $HOME/.warengroup/config.json | jq -r .login.$ORG.token) != '' ]]
elif [[ $(wxi-config login read) ]]
then
AUTH_METHOD=token
elif [[ ! -z ${args['username']} ]]
@@ -149,11 +152,12 @@ wx-login(){
if [[ -z $VAULT_LOGIN || ${#VAULT_LOGIN} -lt 95 || ${#VAULT_LOGIN} -gt 95 ]]
then
wxi-content status "Login" "Failed"
wxi-footer
wxi-stop
fi
TOKEN=$VAULT_LOGIN
wxi-config login
wxi-config login write
;;
token)
echo -n "Token: "
@@ -163,9 +167,9 @@ wx-login(){
then
TOKEN=${args['token']}
fi
elif [[ -f "$HOME/.warengroup/config.json" && $(cat $HOME/.warengroup/config.json | jq -r .login.$ORG.token) != 'null' && $(cat $HOME/.warengroup/config.json | jq -r .login.$ORG.token) != '' ]]
elif [[ $(wxi-config login read) ]]
then
TOKEN=$(cat $HOME/.warengroup/config.json | jq -r .login.$ORG.token)
TOKEN=$(wxi-config login read)
else
read -s TOKEN
fi
@@ -193,11 +197,19 @@ wx-login(){
if [[ -z $VAULT_LOGIN || ${#VAULT_LOGIN} -lt 95 || ${#VAULT_LOGIN} -gt 95 ]]
then
wxi-content status "Login" "Failed"
wxi-footer
if [[ $(wxi-config login read) ]]
then
wx-logout &> /dev/null
wx-login
else
wxi-stop
fi
fi
TOKEN=$VAULT_LOGIN
wxi-config login
wxi-config login write
;;
*)
wxi-content status "Login Type" "Unsupported"

View File

@@ -4,7 +4,7 @@ wx-init(){
if [[ ! -z ${args['hostname']} && ${#args['hostname']} -gt 5 ]]
then
HOSTNAME="${args['hostname']}.$DEVICE_DOMAIN"
HOSTNAME="${args['hostname']}.devices.$DOMAIN"
elif [[ $(hostname -d) ]]
then
HOSTNAME=$(hostname --fqdn)
@@ -15,9 +15,12 @@ wx-init(){
if [[ ! -z ${args['device-type']} ]]
then
if [[ ${args['device-type']} == "server" || ${args['device-type']} == "workstation" ]]
if [[ ${args['device-type']} == "server" ]]
then
DEVICE_TYPE="${args['device-type']}"
DEVICE_TYPE="Server"
elif [[ ${args['device-type']} == "workstation" ]]
then
DEVICE_TYPE="Workstation"
else
wxi-content status "Device Type" "Invalid"
wxi-stop
@@ -51,7 +54,7 @@ wx-init(){
echo "---" > ~/.ansible/vars.yml
echo "hostname: $HOSTNAME" >> ~/.ansible/vars.yml
echo "info:" >> ~/.ansible/vars.yml
echo " type: $TYPE" >> ~/.ansible/vars.yml
echo " type: $DEVICE_TYPE" >> ~/.ansible/vars.yml
echo "config:" >> ~/.ansible/vars.yml
echo " identity:" >> ~/.ansible/vars.yml
echo " vault:" >> ~/.ansible/vars.yml
@@ -66,7 +69,7 @@ wx-init(){
/opt/ansible/bin/ansible-galaxy collection install ansible.posix ansible.utils ansible.windows community.crypto community.dns community.docker community.general community.grafana community.hashi_vault community.libvirt community.mongodb community.mysql community.postgresql community.windows containers.podman --upgrade &> /dev/null
/opt/ansible/bin/ansible-pull -U ssh://git@$GIT_DOMAIN:$GIT_PORT/$GIT_REPOSITORY -d ~/.ansible/pull/infra --accept-host-key --private-key ~/.ssh/keys/init --extra-vars @~/.ansible/vars.yml playbooks/init.yml -t init
/opt/ansible/bin/ansible-pull -U ssh://git@$GIT_DOMAIN:$GIT_PORT/$GIT_REPOSITORY -d ~/.ansible/pull/infra --accept-host-key --private-key ~/.ssh/keys/init --extra-vars @~/.ansible/vars.yml init.yml -t init
unset HVT
}

View File

@@ -12,7 +12,7 @@ wx-login(){
elif [[ ! -z ${args['token']} ]]
then
AUTH_METHOD=token
elif [[ -f "$HOME/.warengroup/config.json" && $(cat $HOME/.warengroup/config.json | jq -r .login.$ORG.token) != 'null' && $(cat $HOME/.warengroup/config.json | jq -r .login.$ORG.token) != '' ]]
elif [[ $(wxi-config login read) ]]
then
AUTH_METHOD=token
elif [[ ! -z ${args['username']} ]]
@@ -61,11 +61,12 @@ wx-login(){
if [[ -z $VAULT_LOGIN || ${#VAULT_LOGIN} -lt 95 || ${#VAULT_LOGIN} -gt 95 ]]
then
wxi-content status "Login" "Failed"
wxi-footer
wxi-stop
fi
TOKEN=$VAULT_LOGIN
wxi-config login
wxi-config login write
;;
token)
echo -n "Token: "
@@ -75,9 +76,9 @@ wx-login(){
then
TOKEN=${args['token']}
fi
elif [[ -f "$HOME/.warengroup/config.json" && $(cat $HOME/.warengroup/config.json | jq -r .login.$ORG.token) != 'null' && $(cat $HOME/.warengroup/config.json | jq -r .login.$ORG.token) != '' ]]
elif [[ $(wxi-config login read) ]]
then
TOKEN=$(cat $HOME/.warengroup/config.json | jq -r .login.$ORG.token)
TOKEN=$(wxi-config login read)
else
read -s TOKEN
fi
@@ -105,11 +106,19 @@ wx-login(){
if [[ -z $VAULT_LOGIN || ${#VAULT_LOGIN} -lt 95 || ${#VAULT_LOGIN} -gt 95 ]]
then
wxi-content status "Login" "Failed"
wxi-footer
if [[ $(wxi-config login read) ]]
then
wx-logout &> /dev/null
wx-login
else
wxi-stop
fi
fi
TOKEN=$VAULT_LOGIN
wxi-config login
wxi-config login write
;;
*)
wxi-content status "Login Type" "Unsupported"