File size: 2,707 Bytes
d522484
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ad627d8
d522484
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/bin/bash

dir_shell=/ql/shell
. $dir_shell/share.sh
. $dir_shell/env.sh

echo -e "======================1. 检测配置文件========================\n"
import_config "$@"
make_dir /etc/nginx/conf.d
make_dir /run/nginx
init_nginx
fix_config

pm2 l &>/dev/null

echo -e "======================2. 安装依赖========================\n"
patch_version

echo -e "======================3. 启动nginx========================\n"
nginx -s reload 2>/dev/null || nginx -c /etc/nginx/nginx.conf
echo -e "nginx启动成功...\n"

echo -e "======================4. 启动pm2服务========================\n"
reload_update
reload_pm2

if [[ $AutoStartBot == true ]]; then
  echo -e "======================5. 启动bot========================\n"
  nohup ql bot >$dir_log/bot.log 2>&1 &
  echo -e "bot后台启动中...\n"
fi

if [[ $EnableExtraShell == true ]]; then
  echo -e "====================6. 执行自定义脚本========================\n"
  nohup ql extra >$dir_log/extra.log 2>&1 &
  echo -e "自定义脚本后台执行中...\n"
fi

echo -e "======================7. 写入rclone配置========================\n"
echo "$RCLONE_CONF" > ~/.config/rclone/rclone.conf

echo -e "############################################################\n"
echo -e "容器启动成功..."
echo -e "############################################################\n"


echo -e "##########8. 写入登陆信息 ############"
echo "{ \"username\": \"$USERNAME\", \"password\": \"$PASSWORD\" }" > /ql/data/config/auth.json

echo -e "##########9. 同步备份信息 ############"
if [ -n "$RCLONE_CONF" ]; then
  echo -e "########## Synchronizing Backup ############"
  
  # Specify the remote folder path in the format remote:path
  REMOTE_FOLDER="serv002:/qinglong2"
  
  # Use rclone ls command to list folder contents, capturing output and errors
  OUTPUT=$(rclone ls "$REMOTE_FOLDER" 2>&1)
  
  # Get the exit status code of the rclone command
  EXIT_CODE=$?
  
  case $EXIT_CODE in
    0) 
      # rclone command executed successfully, check if the folder is empty
      if [ -z "$OUTPUT" ]; then
        echo "Initial installation"
		#rclone sync /ql/data $REMOTE_FOLDER
      else
        mkdir -p /ql/.tmp/data
        rclone sync "$REMOTE_FOLDER" /ql/.tmp/data && real_time=true ql reload data
      fi
      ;;
    1)
      # Handle other errors, check if it was a directory not found error
      if [[ "$OUTPUT" == *"directory not found"* ]]; then
        echo "Error: Folder does not exist"
      else
        echo "Error: $OUTPUT"
      fi
      ;;
    *)
      echo "Error: rclone command failed, exit code: $EXIT_CODE"
      ;;
  esac
else
  echo "No Rclone configuration detected"
fi


tail -f >/dev/null

exec "$@"