decup_website/gencmd.js

50 lines
1.4 KiB
JavaScript
Raw Normal View History

var pacman_f = document.getElementById("pacman");
var username_f = document.getElementById("username");
var password_f = document.getElementById("pass");
var db_password_f = document.getElementById("dbpass");
var output_f = document.getElementById("output");
var cmd_el = document.getElementById("cmd");
var username, password, db_password, pacman, cmd;
function sanitize(s) {
return s
.replaceAll("\\", "\\\\")
.replaceAll('"', '\\"')
.replaceAll("'", "\\'")
.replaceAll("$", "\\$");
}
function generate_cmd(e) {
install_deps = pacman_f.value;
username = sanitize(username_f.value);
password = sanitize(password_f.value);
db_password = sanitize(db_password_f.value);
if (username && password && db_password) {
cmd_el.style.display = "block";
} else {
cmd_el.style.display = "none";
console.log("empty");
return;
}
clone_repo =
"git clone -b prototype https://git.thedroth.rocks/DecUp/platform /opt/decup";
run_ansible =
"ansible-playbook /opt/decup/install.yml --extra-vars 'adminpanel=\\\"" +
username +
'\\" panelpassword=\\"' +
password +
'\\" dbpassword=\\"' +
db_password +
"\\\"'";
cmd = install_deps + " && " + clone_repo + " && " + run_ansible;
output_f.value = 'sudo sh -c "' + cmd + '"';
resize_textarea(output_f);
}
username_f.oninput = generate_cmd;
pacman_f.onchange = generate_cmd;
password_f.oninput = generate_cmd;
db_password_f.oninput = generate_cmd;