This commit is contained in:
qiaofeng1227 2024-12-19 11:56:08 +08:00
commit 5ed7455276

View File

@ -3,10 +3,9 @@
echo "$(date '+%Y-%m-%d %H:%M:%S') - INFO - start to migrate config.ini" echo "$(date '+%Y-%m-%d %H:%M:%S') - INFO - start to migrate config.ini"
migrate_ini() { migrate_ini() {
# Combine source_ini to target ini
# Define file paths, use template ini and syn exsit items from target ini
export target_ini="$1" export target_ini="$1"
export template_ini="$2" export source_ini="$2"
python3 - <<EOF python3 - <<EOF
import configparser import configparser
@ -14,34 +13,34 @@ import os
import sys import sys
target_ini = os.environ['target_ini'] target_ini = os.environ['target_ini']
template_ini = os.environ['template_ini'] source_ini = os.environ['source_ini']
# Create two config parsers # Create two config parsers
target_parser = configparser.ConfigParser() target_parser = configparser.ConfigParser()
template_parser = configparser.ConfigParser() source_parser = configparser.ConfigParser()
try: try:
target_parser.read(target_ini) target_parser.read(target_ini)
template_parser.read(template_ini) source_parser.read(source_ini)
except configparser.MissingSectionHeaderError: except configparser.MissingSectionHeaderError:
print("Error: The provided files are not valid INI files.") print("Error: The provided files are not valid INI files.")
sys.exit(1) sys.exit(1)
# use target_parser to override template_parser # use target_parser to override source_parser
for section in target_parser.sections(): for section in target_parser.sections():
if template_parser.has_section(section): if source_parser.has_section(section):
for key, value in target_parser.items(section): for key, value in target_parser.items(section):
if template_parser.has_option(section, key): if source_parser.has_option(section, key):
template_parser.set(section, key, value) source_parser.set(section, key, value)
with open(target_ini, 'w') as f: with open(target_ini, 'w') as f:
template_parser.write(f) source_parser.write(f)
EOF EOF
} }
# special migration # Special migration
post_migration(){ post_migration(){
echo "$(date '+%Y-%m-%d %H:%M:%S') - INFO - Set listen_port to nginx_proxy_manager" echo "$(date '+%Y-%m-%d %H:%M:%S') - INFO - Set listen_port to nginx_proxy_manager"
config_file="/websoft9/config/config.ini" config_file="/websoft9/config/config.ini"