initial commit

This commit is contained in:
2026-01-18 10:18:49 +01:00
commit 5cdce9d5ac
4 changed files with 265 additions and 0 deletions

80
daily-review.sh Normal file
View File

@@ -0,0 +1,80 @@
#!/bin/bash
DOM=$(date +%e | tr -d ' ')
ROW=$((DOM + 1))
MONTH=$(date +%m | sed 's/^0*//')
COLUMN=$((MONTH + 1))
BASE_PATH=""
WEEK_LOG="$BASE_PATH/$(date +%Y)/$(date +%B)/$(date +%V).org"
F_OVERALL="$BASE_PATH/daily-review-overall.csv"
F_PHYSICALLY="$BASE_PATH/daily-review-physically.csv"
F_MENTALLY="$BASE_PATH/daily-review-mentally.csv"
F_WALK="$BASE_PATH/daily-review-walk.csv"
F_EXERCISE="$BASE_PATH/daily-review-exercise.csv"
V_OVERALL=0
V_PHYSICALLY=0
V_MENTALLY=0
V_WALK=0
V_EXERCISE=0
verify_paths(){
if [ ! -d "$BASE_PATH/$(date +%Y)/$(date +%B)" ]; then
mkdir -p "$BASE_PATH/$(date +%Y)/$(date +%B)"
fi
if [ ! -f "$WEEK_LOG" ]; then
touch "$WEEK_LOG"
cat >> "$WEEK_LOG" << EOF
#-*- mode: org -*-
#+STARTUP: showall
EOF
fi
}
ask_questions(){
echo "Answer the following questions with the values from this table:"
echo -e "#### Legend ####\n# 5 | Amazing #\n# 4 | Good #\n# 3 | Average #\n# 2 | Bad #\n# 1 | Terrible #\n################"
read -p "How are you feeling today physically? " V_PHYSICALLY
read -p "How are you feeling today mentally? " V_MENTALLY
read -p "How was today overall? " V_OVERALL
echo
echo "Answer the following questions with 1 (yes) or 0 (no)."
read -p "Did you go for a walk today? " V_WALK
read -p "Did you exercise today? " V_EXERCISE
}
verify_paths
ask_questions
awk -v row="$ROW" -v col="$COLUMN" -v new_value="$V_OVERALL" -F, \
'BEGIN {OFS=","} NR==row {$col=new_value} 1' \
"$F_OVERALL" > temp.csv && mv temp.csv "$F_OVERALL"
awk -v row="$ROW" -v col="$COLUMN" -v new_value="$V_PHYSICALLY" -F, \
'BEGIN {OFS=","} NR==row {$col=new_value} 1' \
"$F_PHYSICALLY" > temp.csv && mv temp.csv "$F_PHYSICALLY"
awk -v row="$ROW" -v col="$COLUMN" -v new_value="$V_MENTALLY" -F, \
'BEGIN {OFS=","} NR==row {$col=new_value} 1' \
"$F_MENTALLY" > temp.csv && mv temp.csv "$F_MENTALLY"
awk -v row="$ROW" -v col="$COLUMN" -v new_value="$V_WALK" -F, \
'BEGIN {OFS=","} NR==row {$col=new_value} 1' \
"$F_WALK" > temp.csv && mv temp.csv "$F_WALK"
awk -v row="$ROW" -v col="$COLUMN" -v new_value="$V_EXERCISE" -F, \
'BEGIN {OFS=","} NR==row {$col=new_value} 1' \
"$F_EXERCISE" > temp.csv && mv temp.csv "$F_EXERCISE"
cat >> "$WEEK_LOG" << EOF
* $(date +%A), $( date +"%d. %m. %Y")
** Zdravstveno stanje
** Psihično počutje
** Stanje v službi
** Kaj sem danes naredil?
EOF
emacs -nw "$WEEK_LOG"

View File

@@ -0,0 +1,65 @@
#!/bin/bash
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
api_key=""
get_abuseConfidenceScore(){
score=$(curl -s -G https://api.abuseipdb.com/api/v2/check \
--data-urlencode "ipAddress=$1" \
-d maxAgeInDays=90 \
-d verbose \
-H "Key: $api_key" \
-H "Accept: application/json" | jq .data.abuseConfidenceScore)
echo "$score"
}
echo "Checking /var/log/fail2ban.log for found IP addresses..."
ip_list=$(grep Found /var/log/fail2ban.log | awk '{print $8;}' | uniq)
blocked=()
not_blocked_unsafe=()
not_blocked_safe=()
for ip in $(echo "$ip_list"); do
if grep -q "$ip" /etc/csf/csf.deny; then
blocked+=("$ip");
echo -e "${YELLOW}IP $ip is already blocked!${NC}"
else
echo "Getting abuse score for IP: $ip..."
abuse_score=$(get_abuseConfidenceScore $ip)
if [[ $abuse_score -gt 75 ]]; then
not_blocked_unsafe+=("$ip")
echo -e "${RED}IP $ip is unsafe and not yet blocked!${NC}"
else
not_blocked_safe+=("$ip")
echo -e "${GREEN}IP $ip is safe!${NC}"
fi
fi
done
echo
IFS=','
echo "###################################"
echo "# State of found addresses in CSF #"
echo "###################################"
echo "Blocked: ${blocked[*]}"
echo -e "${RED}Not blocked and unsafe: ${not_blocked_unsafe[*]}${NC}"
echo -e "${GREEN}Not blocked and safe: ${not_blocked_safe[*]}${NC}"
unset IFS
if [[ ! -z ${not_blocked_unsafe[*]} ]]; then
echo
echo "#######################"
echo "# Gotta Block 'Em All #"
echo "#######################"
echo "If you want to block the unsafe addresses above, use:"
for ip in ${not_blocked_unsafe[@]}; do
echo "csf -d $ip"
done
fi

