rachkovii68 commited on
Commit
629dbc0
·
1 Parent(s): 7697dbe

Create sync.sh

Browse files
Files changed (1) hide show
  1. sync.sh +63 -0
sync.sh ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Directory of this script
4
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5
+
6
+ # Git repository directory
7
+ GIT_REPO_DIR="/git"
8
+
9
+ # Log file
10
+ LOG_FILE="$SCRIPT_DIR/sync.log"
11
+
12
+ # Files to sync
13
+ XUI_DB_PATH="/etc/x-ui/x-ui.db"
14
+ XRAY_CONFIG_PATH="/usr/local/x-ui/bin/config.json"
15
+
16
+ # Target directory in the git repo
17
+ TARGET_DIR="$GIT_REPO_DIR/x-ui-configs"
18
+
19
+ # Git commit message
20
+ COMMIT_MESSAGE="Automatic sync of x-ui configs"
21
+
22
+ # --- Functions ---
23
+
24
+ log() {
25
+ echo "$(date +'%Y-%m-%d %H:%M:%S') - $1" >> "$LOG_FILE"
26
+ }
27
+
28
+ sync_files() {
29
+ log "Starting file synchronization..."
30
+
31
+ # Git safe directory
32
+ git config --global --add safe.directory /git
33
+
34
+ # Setup Git
35
+ echo "Setting up Git..." >> $LOG_FILE
36
+ git config --global user.email "igor04091968@gmail.com"
37
+
38
+ # The cp commands are removed because the volume mounts make them redundant.
39
+ # The live database is already in the git repository on the host.
40
+
41
+ # Git operations
42
+ cd "$GIT_REPO_DIR" || exit 1
43
+ git config --global user.email "igor04091968@gmail.com"
44
+ git config --global user.name "igor04091968"
45
+
46
+ git add .
47
+
48
+ git commit -m "$COMMIT_MESSAGE"
49
+ log "Committed changes."
50
+
51
+ git pull
52
+ if git push; then
53
+ log "Pushed changes to the remote repository."
54
+ else
55
+ log "Error: Failed to push changes."
56
+ fi
57
+
58
+ log "Synchronization finished."
59
+ }
60
+
61
+ # --- Main ---
62
+
63
+ sync_files