From 539354f792e100daa5a79e6ddd4fdb7269cd125f Mon Sep 17 00:00:00 2001 From: chiu Date: Thu, 5 Feb 2026 10:39:30 +0000 Subject: [PATCH] Fix quotation mark errors caused by translation --- lib/tasks/change_site_server_name.rake | 27 ++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/tasks/change_site_server_name.rake b/lib/tasks/change_site_server_name.rake index 93c3706..4d756fb 100644 --- a/lib/tasks/change_site_server_name.rake +++ b/lib/tasks/change_site_server_name.rake @@ -26,17 +26,28 @@ namespace :create_site do puts [e,e.backtrace] end end - def change_construct_nginx(ssh,site_construct,update_multithread=false) + def change_construct_nginx(ssh, site_construct, update_multithread=false) @is_multithread = update_multithread auto_update_infos("Reading setting file...") - nginx_file_content = exec_command_by_user(ssh,"cat #{site_construct.nginx_file}") - nginx_file_content = site_construct.generate_nginx_text(nginx_file_content) - auto_update_infos("Writing...") - cmd = "x='#{nginx_file_content.gsub("\\$","$").gsub(/'{1,3}/,"\"\'\"")}'; echo '#{@password}' | sudo -S sh -c \"echo '$x' > #{site_construct.nginx_file}\"" - exec_command_by_user(ssh,cmd) - exec_ssh_command_by_sudo(ssh,"service nginx restart") + raw_content = exec_command_by_user(ssh, "cat #{site_construct.nginx_file}") + nginx_file_content = site_construct.generate_nginx_text(raw_content) + auto_update_infos("Writing via safe stream...") + ssh.open_channel do |channel| + channel.exec("sudo -S sh -c 'cat > #{site_construct.nginx_file}'") do |ch, success| + ch.on_extended_data do |c, type, data| + if data =~ /password/i + c.send_data("#{@password}\n") + end + end + ch.send_data(nginx_file_content) + ch.eof! + end + end + ssh.loop + exec_ssh_command_by_sudo(ssh, "service nginx restart") auto_update_infos("Finish!") - end + end + def exec_command_by_user(session,command) output = session.exec!(command) return output[0...-1].gsub(/^\n[\n]+/,'')