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