Compare commits
11
Commits
169e6c934f
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d1b2d10394 | ||
|
|
9512520bfe | ||
|
|
ab3044d053 | ||
|
|
7345b746e0 | ||
|
|
e0c4d62f0b | ||
|
|
7dbb13d31b | ||
|
|
a51a493665 | ||
|
|
343ad5d8ad | ||
|
|
c5548ecf6d | ||
|
|
73b4f0690b | ||
|
|
26ff55fd22 |
@@ -0,0 +1 @@
|
|||||||
|
/ansible
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#(c) by CeMunzIT (Christopher Münzer)
|
||||||
|
|
||||||
|
MNT="/mnt/video" #Zielverzeichnis zum Sichern
|
||||||
|
HDR="/home/pi" #Heimatverzeichnis
|
||||||
|
|
||||||
|
#Arbeitsvariable
|
||||||
|
DATE="$(date +%Y-%m-%d)"
|
||||||
|
TIMESTAMP="$(date +%Y-%m-%d_%H-%M-%S)"
|
||||||
|
SOURCE_DIR="$HDR/Monitor"
|
||||||
|
TARGET_DIR="$MNT/$DATE"
|
||||||
|
LOG_DIR="$HDR/log"
|
||||||
|
LOGFILE="$LOG_DIR/$DATE.log"
|
||||||
|
ERROR="!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!"
|
||||||
|
|
||||||
|
#Logverzeichnis vorhanden/erstellen
|
||||||
|
if [ ! -d "$LOG_DIR" ]; then
|
||||||
|
mkdir -p $LOG_DIR
|
||||||
|
fi
|
||||||
|
|
||||||
|
#Prüfung Mount vorhanden
|
||||||
|
if mountpoint -q "$MNT"; then
|
||||||
|
echo "" >> "$LOGFILE" 2>&1
|
||||||
|
echo "$TIMESTAMP Mountverzeichnis vorhanden" >> "$LOGFILE" 2>&1
|
||||||
|
else
|
||||||
|
echo "" >> "$LOGFILE" 2>&1
|
||||||
|
echo "$TIMESTAMP kein Mountpfad auf $MNT gefunden" >> "$LOGFILE" 2>&1
|
||||||
|
echo "$ERROR" >> "$LOGFILE" 2>&1
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
#Verfügbarer Speicherplatz am Zielverzeichnis
|
||||||
|
|
||||||
|
SPL=$(df -h $MNT | grep $MNT | tr -s ' ' | cut -d ' ' -f 5 | tr -d '%')
|
||||||
|
if [ "$SPL" -le 90 ]; then
|
||||||
|
echo "$TIMESTAMP Speicherplatz bei $SPL %" >> "$LOGFILE" 2>&1
|
||||||
|
else
|
||||||
|
echo "$TIMESTAMP Nicht genug Speicherplatz auf dem Zielverzeichnis" >> "$LOGFILE" 2>&1
|
||||||
|
echo "$ERROR" >> "$LOGFILE" 2>&1
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
#Zielverzeichnis mit Datum anlegen oder vorhanden
|
||||||
|
if [ ! -d "$TARGET_DIR" ]; then
|
||||||
|
mkdir -p $TARGET_DIR
|
||||||
|
echo "$TIMESTAMP Neuer Ordner in: $TARGET_DIR erstellt" >> "$LOGFILE" 2>&1
|
||||||
|
else
|
||||||
|
echo "$TIMESTAMP Ordner vorhanden" >> "$LOGFILE" 2>&1
|
||||||
|
fi
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
#Dateien verschieben
|
||||||
|
|
||||||
|
mv -v $SOURCE_DIR/* $TARGET_DIR/ >> "$LOGFILE" 2>&1
|
||||||
|
|
||||||
|
#Prüfen ob das Verschieben erfolgreich war oder nicht
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "$TIMESTAMP Verschieben Erfolgreich!" >> "$LOGFILE" 2>&1
|
||||||
|
else
|
||||||
|
echo "$TIMESTAMP Verschieben Fehlgeschlagen!" >> "$LOGFILE" 2>&1
|
||||||
|
echo "$ERROR" >> "$LOGFILE" 2>&1
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
sleep 2
|
||||||
|
echo "------------------------------------------------------------------------------------------------------------------------------" >> "$LOGFILE" 2>&1
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# Place under /etc/dnsmasq.d/99-dns-vip.conf
|
||||||
|
# This will propagate the DNS VIP of keepalived as DNS Server over DHCP
|
||||||
|
dhcp-option=option:dns-server,192.168.1.4
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
# Place under /etc/keepalived/keepalived.conf on BACKUP pihole
|
||||||
|
global_defs {
|
||||||
|
router_id pihole-dns-02
|
||||||
|
script_user root
|
||||||
|
enable_script_security
|
||||||
|
}
|
||||||
|
|
||||||
|
vrrp_script chk_ftl {
|
||||||
|
script "/etc/scripts/chk_ftl"
|
||||||
|
interval 1
|
||||||
|
weight -10
|
||||||
|
}
|
||||||
|
|
||||||
|
vrrp_instance PIHOLE {
|
||||||
|
state BACKUP
|
||||||
|
interface eth0
|
||||||
|
virtual_router_id 55
|
||||||
|
priority 145
|
||||||
|
advert_int 1
|
||||||
|
unicast_src_ip 192.168.1.3
|
||||||
|
unicast_peer {
|
||||||
|
192.168.1.2
|
||||||
|
}
|
||||||
|
|
||||||
|
authentication {
|
||||||
|
auth_type PASS
|
||||||
|
auth_pass secret
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual_ipaddress {
|
||||||
|
192.168.1.4/24
|
||||||
|
}
|
||||||
|
|
||||||
|
track_script {
|
||||||
|
chk_ftl
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
# Place under /etc/keepalived/keepalived.conf on MASTER pihole
|
||||||
|
global_defs {
|
||||||
|
router_id pihole-dns-01
|
||||||
|
script_user root
|
||||||
|
enable_script_security
|
||||||
|
}
|
||||||
|
|
||||||
|
vrrp_script chk_ftl {
|
||||||
|
script "/usr/local/scripts/chk_ftl"
|
||||||
|
interval 1
|
||||||
|
weight -10
|
||||||
|
}
|
||||||
|
|
||||||
|
vrrp_instance PIHOLE {
|
||||||
|
state MASTER
|
||||||
|
interface eth0
|
||||||
|
virtual_router_id 55
|
||||||
|
priority 150
|
||||||
|
advert_int 1
|
||||||
|
unicast_src_ip 192.168.2.2
|
||||||
|
unicast_peer {
|
||||||
|
192.168.2.3
|
||||||
|
}
|
||||||
|
|
||||||
|
authentication {
|
||||||
|
auth_type PASS
|
||||||
|
auth_pass secret
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual_ipaddress {
|
||||||
|
192.168.2.4/24
|
||||||
|
}
|
||||||
|
|
||||||
|
track_script {
|
||||||
|
chk_ftl
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Place under /etc/scripts for FTL Status check of keepalived
|
||||||
|
|
||||||
|
STATUS=$(ps ax | grep -v grep | grep pihole-FTL)
|
||||||
|
|
||||||
|
if [ "$STATUS" != "" ]
|
||||||
|
then
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# Name: cooler_skript
|
||||||
|
# Purpose: Anschluss eines Kuehlkoerpers und Temperatur Sensor
|
||||||
|
# GPIO-Library: RPi.GPIO 0.5.4
|
||||||
|
#
|
||||||
|
# Author: Felix Stern
|
||||||
|
# Website: www.tutorials-raspberrypi.de
|
||||||
|
#
|
||||||
|
# Created: 04.04.2014
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
#!/usr/bin/env python
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
|
||||||
|
GPIO.setmode(GPIO.BCM)
|
||||||
|
GPIO.setwarnings(False)
|
||||||
|
|
||||||
|
IMPULS_PIN = 23 #Pin, der zum Transistor fuehrt
|
||||||
|
SLEEP_TIME = 30 #Alle wie viel Sekunden die Temperatur ueberprueft wird
|
||||||
|
MAX_CPU_TEMP = 40 #Ab welcher CPU Temperatur der Luefter sich drehen soll
|
||||||
|
MAX_SENSOR_TEMP = 30 #Ab welcher Temperatur im Gehaeuse der Luefter sich drehen soll
|
||||||
|
SENSOR_ID = '' #ID des Sonsors, BITTE ANPASSEN, falls kein Sensor vorhanden leer lassen
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def get_sensor_temperature():
|
||||||
|
try:
|
||||||
|
tempfile = open("/sys/bus/w1/devices/"+SENSOR_ID+"/w1_slave")
|
||||||
|
text = tempfile.read()
|
||||||
|
tempfile.close()
|
||||||
|
temperature_data = text.split()[-1]
|
||||||
|
temperature = float(temperature_data[2:])
|
||||||
|
temperature = temperature / 1000
|
||||||
|
return float(temperature)
|
||||||
|
except:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def get_cpu_temperature():
|
||||||
|
temp = os.popen('vcgencmd measure_temp').readline()
|
||||||
|
return float(temp.replace("temp=","").replace("'C\n",""))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
|
||||||
|
#Init
|
||||||
|
GPIO.setup(IMPULS_PIN, GPIO.OUT)
|
||||||
|
GPIO.output(IMPULS_PIN, False)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
cpu_temp = get_cpu_temperature()
|
||||||
|
sensor_temp = get_sensor_temperature()
|
||||||
|
if cpu_temp >= MAX_CPU_TEMP or sensor_temp >= MAX_SENSOR_TEMP :
|
||||||
|
GPIO.output(IMPULS_PIN, True)
|
||||||
|
else:
|
||||||
|
GPIO.output(IMPULS_PIN, False)
|
||||||
|
|
||||||
|
#print "gemessene CPU Temperatur:" + str(cpu_temp)
|
||||||
|
#print "gemessene Sensor Temperatur:" + str(sensor_temp)
|
||||||
|
|
||||||
|
time.sleep(SLEEP_TIME)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
||||||
Executable
+51
@@ -0,0 +1,51 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#(c)By CeMunz IT
|
||||||
|
#Script zum Sicheren löschen von Festplatten
|
||||||
|
|
||||||
|
clear
|
||||||
|
|
||||||
|
echo "Willkommen beil Löschungstool für Festplatten (HDDs)"
|
||||||
|
echo ""
|
||||||
|
echo "Es laufen insgesammt 2 Löschvorgänge durch!"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
FP= ls /dev/sd* | grep sd
|
||||||
|
echo ""
|
||||||
|
read -p "Bitte Festplatte wählen (a...g):" lp
|
||||||
|
echo "folgende Festplatte wird gelöscht:"
|
||||||
|
|
||||||
|
echo "/dev/sd$lp"
|
||||||
|
echo -n "Richtige Platte gewählt?(j/n): "
|
||||||
|
read -r choice
|
||||||
|
|
||||||
|
case $choice in
|
||||||
|
j|J)
|
||||||
|
echo "Festplatte wird gelöscht. NICHT VORZEITIG STOPPEN!"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Vorgang abgebrochen!"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "Erster Vorgang"
|
||||||
|
|
||||||
|
# Setzen des Passwortes zum löschen
|
||||||
|
sudo hdparm --user-master u --security-set-pass Eins /dev/sd$lp > /dev/null
|
||||||
|
sudo hdparm --user-master u --security-erase-enhanced Eins /dev/sd$lp
|
||||||
|
|
||||||
|
echo "Zweiter Vorgang"
|
||||||
|
|
||||||
|
### In Bearbeitung!
|
||||||
|
### #sudo dd if=/dev/urandom of=/dev/sd$lp bs=4M status=progress conv=fdatasync
|
||||||
|
|
||||||
|
### #echo "Dritter Vorgang"
|
||||||
|
|
||||||
|
sudo dd if=/dev/zero of=/dev/sd$lp bs=1M status=progress conv=fdatasync
|
||||||
|
|
||||||
|
echo "Metadaten löschen:" # wipefs macht die Platte "sauber" von Metadaten für eine neue Nutzung
|
||||||
|
wipefs -a /dev/sd$lp
|
||||||
|
|
||||||
|
echo "Festplatte /dev/sd$lp erfolgtreich gelöscht!"
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Dieses Script ist für die Aktuallisierung vom Hivellominer Node
|
||||||
|
#
|
||||||
|
# Eine Überarbeitung ist zulässig, muss aber dann wieder zur Verfügung gestellt werden
|
||||||
|
#
|
||||||
|
# Version 1.2
|
||||||
|
#
|
||||||
|
# (c)2025 CeMunzIT Christopher Münzer
|
||||||
|
|
||||||
|
clear
|
||||||
|
|
||||||
|
dir="/opt/hivello/"
|
||||||
|
hv="hivello"
|
||||||
|
hvd="$hv.deb"
|
||||||
|
|
||||||
|
if [ -d "$dir" ]; then
|
||||||
|
echo "Verzeichniss vorhanden"
|
||||||
|
else
|
||||||
|
echo "Verzeichniss wird erstellt"
|
||||||
|
if ! mkdir -p "$dir"; then
|
||||||
|
echo "Konnte Verzeichnis nicht erstellen" >&2
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
echo "Verzeichnis erfolgreich erstellt"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd $dir
|
||||||
|
|
||||||
|
if [ -f "$hvd" ]; then
|
||||||
|
echo "$hv vohanden und wird deinstalliert"
|
||||||
|
sleep 4
|
||||||
|
dpkg -r $hv
|
||||||
|
echo "$hvd Datei wird gelöscht"
|
||||||
|
sleep 4
|
||||||
|
rm -rf $hvd
|
||||||
|
else
|
||||||
|
echo "Datei ist nicht vorhanden und wird gedownloadet"
|
||||||
|
fi
|
||||||
|
|
||||||
|
wget https://download.hivello.services/linux/hivello.deb
|
||||||
|
|
||||||
|
sleep 4
|
||||||
|
|
||||||
|
cd $dir
|
||||||
|
|
||||||
|
echo "neue Datei wird Installiert"
|
||||||
|
|
||||||
|
sleep 3
|
||||||
|
|
||||||
|
dpkg -i $hvd
|
||||||
|
|
||||||
|
echo "beendet"
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
OWM_API_KEY=ea645349e2fbb2ff573104bdd6763604
|
||||||
|
DB_USER=root
|
||||||
|
DB_PASSWORD=dein_db_passwort
|
||||||
|
DB_HOST=127.0.0.1
|
||||||
|
DB_PORT=3306
|
||||||
|
DB_NAME=weather_db
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
**1. Voraussetzungen installieren**
|
||||||
|
|
||||||
|
API Key auf openweathermap.org generieren
|
||||||
|
|
||||||
|
```
|
||||||
|
pip install requests mariadb python-dotenv
|
||||||
|
```
|
||||||
|
|
||||||
|
**2. Datenbank Vorbereiten**
|
||||||
|
|
||||||
|
```
|
||||||
|
CREATE DATABASE weather_db;
|
||||||
|
|
||||||
|
USE weather_db;
|
||||||
|
|
||||||
|
CREATE TABLE weather_data (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
city VARCHAR(100) NOT NULL,
|
||||||
|
country VARCHAR(10),
|
||||||
|
temperature FLOAT,
|
||||||
|
feels_like FLOAT,
|
||||||
|
humidity INT,
|
||||||
|
pressure INT,
|
||||||
|
wind_speed FLOAT,
|
||||||
|
description VARCHAR(255),
|
||||||
|
recorded_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
**3. Script und .env Datei ablegen und bearbeiten**
|
||||||
|
|
||||||
|
**4. Cronjob**
|
||||||
|
```
|
||||||
|
0 * * * * /usr/bin/python3 /pfad/zum/weather_script.py
|
||||||
|
```
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
import requests
|
||||||
|
import mariadb
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
from datetime import datetime
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
# Umgebungsvariablen aus .env laden
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
# --- Konfiguration ---
|
||||||
|
API_KEY = os.getenv("OWM_API_KEY")
|
||||||
|
CITY = "Berlin"
|
||||||
|
UNITS = "metric" # metric = Celsius, imperial = Fahrenheit
|
||||||
|
|
||||||
|
DB_CONFIG = {
|
||||||
|
"user": os.getenv("DB_USER", "root"),
|
||||||
|
"password": os.getenv("DB_PASSWORD", ""),
|
||||||
|
"host": os.getenv("DB_HOST", "127.0.0.1"),
|
||||||
|
"port": int(os.getenv("DB_PORT", 3306)),
|
||||||
|
"database": os.getenv("DB_NAME", "weather_db"),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def fetch_weather(city):
|
||||||
|
"""Ruft Wetterdaten von der OpenWeatherMap-API ab."""
|
||||||
|
url = "https://api.openweathermap.org/data/2.5/weather"
|
||||||
|
params = {
|
||||||
|
"q": city,
|
||||||
|
"appid": API_KEY,
|
||||||
|
"units": UNITS,
|
||||||
|
"lang": "de",
|
||||||
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = requests.get(url, params=params, timeout=10)
|
||||||
|
response.raise_for_status()
|
||||||
|
return response.json()
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
print(f"Fehler beim Abrufen der Wetterdaten: {e}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def parse_weather(data):
|
||||||
|
"""Extrahiert die relevanten Felder aus der API-Antwort."""
|
||||||
|
return {
|
||||||
|
"city": data["name"],
|
||||||
|
"country": data["sys"].get("country", ""),
|
||||||
|
"temperature": data["main"]["temp"],
|
||||||
|
"feels_like": data["main"]["feels_like"],
|
||||||
|
"humidity": data["main"]["humidity"],
|
||||||
|
"pressure": data["main"]["pressure"],
|
||||||
|
"wind_speed": data["wind"]["speed"],
|
||||||
|
"description": data["weather"][0]["description"],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def save_to_db(weather):
|
||||||
|
"""Speichert die Wetterdaten in der MariaDB."""
|
||||||
|
try:
|
||||||
|
conn = mariadb.connect(**DB_CONFIG)
|
||||||
|
except mariadb.Error as e:
|
||||||
|
print(f"Fehler bei der DB-Verbindung: {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
sql = """
|
||||||
|
INSERT INTO weather_data
|
||||||
|
(city, country, temperature, feels_like, humidity,
|
||||||
|
pressure, wind_speed, description, recorded_at)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
|
"""
|
||||||
|
values = (
|
||||||
|
weather["city"],
|
||||||
|
weather["country"],
|
||||||
|
weather["temperature"],
|
||||||
|
weather["feels_like"],
|
||||||
|
weather["humidity"],
|
||||||
|
weather["pressure"],
|
||||||
|
weather["wind_speed"],
|
||||||
|
weather["description"],
|
||||||
|
datetime.now(),
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
cursor.execute(sql, values)
|
||||||
|
conn.commit()
|
||||||
|
print(f"Daten gespeichert (ID: {cursor.lastrowid})")
|
||||||
|
except mariadb.Error as e:
|
||||||
|
print(f"Fehler beim Speichern: {e}")
|
||||||
|
conn.rollback()
|
||||||
|
finally:
|
||||||
|
cursor.close()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
if not API_KEY:
|
||||||
|
print("Fehler: OWM_API_KEY nicht gesetzt. Bitte in .env eintragen.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
print(f"Rufe Wetterdaten für '{CITY}' ab...")
|
||||||
|
data = fetch_weather(CITY)
|
||||||
|
|
||||||
|
if data:
|
||||||
|
weather = parse_weather(data)
|
||||||
|
print(f"Temperatur: {weather['temperature']}°C, "
|
||||||
|
f"{weather['description']}")
|
||||||
|
save_to_db(weather)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user