58
pve-netbox-diff.sh Normal file
View File

@@ -0,0 +1,58 @@
#! /bin/bash
#set -e
NETBOX_URL=""
NETBOX_AUTH_TOKEN=""
MAILTO=""
SUBJECT="PVE and NetBox mismatch"
curl -s -X GET "$NETBOX_URL/api/virtualization/virtual-machines/" \
-H "Authorization: Token $NETBOX_AUTH_TOKEN" \
-H 'Accept: application/json' | \
jq -r '
[
.results[] |
{
VMID: .custom_fields.VMID,
status: (.status.value |
gsub("active"; "running") |
gsub("offline"; "stopped")),
name: .name
}
] |
sort_by(.VMID) |
map([.VMID, .status, .name]) |
(["VMID", "Status", "Name"]) as $header |
$header, .[] |
@csv' | \
tr -d '"' > /tmp/netbox-status.csv
/usr/sbin/pct list | awk 'NR==1 {print "VMID,Status,Name"} NR>1 {print $1","$2","$3}' > /tmp/pve-status.csv
/usr/sbin/qm list | awk 'NR>1 {print $1","$3","$2}' OFS="," >> /tmp/pve-status.csv
diff -C 0 /tmp/pve-status.csv /tmp/netbox-status.csv > /tmp/diff_result.txt
EXIT_STATUS=$?
if [ $EXIT_STATUS -eq 1 ]; then
for host in $(diff -C 0 /tmp/pve-status.csv /tmp/netbox-status.csv | grep '^- ' | awk -F ',' '{sub(/^- /, ""); print $1; }'); do
if [[ ${host:0:1} -eq 1 ]]; then
echo "Resources for $host:" >> /tmp/new-host-resources.txt
/usr/sbin/pct config $host | grep -E '^hostname|^cores|^memory|^rootfs|^net' >> /tmp/new-host-resources.txt
echo >> /tmp/new-host-resources.txt
elif [[ ${host:0:1} -eq 2 ]]; then
echo "Resources for $host:" >> /tmp/new-host-resources.txt
/usr/sbin/qm config $host | grep -E '^name|^cores|^memory|^scsi[0-9]|^net' >> /tmp/new-host-resources.txt
echo >> /tmp/new-host-resources.txt
fi
done
if [ -f /tmp/new-host-resources.txt ]; then
awk 'FNR==1 && NR!=1 {print ""; print "Here is a list of hosts missing from NetBox together with their information:"}; {print}' /tmp/diff_result.txt /tmp/new-host-resources.txt > /tmp/mail.txt
else
cp /tmp/diff_result.txt /tmp/mail.txt
fi
mail -s "$SUBJECT" "$MAILTO" < /tmp/mail.txt
fi
rm -f /tmp/pve-status.csv /tmp/netbox-status.csv /tmp/diff_result.txt /tmp/new-host-resources.txt /tmp/mail.txt

62
zola-deploy.sh Executable file
View File

@@ -0,0 +1,62 @@
#!/bin/bash
set -e
dev_server=""
prod_server=""
websites=("")
active_website=""
path_match=0
not_git(){
echo "You are not in a git repository!"
exit 1
}
get_git_branch(){
gitBranch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null) || not_git
}
check_path_match(){
for website in "${websites[@]}"; do
if [[ $cwd == *$website* ]]; then
path_match=1
active_website=$website
break
fi
done
}
zola_deploy(){
cwd=$(pwd)
check_path_match
if [[ $path_match == 1 ]]; then
if [[ $gitBranch == "main" ]]; then
cd "$(git rev-parse --show-toplevel)"
production_deploy_alert
zola build
rsync -r --delete --chown=www-data:www-data ./public/ $prod_server:/srv/http/$active_website
elif [[ $gitBranch == "dev" ]]; then
cd "$(git rev-parse --show-toplevel)"
zola --config config.dev.toml build --drafts
rsync -r --delete ./public/ $dev_server:/var/www/dev.$active_website
else
echo "Not on a correct branch (must be either dev or main)!"
fi
else
echo "Not a known website!"
exit 1
fi
}
production_deploy_alert(){
read -p "Deploying to production! Are you sure? (y/N):" -s -n 1 -r
echo
case $REPLY in
[Yy]) echo "Okay! Here we go!";;
*) echo "See ya!"; exit 1;;
esac
}
get_git_branch
zola_deploy