websoft9/apps/roles/role_init/templates/init.sh.jinja2

52 lines
1.9 KiB
Plaintext
Raw Normal View History

2022-07-11 14:03:55 +08:00
#!/bin/bash
# support special char [!"`$%()[]{},.*+-:;<=>?_~/|]
new_password=$(pwgen -ncCs 14 1)!
sudo sleep 10s
sudo sh -c 'echo "init-password started at" $(date -d now) 1>> /tmp/init_debug.txt'
2022-07-11 14:40:24 +08:00
{% for app_name in applist.stdout_lines %}
2022-07-12 08:43:15 +08:00
#1 init for applist of .env
2022-07-11 15:29:11 +08:00
sudo docker compose -f /data/apps/{{app_name}}/docker-compose.yml down -v
2022-07-12 08:43:15 +08:00
# init password
has_app_password=$(cat /data/apps/{{app_name}}/.env |grep APP_PASSWORD)
if [ $has_app_password == "" ]; then
2022-07-12 09:12:42 +08:00
sudo sed -i "s/_PASSWORD=.*/_PASSWORD=$new_password/g" /data/apps/{{app_name}}/.env
else
# has_app_encrypt
2022-07-12 15:31:30 +08:00
has_app_encrypt=$(cat /data/apps/{{app_name}}/.env |grep "APP_ENCRYPT=")
2022-07-12 09:12:42 +08:00
if [ $has_app_encrypt == "" ]; then
sudo sed -i "s/APP_PASSWORD=.*/APP_PASSWORD=$new_password/g" /data/apps/{{app_name}}/.env
else
sudo sed -i "s/APP_PASSWORD=.*/APP_PASSWORD=$new_password/g" /data/apps/{{app_name}}/.env
2022-07-12 17:08:44 +08:00
app_encrypt_password=$(bash /data/apps/{{app_name}}/src/encrypt.sh)
2022-07-12 09:12:42 +08:00
sudo sed -i "s/APP_ENCRYPT_PASSWORD=.*/APP_ENCRYPT_PASSWORD=$app_encrypt_password/g" /data/apps/{{app_name}}/.env
fi
2022-07-12 10:52:40 +08:00
fi
# change all the variables to real value,such as DB_MYSQL_PASSWORD=$APP_PASSWORD=>DB_MYSQL_PASSWORD=ues983ks9309023! TODO
2022-07-12 08:43:15 +08:00
# init APP_URL
2022-07-12 09:12:42 +08:00
app_url_replace=$(cat /data/apps/{{app_name}}/.env |grep APP_URL_REPLACE)
if [ $app_url_replace == "APP_URL_REPLACE=true" ]; then
public_ip=`wget -O - https://download.websoft9.com/ansible/get_ip.sh | bash`
sudo sed -i "s/APP_URL=.*/APP_URL=$public_ip/g" /data/apps/{{app_name}}/.env
else
echo "There is not APP_URL"
fi
2022-07-12 08:43:15 +08:00
2022-07-11 15:29:11 +08:00
sudo docker compose -f /data/apps/{{app_name}}/docker-compose.yml up -d --no-recreate
2022-07-11 14:03:55 +08:00
2022-07-11 15:29:11 +08:00
#2 init for applist of special
2022-07-12 08:43:15 +08:00
after_path=/data/apps/{{app_name}}/src/after_up.sh
if [ -f "$after_path" ]; then
bash /data/apps/{{app_name}}/src/after_up.sh
else
echo "There is not after_up"
fi
{% endfor %}
2022-07-11 15:29:11 +08:00
sudo sh -c 'echo "init docker ended at" $(date -d now) 1>> /tmp/init_debug.txt'