websoft9/docker/apphub/config/entrypoint.sh

55 lines
1.4 KiB
Bash
Raw Normal View History

2023-09-18 17:13:15 +08:00
#!/bin/bash
2023-10-21 14:58:55 +08:00
# Define PATH
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
# Export PATH
export PATH
2023-09-18 17:13:15 +08:00
2023-10-13 17:33:18 +08:00
set -e
2023-10-13 16:27:02 +08:00
2023-10-19 11:13:18 +08:00
try_times=5
2023-10-19 10:44:31 +08:00
2023-10-21 17:41:27 +08:00
supervisord
2023-10-19 10:44:31 +08:00
supervisorctl start apphub
2023-10-13 17:33:18 +08:00
# set git user and email
for ((i=0; i<$try_times; i++)); do
2023-10-16 09:30:55 +08:00
set +e
2023-10-19 11:13:18 +08:00
username=$(apphub getconfig --section gitea --key user_name 2>/dev/null)
2023-10-19 11:42:23 +08:00
email=$(apphub getconfig --section gitea --key user_email 2>/dev/null)
2023-10-16 09:30:55 +08:00
set -e
2023-10-13 17:33:18 +08:00
if [ -n "$username" ] && [ -n "$email" ]; then
break
fi
2023-10-19 11:13:18 +08:00
echo "Wait for service running, retrying..."
2023-10-13 17:33:18 +08:00
sleep 3
done
2023-10-13 16:27:02 +08:00
2023-10-13 17:33:18 +08:00
if [[ -n "$username" ]]; then
2023-10-19 11:13:18 +08:00
echo "git config --global user.name $username"
2023-10-13 17:33:18 +08:00
git config --global user.name "$username"
2023-10-13 16:27:02 +08:00
else
2023-10-19 11:13:18 +08:00
echo "username is null, git config username failed"
2023-10-13 17:33:18 +08:00
exit 1
fi
regex="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
if [[ $email =~ $regex ]]; then
2023-10-19 11:13:18 +08:00
echo "git config --global user.email $email"
2023-10-13 17:33:18 +08:00
git config --global user.email "$email"
else
2023-10-19 11:13:18 +08:00
echo "Not have correct email, git config email failed"
2023-10-13 17:33:18 +08:00
exit 1
2023-10-13 16:27:02 +08:00
fi
2023-10-20 17:03:07 +08:00
2023-10-23 16:13:35 +08:00
create_apikey() {
# 容器第一次启动时不管apikey是否为空调用apphub genkey
2023-10-24 16:13:02 +08:00
if [ ! -f /websoft9/apphub/src/config/initialized ] || [ -z "$(apphub getkey)" ]; then
2023-10-23 16:13:35 +08:00
echo "Create new apikey"
apphub genkey
2023-10-24 16:13:02 +08:00
touch /websoft9/apphub/src/config/initialized 2>/dev/null
2023-10-23 16:13:35 +08:00
fi
}
create_apikey
2023-10-21 17:41:27 +08:00
tail -f /var/log/supervisord.log