-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
52 lines (43 loc) · 2.08 KB
/
start.sh
File metadata and controls
52 lines (43 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env bash
STORAGE_BOX_LOGIN="USERNAME"
STORAGE_BOX_PASSWORD="password"
STORAGE_BOX_ID="IDIDID"
STORAGE_BOX_API="https://robot-ws.your-server.de/storagebox/$STORAGE_BOX_ID"
get_storagebox_info() {
response=$(curl -u "$STORAGE_BOX_LOGIN:$STORAGE_BOX_PASSWORD" -s "$STORAGE_BOX_API")
if [[ $? -ne 0 ]]; then
echo "Error while connecting to Hetzner API"
exit 1
fi
disk_quota=$(echo "$response" | jq -r '.storagebox.disk_quota')
disk_usage=$(echo "$response" | jq -r '.storagebox.disk_usage')
storage_name=$(echo "$response" | jq -r '.storagebox.name')
product=$(echo "$response" | jq -r '.storagebox.product')
location=$(echo "$response" | jq -r '.storagebox.location')
paid_until=$(echo "$response" | jq -r '.storagebox.paid_until')
if [[ -z "$disk_quota" || -z "$disk_usage" ]]; then
echo "Error: Cannot retrieve disk data."
exit 1
fi
free_space=$((disk_quota - disk_usage))
usage_percent=$((100 * disk_usage / disk_quota))
echo "╭╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╮"
echo " 📦📦📦 Storage Box 📦📦📦"
echo "╰╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╯"
echo "╭╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╮"
echo " 🍰 Name: ${storage_name:-<not provided>}"
echo " 🚀 Product: $product"
echo " 🍡 Location: $location"
echo " ⏳ Paid until: $paid_until"
echo "╰╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╯"
echo "╭╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╮"
echo " 😱 Disk quota: $disk_quota MB"
echo " ⠧ Used: $disk_usage MB "
echo " ⠼ free: $free_space MB"
echo "╰╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╾╯"
}
if ! command -v jq &>/dev/null; then
echo "❌ jq not found. Install it from package manager"
exit 1
fi
get_storagebox_info