bhgi commited on
Commit
e3371af
·
verified ·
1 Parent(s): f160dc0

Add auto-configuration script for S3 storage

Browse files
Files changed (1) hide show
  1. start.sh +45 -7
start.sh CHANGED
@@ -1,11 +1,49 @@
1
  #!/bin/sh
 
 
2
  # 创建数据目录
3
- mkdir -p /tmp/openlist/data
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
- # 创建配置文件
6
- cat > /tmp/openlist/data/config.json << 'CONFIG'
7
- {"http_port":7860}
8
- CONFIG
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
- # 启动OpenList
11
- exec /opt/openlist/openlist server --data /tmp/openlist/data
 
1
  #!/bin/sh
2
+ set -e
3
+
4
  # 创建数据目录
5
+ mkdir -p /opt/openlist/data
6
+
7
+ # 初始化配置
8
+ if [ ! -f /opt/openlist/data/config.json ]; then
9
+ echo '{"http_port":5244}' > /opt/openlist/data/config.json
10
+ fi
11
+
12
+ # 设置管理员密码
13
+ if [ -n "$ADMIN_PASSWORD" ]; then
14
+ ./openlist admin set "$ADMIN_PASSWORD" --data /opt/openlist/data
15
+ fi
16
+
17
+ # 启动OpenList(后台)
18
+ ./openlist server --data /opt/openlist/data &
19
+ OPENLIST_PID=$!
20
+
21
+ # 等待服务启动
22
+ sleep 5
23
 
24
+ # 配置S3存储(通过API)
25
+ if [ -n "$S3_ACCESS_KEY" ] && [ -n "$S3_SECRET_KEY" ]; then
26
+ # 登录获取token
27
+ TOKEN=$(curl -s -X POST "http://localhost:5244/api/auth/login" -H "Content-Type: application/json" -d '{"username":"admin","password":"'"$ADMIN_PASSWORD"'"}' | grep -o '"token":"[^"]*"' | cut -d'"' -f4)
28
+
29
+ if [ -n "$TOKEN" ]; then
30
+ # 检查是否已存在S3存储
31
+ EXISTING=$(curl -s "http://localhost:5244/api/admin/storage/list" -H "Authorization: $TOKEN" | grep -c '"mount_path":"/hi168s3"')
32
+
33
+ if [ "$EXISTING" -eq 0 ]; then
34
+ # 创建S3存储
35
+ curl -s -X POST "http://localhost:5244/api/admin/storage/create" -H "Content-Type: application/json" -H "Authorization: $TOKEN" -d '{
36
+ "mount_path": "/hi168s3",
37
+ "order": 0,
38
+ "driver": "S3",
39
+ "cache_expiration": 30,
40
+ "status": "work",
41
+ "addition": "{"bucket":"hi168-29132-0136saow","endpoint":"https://s3.hi168.com","region":"auto","access_key_id":"'"$S3_ACCESS_KEY"'","secret_access_key":"'"$S3_SECRET_KEY"'","force_path_style":true}"
42
+ }'
43
+ echo "S3 storage configured"
44
+ fi
45
+ fi
46
+ fi
47
 
48
+ # 等待OpenList进程
49
+ wait $OPENLIST_PID