Compare commits

..

25 Commits

Author SHA1 Message Date
ff4bebdc53 Move wi-restricted function to base and fix bash version execution 2025-06-28 15:14:49 +03:00
d9a7864199 Fix running init.sh in non root user 2025-06-28 14:34:59 +03:00
03bba2ba7f Code Update 2025-06-26 23:08:49 +03:00
e75b95abac Code Update 2025-06-23 09:36:34 +03:00
73025e14d8 Code Update 2025-06-22 01:49:56 +03:00
0cdc32a743 Code Update 2025-06-22 00:45:15 +03:00
196a4ef2eb Move Hostname variable to init function 2025-06-21 23:48:10 +03:00
2220092a87 Code Update 2025-05-10 11:30:44 +03:00
746ae8ebf4 Code Update 2025-05-04 19:12:02 +03:00
944e9f020c Code Update 2025-01-05 02:45:16 +02:00
eb5f7980de Update copyright year 2025-01-01 18:00:36 +02:00
4111068772 Add epel-release to dependencies because lsb_release is only available in EPEL 2024-11-23 04:44:52 +02:00
b383c1ddd0 Add lsb_release to Ansible dependencies 2024-11-23 01:10:33 +02:00
280928e133 Install required packages in Rocky Linux 2024-11-22 04:45:08 +02:00
5e3d337b2c Add directory to ansible-pull command 2024-11-20 05:36:21 +02:00
28f807fb44 Code Update: Add extra vars to ansible-pull command 2024-10-06 22:49:32 +03:00
b236fdb65b Code Update 2024-09-26 18:19:53 +03:00
e0e25ef1ac Code Update 2024-07-01 06:23:18 +03:00
206bbbad1c Code Update 2024-07-01 02:21:11 +03:00
0ca9ad28dc Code Update 2024-06-30 17:42:08 +03:00
04699cccce Code Update 2024-06-30 17:19:43 +03:00
3488bb794d Code Update 2024-06-30 17:05:38 +03:00
6e11dc8e8e Code Update 2024-06-30 17:03:46 +03:00
605366d786 Code Update 2024-06-30 16:57:14 +03:00
e76cd7f45e Documentation Update 2024-06-30 16:56:57 +03:00
8 changed files with 149 additions and 117 deletions

View File

@ -1,6 +1,6 @@
MIT License 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 Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -3,10 +3,11 @@
## Run Command ## Run Command
``` ```
curl https://waren.io/init.sh -o init.sh curl https://waren.io/init.sh -o init.sh
bash init.sh chmod +x init.sh
./init.sh
``` ```
## Build Command ## Maintaining Command
``` ```
bash build.sh ./maintainer.sh
``` ```

129
init.sh
View File

