TMUX
# CREATE NEW SESSION
tmux new -s runner
# DETACH SESSION (= EXIT W/O END THE SESSION)
STRG + B + :detach
# LIST EXISTING SESSIONS
tmux ls
# ATTACH EXISTING SESSION
tmux a -t runner
REMOVE QUOTES FROM STRING
echo inventory: 10.31.102.119", "10.31.102.111", "10.31.102.110 | sed 's/.\(.*\)/\0/'
REMOVE SPACE FROM STRING
echo " 3918912k " | sed 's/ //g'
EXTRACT TAR.XZ
tar -xf podlet-x86_64-unknown-linux-gnu.tar.xz
APPEND TEXT TO FIRST LINE OF FILE
echo 'vsphere_vm_template="/path/to/template"' | cat - /tmp/vsphere-vm-tfvars.tpl
TAR CURRENT DIR
artifact_name=$(basename $PWD).tar.gz
touch ${artifact_name}
tar -czf ${artifact_name} --exclude=${artifact_name} .
SPLIT DELIMITED STRING
branch=ubuntu23-labda-vsphere
echo $(echo $branch | cut -d "-" -f 1) #ubuntu23
echo $(echo $branch | cut -d "-" -f 2) #labda
echo $(echo $branch | cut -d "-" -f 3) #vsphere
SEARCH FOR PATTERN IN SUBFOLDERS
SEARCH_PATH="/home/sthings/projects/ansible/test/collections/ansible_collections/sthings/deploy_rke/roles"
grep -A2 -B2 -Hrn 'ansible.builtin.include_role' ${SEARCH_PATH}
PRINT ARRAY IN ONE LINE w/ JQ
files=(one two three)
jq -c -n '$ARGS.positional' --args "${files[@]}"
EXTRACTING A STRING BETWEEN LAST TWO SLASHES IN BASH
string='/a/b/c/d/e' # initial data
dir=${string%/*} # trim everything past the last /
dir=${dir##*/} # ...then remove everything before the last / remaining
printf '%s\n' "$dir" # demonstrate output
CHECK FOR VALUES IN ARRAY / EXCLUDE FROM ARRAY
#! /bin/bash
DIR="/home/sthings/projects/ansible/test/roles"
DIRS=$(ls ${DIR})
EXCLUDE_ROLE="configure_rke_node"
ALL_ROLES=$(echo ${DIRS[@]/$EXCLUDE_ROLE})
CHECK_FOR="download_install_binary"
if [[ ${DIRS[@]/$ALL_ROLES} =~ $CHECK_FOR ]]
then
echo "ROLE FOUND"
else
echo "ROLE NOT FOUND"
fi
SEARCH AND REPLACE IN LOOP
# GET ALL FILES
all_files=$(find test/install-configure-docker -type f)
# ECHO ALL FILES
echo $all_files
# SET NAMES
old=install-configure-docker
new=install_configure_docker
sed -i "s/${old}/${new}/g" $all_files
FIND, SEARCH AND REPLACE
# SEARCH FOR ALL FILES IN (SUB-)FOLDERS
find sthings/deploy_rke/roles/install_cofigure_docker -type f
# SEARCH AND REPLACE FOR ALL (FOUND) FILES IN (SUB-)FOLDERS
sed -i 's/install-configure-docker/install_configure_docker/g' $(find sthings/deploy_rke/roles/install_cofigure_docker -type f)
STATIC IP UBUNTU23
sudo cat <<EOF > /etc/netplan/00-installer-config.yaml
network:
version: 2
renderer: networkd
ethernets:
ens192:
dhcp4: false
dhcp6: false
addresses:
- 10.100.136.210/24
routes:
- to: default
via: 10.100.136.254
nameservers:
addresses: [10.100.101.5]
EOF
sudo chmod 600 /etc/netplan/00-installer-config.yaml
sudo netplan --debug apply
CUT FOLDERPATH W/ SED FROM URL
git clone https://github.com/stuttgart-things/stuttgart-things.git
cd $(echo $(params.REPO_URL) | sed 's|.*/||' | sed 's/.git//g')
# https://github.com/stuttgart-things/stuttgart-things.git -> stuttgart-things
SPLIT STRINGS BY DELIMITER (+-) W/ AWK
path=$(awk -F+- '{print $1}' <<< 'git/data/github:token+-false+-GITHUB_TOKEN') # =git/data/github:token
convert=$(awk -F+- '{print $2}' <<< 'git/data/github:token+-false+-GITHUB_TOKEN') # =false
token=$(awk -F+- '{print $3}' <<< 'git/data/github:token+-false+-GITHUB_TOKEN') # =GITHUB_TOKEN
LOOP OVER PARAMETERS W/ SET + FOR LOOP
set great foo bar # set parameters
echo "$@" # test output
for argument in "$@"; do echo $argument ; done # loop over parameters
# loop over parameters andchange +- to : w/ sed
for argument in "$@"; do echo $argument | sed -e "s/+-/: /g" ; done
CONCATENATE SET PARAMETERS + FOR LOOP
set 'scanners vuln' 'timeout 30m'
output=" "; for argument in "$@"; do output=${output}'--'$argument' '; done
echo ${output} #--scanners vuln --timeout 30m
INSTALL PUB CERTS
# UBUNTU/ALPINE
VAULT_URL_LABUL=https://vault.labul.sva.de:8200
VAULT_URL_LABDA=https://vault.tiab.labda.sva.de:8200
VAULT_URL_LABUL_VSPHERE=https://vault-vsphere.labul.sva.de:8200
VAULT_URL_LABUL_PVE=https://vault-pve.labul.sva.de:8200
VAULT_URL_LABDA_VSPHERE=https://vault-vsphere.tiab.labda.sva.de:8200
# INSTALL VAULT CERTS
sudo wget -O /usr/local/share/ca-certificates/labul-ca.crt ${VAULT_URL_LABUL}/v1/pki/ca/pem --no-check-certificate \
sudo wget -O /usr/local/share/ca-certificates/labda-ca.crt ${VAULT_URL_LABDA}/v1/pki/ca/pem --no-check-certificate \
sudo wget -O /usr/local/share/ca-certificates/labul-vsphere-ca.crt ${VAULT_URL_LABUL_VSPHERE}/v1/pki/ca/pem --no-check-certificate \
sudo wget -O /usr/local/share/ca-certificates/labda-vsphere-ca.crt ${VAULT_URL_LABDA_VSPHERE}/v1/pki/ca/pem --no-check-certificate \
sudo wget -O /usr/local/share/ca-certificates/labul-pve.crt ${VAULT_URL_LABUL_PVE}/v1/pki/ca/pem --no-check-certificate \
sudo update-ca-certificates
GET VERSION NUMBER W/ AWK
python3 --version # Python 3.10.12
python3 --version | awk '{print $2}' # 3.10.12
UNTIL LOOP
#!/bin/bash
until skopeo inspect docker://registry.fedoraproject.org/fedora:latest
do
echo checking..
sleep 1
done
CHECK TEKTON PIPELINERUN STATUS IN WHILE LOOP W/ OPERATORS
#!/bin/bash
sleep=10
failed_prs=0
succeeded_prs=0
retries=0
max_retries=3
all_prs=$(tkn pr list -n tektoncd | grep -c alpine)
echo all pipelineRuns: ${all_prs}
while [[ ${failed_prs} -le 0 ]] || [[ ${succeeded_prs} -eq ${all_prs} ]] || [[ ${retries} -eq ${max_retries} ]]
do
echo ${retries_left} retries left
echo check/retry in ${sleep} seconds..
sleep ${sleep}
failed_prs=$(tkn pr list -n tektoncd | grep alpine | grep -c Failed)
echo Failed pipelineRuns: ${failed_prs}
tkn pr list -n tektoncd | grep alpine | grep Failed
succeeded_prs=$(tkn pr list -n tektoncd | grep alpine | grep -c Succeeded)
echo Succeeded pipelineRuns: ${succeeded_prs}
tkn pr list -n tektoncd | grep alpine | grep Succeeded
retries=`expr ${retries} + 1`
retries_left=`expr ${max_retries} - ${retries}`
done
echo "Done watching pipelineRuns!"
echo Failed pipelineRuns: ${failed_prs}
echo Succeeded pipelineRuns: ${succeeded_prs}
DHCP Network config
cat <<EOF > 99_config.yaml
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: true
EOF
sudo netplan apply
Enable ssh password authentication
vi /etc/ssh/sshd_config
# set this variable to yes to allow passwords
PaswordAuthentication yes
# Restart Service
sudo systemctl restart ssh
# Copy public key to remote machine
ssh-copy-id [email protected]