Add auto-configuration script for S3 storage
Browse files
start.sh
CHANGED
|
@@ -1,11 +1,49 @@
|
|
| 1 |
#!/bin/sh
|
|
|
|
|
|
|
| 2 |
# 创建数据目录
|
| 3 |
-
mkdir -p /
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
|
|
|
| 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
|