@ -1,7 +1,15 @@
#!/bin/bash #!/bin/bash
if [ ! "$BASH_VERSION" ] ; then if [ ! "$BASH_VERSION" ] ; then
bash $0 $1 $2 $3 $4 $5 $6 $7 $8 $9 sudo curl https://waren.io/init.sh -o $PWD/init.sh
sudo bash $PWD/init.sh $1 $2 $3 $4 $5 $6 $7 $8 $9
exit 1
fi
if [[ $USER != "root" ]]
then
sudo curl https://waren.io/init.sh -o $PWD/init.sh
sudo bash $PWD/init.sh $1 $2 $3 $4 $5 $6 $7 $8 $9
exit 1 exit 1
fi fi
@ -65,14 +73,29 @@ wx-header(){
} }
wi-init(){ wi-init(){
wi-login $1 $2 wi-login $1
wi-header "Init" wi-header "Init"
if [[ ! -z $2 && ${#2} -gt 5 ]]
then
HOSTNAME="$2.$DEVICE_DOMAIN"
elif [[ $(hostname -d) ]]
then
HOSTNAME=$(hostname --fqdn)
else
echo "Status: Hostname Required"
wx-stop
fi
mkdir -p ~/.ssh/keys &> /dev/null mkdir -p ~/.ssh/keys &> /dev/null
apt-get install -y python3-pip python3-venv jq git curl &> /dev/null apt-get update &> /dev/null
apt-get install -y python3-pip python3-venv jq git curl lsb-release &> /dev/null
dnf install -y epel-release &> /dev/null
dnf install -y python3-pip jq git curl lsb_release &> /dev/null
python3 -m venv /opt/ansible &> /dev/null python3 -m venv /opt/ansible &> /dev/null
/opt/ansible/bin/pip3 install ansible hvac netaddr jmespath pexpect &> /dev/null /opt/ansible/bin/pip3 install ansible &> /dev/null
/opt/ansible/bin/pip3 install cryptography dnspython hvac jmespath netaddr pexpect &> /dev/null
curl \ curl \
-H "X-Vault-Token: ${config["login",$ORG]}" \ -H "X-Vault-Token: ${config["login",$ORG]}" \
@ -85,20 +108,12 @@ wi-init(){
if [ ! -f ~/.ansible/vars.yml ] if [ ! -f ~/.ansible/vars.yml ]
then then
openssl rand -base64 64 | tr -d '\n' | head -c 64 > ~/.ansible/vault.yml
ANSIBLE_VAULT_SECRET=$(<~/.ansible/vault.yml)
echo "---" > ~/.ansible/vars.yml echo "---" > ~/.ansible/vars.yml
echo "hostname: $HOSTNAME" >> ~/.ansible/vars.yml echo "hostname: $HOSTNAME" >> ~/.ansible/vars.yml
echo "folder: /$FOLDER/" >> ~/.ansible/vars.yml echo "config:" >> ~/.ansible/vars.yml
echo "vault:" >> ~/.ansible/vars.yml echo " identity:" >> ~/.ansible/vars.yml
echo " ansible:" >> ~/.ansible/vars.yml echo " vault:" >> ~/.ansible/vars.yml
echo " secret: $ANSIBLE_VAULT_SECRET" >> ~/.ansible/vars.yml echo " domain: $VAULT_DOMAIN" >> ~/.ansible/vars.yml
echo " hashicorp:" >> ~/.ansible/vars.yml
echo " domain: $VAULT_DOMAIN" >> ~/.ansible/vars.yml
/opt/ansible/bin/ansible-vault encrypt --vault-password-file ~/.ansible/vault.yml ~/.ansible/vars.yml > /dev/null
fi fi
GIT_DOMAIN="git.cwinfo.net" GIT_DOMAIN="git.cwinfo.net"
@ -107,24 +122,19 @@ wi-init(){
export HVT=${config["login",$ORG]} export HVT=${config["login",$ORG]}
/opt/ansible/bin/ansible-galaxy collection install ansible.posix ansible.utils community.crypto community.docker community.general community.hashi_vault community.libvirt community.mysql community.postgresql containers.podman --upgrade &> /dev/null /opt/ansible/bin/ansible-galaxy collection install ansible.posix ansible.utils community.crypto community.dns community.docker community.general community.hashi_vault community.libvirt community.mongodb community.mysql community.postgresql containers.podman --upgrade &> /dev/null
/opt/ansible/bin/ansible-pull -U ssh://git@$GIT_DOMAIN:$GIT_PORT/$GIT_REPOSITORY --accept-host-key --vault-password-file ~/.ansible/vault.yml --private-key ~/.ssh/keys/init 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 playbooks/init.yml -t init
unset HVT unset HVT
} }
wx-login(){ wx-login(){
if [[ -z "$HOSTNAME" || ${#HOSTNAME} -lt 5 ]]
then
wx-header "Login"
echo "Status: Hostname Required"
wx-stop
fi
if [[ ! -z $1 ]] if [[ ! -z $1 ]]
then then
ORG=$1 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" ]] elif [[ $(hostname -d) = *"devices.waren.io" ]]
then then
ORG=warengroup ORG=warengroup
@ -134,6 +144,9 @@ wx-login(){
elif [[ $(hostname -d) = *"devices.christerwaren.fi" ]] elif [[ $(hostname -d) = *"devices.christerwaren.fi" ]]
then then
ORG=cwchristerw 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 else
wx-header "Login" wx-header "Login"
echo "Status: Organization Required" echo "Status: Organization Required"
@ -157,21 +170,9 @@ wx-login(){
FOLDER=$ORG FOLDER=$ORG
DEVICE_DOMAIN="devices.$DOMAIN" DEVICE_DOMAIN="devices.$DOMAIN"
IDM_DOMAIN="idm.cwinfo.net" IDM_DOMAIN="idm.waren.io"
VAULT_DOMAIN="vault.cwinfo.net" VAULT_DOMAIN="vault.cwinfo.net"
if [[ ! -z $2 ]]
then
HOSTNAME="$2.$DEVICE_DOMAIN"
elif [[ $(hostname -d) ]]
then
HOSTNAME=$(hostname --fqdn)
else
wx-header "Login"
echo "Status: Hostname Required"
wx-stop
fi
if [[ -z $USER || $USER == "root" || $USER == "local" ]] if [[ -z $USER || $USER == "root" || $USER == "local" ]]
then then
if [[ -z $SUDO_USER ]] if [[ -z $SUDO_USER ]]
@ -195,9 +196,13 @@ wx-login(){
if [[ $VAULT_STATUS -eq 200 ]] if [[ $VAULT_STATUS -eq 200 ]]
then then
if [[ $USER != "root" && $USER != "local" && -f "$HOME/.config/warengroup/config.json" ]] if [[ $USER != "root" && $USER != "local" && -f "$HOME/.warengroup/config.json" ]]
then then
TOKEN="$(cat $HOME/.config/warengroup/config.json | jq -r .login.$ORG)" 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 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') 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')
@ -206,8 +211,8 @@ wx-login(){
config["login",${ORG}]=$VAULT_LOGIN config["login",${ORG}]=$VAULT_LOGIN
if [[ $USER != "root" && $USER != "local" ]] if [[ $USER != "root" && $USER != "local" ]]
then then
jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json 1> $HOME/.config/warengroup/config.json.tmp jq '.login.'$ORG'.token = "'$VAULT_LOGIN'"' $HOME/.warengroup/config.json 1> $HOME/.warengroup/config.json.tmp
mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null mv $HOME/.warengroup/config.json.tmp $HOME/.warengroup/config.json &> /dev/null
fi fi
else else
IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN) IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN)
@ -216,7 +221,7 @@ wx-login(){
wx-header "Login" wx-header "Login"
echo $wxBold$ORG$wxNormal echo $wxBold$ORG$wxNormal
if [[ -z $USERNAME || $USERNAME == "root" || $USERNAME == "local" ]] if [[ -z $USERNAME || $USERNAME == "root" || $USERNAME == "local" || $USERNAME == "nobody" ]]
then then
echo -n "Username: " echo -n "Username: "
read USERNAME read USERNAME
@ -224,6 +229,9 @@ wx-login(){
echo "Username: $USERNAME" echo "Username: $USERNAME"
fi 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: " echo -n "Password: "
read -s PASSWORD read -s PASSWORD
echo "****************" echo "****************"
@ -244,8 +252,8 @@ wx-login(){
if [[ $USER != "root" && $USER != "local" ]] if [[ $USER != "root" && $USER != "local" ]]
then then
jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp jq '.login.'$ORG'.token = "'$VAULT_LOGIN'"' $HOME/.warengroup/config.json &> $HOME/.warengroup/config.json.tmp
mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null mv $HOME/.warengroup/config.json.tmp $HOME/.warengroup/config.json &> /dev/null
fi fi
fi fi
else else
@ -273,8 +281,8 @@ wx-login(){
if [[ $USER != "root" && $USER != "local" ]] if [[ $USER != "root" && $USER != "local" ]]
then then
jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp jq '.login.'$ORG'.token = "'$VAULT_LOGIN'"' $HOME/.warengroup/config.json &> $HOME/.warengroup/config.json.tmp
mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null mv $HOME/.warengroup/config.json.tmp $HOME/.warengroup/config.json &> /dev/null
fi fi
fi fi
fi fi
@ -292,16 +300,18 @@ wx-repeat() {
printf "%s" "${spaces// /$str}" printf "%s" "${spaces// /$str}"
} }
wi-restricted(){
if [[ $USER != "root" && $USER != "local" ]]
then
sudo $1
exit 1
fi
}
wi-start(){ wi-start(){
wi-header "Warén Group" h1 wi-header "Warén Init" 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
} }
wi-stop (){ wi-stop (){
@ -315,6 +325,11 @@ wi-stop (){
} }
wi-restricted "$0 $1 $2" if [[ ! -f /bin/jq ]]
then
apt update &> /dev/null
apt install -y jq &> /dev/null
fi
wi-init $1 $2 wi-init $1 $2
wi-stop wi-stop

View File

@ -1,7 +1,15 @@
#!/bin/bash #!/bin/bash
if [ ! "$BASH_VERSION" ] ; then if [ ! "$BASH_VERSION" ] ; then
bash $0 $1 $2 $3 $4 $5 $6 $7 $8 $9 sudo curl https://waren.io/init.sh -o $PWD/init.sh
sudo bash $PWD/init.sh $1 $2 $3 $4 $5 $6 $7 $8 $9
exit 1
fi
if [[ $USER != "root" ]]
then
sudo curl https://waren.io/init.sh -o $PWD/init.sh
sudo bash $PWD/init.sh $1 $2 $3 $4 $5 $6 $7 $8 $9
exit 1 exit 1
fi fi
@ -18,6 +26,11 @@ wiNormal=$(tput sgr0)
{{ CODES }} {{ CODES }}
wi-restricted "$0 $1 $2" if [[ ! -f /bin/jq ]]
then
apt update &> /dev/null
apt install -y jq &> /dev/null
fi
wi-init $1 $2 wi-init $1 $2
wi-stop wi-stop

View File

@ -1,12 +1,27 @@
wi-init(){ wi-init(){
wi-login $1 $2 wi-login $1
wi-header "Init" wi-header "Init"
if [[ ! -z $2 && ${#2} -gt 5 ]]
then
HOSTNAME="$2.$DEVICE_DOMAIN"
elif [[ $(hostname -d) ]]
then
HOSTNAME=$(hostname --fqdn)
else
echo "Status: Hostname Required"
wx-stop
fi
mkdir -p ~/.ssh/keys &> /dev/null mkdir -p ~/.ssh/keys &> /dev/null
apt-get install -y python3-pip python3-venv jq git curl &> /dev/null apt-get update &> /dev/null
apt-get install -y python3-pip python3-venv jq git curl lsb-release &> /dev/null
dnf install -y epel-release &> /dev/null
dnf install -y python3-pip jq git curl lsb_release &> /dev/null
python3 -m venv /opt/ansible &> /dev/null python3 -m venv /opt/ansible &> /dev/null
/opt/ansible/bin/pip3 install ansible hvac netaddr jmespath pexpect &> /dev/null /opt/ansible/bin/pip3 install ansible &> /dev/null
/opt/ansible/bin/pip3 install cryptography dnspython hvac jmespath netaddr pexpect &> /dev/null
curl \ curl \
-H "X-Vault-Token: ${config["login",$ORG]}" \ -H "X-Vault-Token: ${config["login",$ORG]}" \
@ -19,20 +34,12 @@ wi-init(){
if [ ! -f ~/.ansible/vars.yml ] if [ ! -f ~/.ansible/vars.yml ]
then then
openssl rand -base64 64 | tr -d '\n' | head -c 64 > ~/.ansible/vault.yml
ANSIBLE_VAULT_SECRET=$(<~/.ansible/vault.yml)
echo "---" > ~/.ansible/vars.yml echo "---" > ~/.ansible/vars.yml
echo "hostname: $HOSTNAME" >> ~/.ansible/vars.yml echo "hostname: $HOSTNAME" >> ~/.ansible/vars.yml
echo "folder: /$FOLDER/" >> ~/.ansible/vars.yml echo "config:" >> ~/.ansible/vars.yml
echo "vault:" >> ~/.ansible/vars.yml echo " identity:" >> ~/.ansible/vars.yml
echo " ansible:" >> ~/.ansible/vars.yml echo " vault:" >> ~/.ansible/vars.yml
echo " secret: $ANSIBLE_VAULT_SECRET" >> ~/.ansible/vars.yml echo " domain: $VAULT_DOMAIN" >> ~/.ansible/vars.yml
echo " hashicorp:" >> ~/.ansible/vars.yml
echo " domain: $VAULT_DOMAIN" >> ~/.ansible/vars.yml
/opt/ansible/bin/ansible-vault encrypt --vault-password-file ~/.ansible/vault.yml ~/.ansible/vars.yml > /dev/null
fi fi
GIT_DOMAIN="git.cwinfo.net" GIT_DOMAIN="git.cwinfo.net"
@ -41,9 +48,9 @@ wi-init(){
export HVT=${config["login",$ORG]} export HVT=${config["login",$ORG]}
/opt/ansible/bin/ansible-galaxy collection install ansible.posix ansible.utils community.crypto community.docker community.general community.hashi_vault community.libvirt community.mysql community.postgresql containers.podman --upgrade &> /dev/null /opt/ansible/bin/ansible-galaxy collection install ansible.posix ansible.utils community.crypto community.dns community.docker community.general community.hashi_vault community.libvirt community.mongodb community.mysql community.postgresql containers.podman --upgrade &> /dev/null
/opt/ansible/bin/ansible-pull -U ssh://git@$GIT_DOMAIN:$GIT_PORT/$GIT_REPOSITORY --accept-host-key --vault-password-file ~/.ansible/vault.yml --private-key ~/.ssh/keys/init 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 playbooks/init.yml -t init
unset HVT unset HVT
} }

View File

@ -1,14 +1,9 @@
wx-login(){ wx-login(){
if [[ -z "$HOSTNAME" || ${#HOSTNAME} -lt 5 ]]
then
wx-header "Login"
echo "Status: Hostname Required"
wx-stop
fi
if [[ ! -z $1 ]] if [[ ! -z $1 ]]
then then
ORG=$1 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" ]] elif [[ $(hostname -d) = *"devices.waren.io" ]]
then then
ORG=warengroup ORG=warengroup
@ -18,6 +13,9 @@ wx-login(){
elif [[ $(hostname -d) = *"devices.christerwaren.fi" ]] elif [[ $(hostname -d) = *"devices.christerwaren.fi" ]]
then then
ORG=cwchristerw 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 else
wx-header "Login" wx-header "Login"
echo "Status: Organization Required" echo "Status: Organization Required"
@ -41,21 +39,9 @@ wx-login(){
FOLDER=$ORG FOLDER=$ORG
DEVICE_DOMAIN="devices.$DOMAIN" DEVICE_DOMAIN="devices.$DOMAIN"
IDM_DOMAIN="idm.cwinfo.net" IDM_DOMAIN="idm.waren.io"
VAULT_DOMAIN="vault.cwinfo.net" VAULT_DOMAIN="vault.cwinfo.net"
if [[ ! -z $2 ]]
then
HOSTNAME="$2.$DEVICE_DOMAIN"
elif [[ $(hostname -d) ]]
then
HOSTNAME=$(hostname --fqdn)
else
wx-header "Login"
echo "Status: Hostname Required"
wx-stop
fi
if [[ -z $USER || $USER == "root" || $USER == "local" ]] if [[ -z $USER || $USER == "root" || $USER == "local" ]]
then then
if [[ -z $SUDO_USER ]] if [[ -z $SUDO_USER ]]
@ -79,9 +65,13 @@ wx-login(){
if [[ $VAULT_STATUS -eq 200 ]] if [[ $VAULT_STATUS -eq 200 ]]
then then
if [[ $USER != "root" && $USER != "local" && -f "$HOME/.config/warengroup/config.json" ]] if [[ $USER != "root" && $USER != "local" && -f "$HOME/.warengroup/config.json" ]]
then then
TOKEN="$(cat $HOME/.config/warengroup/config.json | jq -r .login.$ORG)" 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 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') 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')
@ -90,8 +80,8 @@ wx-login(){
config["login",${ORG}]=$VAULT_LOGIN config["login",${ORG}]=$VAULT_LOGIN
if [[ $USER != "root" && $USER != "local" ]] if [[ $USER != "root" && $USER != "local" ]]
then then
jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json 1> $HOME/.config/warengroup/config.json.tmp jq '.login.'$ORG'.token = "'$VAULT_LOGIN'"' $HOME/.warengroup/config.json 1> $HOME/.warengroup/config.json.tmp
mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null mv $HOME/.warengroup/config.json.tmp $HOME/.warengroup/config.json &> /dev/null
fi fi
else else
IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN) IDM_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://$IDM_DOMAIN)
@ -100,7 +90,7 @@ wx-login(){
wx-header "Login" wx-header "Login"
echo $wxBold$ORG$wxNormal echo $wxBold$ORG$wxNormal
if [[ -z $USERNAME || $USERNAME == "root" || $USERNAME == "local" ]] if [[ -z $USERNAME || $USERNAME == "root" || $USERNAME == "local" || $USERNAME == "nobody" ]]
then then
echo -n "Username: " echo -n "Username: "
read USERNAME read USERNAME
@ -108,6 +98,9 @@ wx-login(){
echo "Username: $USERNAME" echo "Username: $USERNAME"
fi 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: " echo -n "Password: "
read -s PASSWORD read -s PASSWORD
echo "****************" echo "****************"
@ -128,8 +121,8 @@ wx-login(){
if [[ $USER != "root" && $USER != "local" ]] if [[ $USER != "root" && $USER != "local" ]]
then then
jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp jq '.login.'$ORG'.token = "'$VAULT_LOGIN'"' $HOME/.warengroup/config.json &> $HOME/.warengroup/config.json.tmp
mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null mv $HOME/.warengroup/config.json.tmp $HOME/.warengroup/config.json &> /dev/null
fi fi
fi fi
else else
@ -157,8 +150,8 @@ wx-login(){
if [[ $USER != "root" && $USER != "local" ]] if [[ $USER != "root" && $USER != "local" ]]
then then
jq '.login.'$ORG' = "'$VAULT_LOGIN'"' $HOME/.config/warengroup/config.json &> $HOME/.config/warengroup/config.json.tmp jq '.login.'$ORG'.token = "'$VAULT_LOGIN'"' $HOME/.warengroup/config.json &> $HOME/.warengroup/config.json.tmp
mv $HOME/.config/warengroup/config.json.tmp $HOME/.config/warengroup/config.json &> /dev/null mv $HOME/.warengroup/config.json.tmp $HOME/.warengroup/config.json &> /dev/null
fi fi
fi fi
fi fi

View File

@ -1,7 +0,0 @@
wi-restricted(){
if [[ $USER != "root" && $USER != "local" ]]
then
sudo $1
exit 1
fi
}

View File

@ -1,3 +1,13 @@
wi-start(){ wi-start(){
wi-header "Warén Group" h1 wi-header "Warén Init" 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
} }