File size: 3,779 Bytes
d98cf4b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash

HF_TOKEN="${HF_TOKEN:?HF_TOKEN must be set}"

hf auth login --token "$HF_TOKEN" 2>&1 | tail -1

if [ -z "$MC_DATASET" ]; then
    echo ""
    echo "============================================"
    echo "  ERROR: MC_DATASET غير معرف"
    echo "  شغّل الحاوية مع: -e MC_DATASET=username/mc-data"
    echo "  مثال: -e MC_DATASET=sayed125/mc-server-data"
    echo "============================================"
    echo ""
    exit 1
fi

DATASET="$MC_DATASET"

init_dataset() {
    echo "التحقق من Dataset: $DATASET"
    if hf repos create --type dataset "$DATASET" 2>&1; then
        echo "✅ تم إنشاء Dataset"
    else
        echo "⚠️  Dataset موجود مسبقاً"
    fi
}

pull_files() {
    echo "سحب الملفات من Dataset..."
    mkdir -p /tmp/sync
    if hf download "$DATASET" --local-dir /tmp/sync --repo-type dataset 2>&1; then
        cp -r /tmp/sync/* /minecraft/ 2>/dev/null
        rm -rf /tmp/sync
        echo "✅ تم سحب الملفات"
    else
        echo "ℹ️  Dataset فاضي أو لا يمكن السحب"
    fi
    hf download "$DATASET" worlds.tar.gz --local-dir /tmp --repo-type dataset 2>/dev/null
    if [ -f /tmp/worlds.tar.gz ]; then
        tar xzf /tmp/worlds.tar.gz -C /minecraft 2>/dev/null && echo "✅ تم استرجاع العالم"
        rm -f /tmp/worlds.tar.gz
    fi
}

push_file() {
    [ -f "$1" ] && hf upload "$DATASET" "$1" 2>&1 && echo "✅ رفع $1"
}

backup_configs() {
    for f in server.properties bukkit.yml ops.json whitelist.json eula.txt permissions.yml playit_secret; do
        [ -f "/minecraft/$f" ] && push_file "/minecraft/$f"
    done
}

pull_dirs() {
    echo "سحب المجلدات من Dataset..."
    mkdir -p /tmp/sync
    if hf download "$DATASET" --local-dir /tmp/sync --repo-type dataset 2>&1; then
        cp -r /tmp/sync/* /minecraft/ 2>/dev/null
        rm -rf /tmp/sync
        echo "✅ تم سحب المجلدات"
    else
        echo "ℹ️  لا توجد مجلدات في Dataset"
    fi
}

push_dirs() {
    echo "رفع هيكل المجلدات إلى Dataset..."
    mkdir -p /tmp/staging
    find /minecraft -mindepth 1 -type f \
        ! -name "purpur.jar" \
        ! -path "*/libraries/*" \
        ! -path "*/cache/*" \
        ! -name "*.gz" \
        ! -name "*.jar" \
        2>/dev/null | while IFS= read -r f; do
            rel="${f#/minecraft/}"
            dir="/tmp/staging/$(dirname "$rel")"
            mkdir -p "$dir"
            cp "$f" "/tmp/staging/$rel"
    done
    if hf upload "$DATASET" /tmp/staging --repo-type dataset 2>&1; then
        echo "✅ تم رفع هيكل المجلدات"
    fi
    rm -rf /tmp/staging
}

backup_worlds() {
    echo "نسخ احتياطي للعوالم..."
    tar czf /tmp/worlds.tar.gz \
      -C /minecraft world \
      -C /minecraft world_nether \
      -C /minecraft world_the_end 2>/dev/null
    if hf upload "$DATASET" /tmp/worlds.tar.gz 2>&1; then
        echo "✅ تم نسخ العوالم"
    fi
    rm -f /tmp/worlds.tar.gz
}

backup_all() {
    echo "نسخ احتياطي كامل..."
    tar czf /tmp/full-backup.tar.gz \
      --exclude=purpur.jar \
      --exclude=libraries \
      --exclude=cache \
      -C /minecraft . 2>/dev/null
    if hf upload "$DATASET" /tmp/full-backup.tar.gz 2>&1; then
        echo "✅ تم النسخ الاحتياطي الكامل"
    fi
    rm -f /tmp/full-backup.tar.gz
}

case "${1:-all}" in
    init)   init_dataset ;;
    pull)   pull_files ; pull_dirs ;;
    push)   shift; push_file "$@" ;;
    configs) backup_configs ;;
    dirs)   push_dirs ;;
    worlds) backup_worlds ;;
    full)   backup_all ;;
    all)
        init_dataset
        pull_files
        pull_dirs
        ;;
esac