const { execSync } = require('child_process'); const readline = require('readline'); function run(command) { try { const output = execSync(command, { stdio: 'pipe' }); console.log(output.toString()); } catch (error) { // Log error output or message using console.log (no console.error) console.log('Error executing command:', error.stdout ? error.stdout.toString() : error.message); } } function prompt(question) { const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); return new Promise(resolve => rl.question(question, ans => { rl.close(); resolve(ans.trim()); })); } async function main() { const CRD_SSH_Code = await prompt('Google CRD SSH Code: '); const username = 'user'; const password = 'root'; const Pin = '123456'; if (!CRD_SSH_Code) { console.log('Please enter authcode from the given link'); return; } if (Pin.length < 6) { console.log('Enter a pin more or equal to 6 digits'); return; } // Create user and set password run(`sudo useradd -m ${username}`); run(`sudo adduser ${username} sudo`); run(`echo '${username}:${password}' | sudo chpasswd`); run(`sudo sed -i 's/\\/bin\\/sh/\\/bin\\/bash/g' /etc/passwd`); // Update system run('sudo apt update'); // Install Chrome Remote Desktop run('wget https://dl.google.com/linux/direct/chrome-remote-desktop_current_amd64.deb'); run('sudo dpkg --install chrome-remote-desktop_current_amd64.deb'); run('sudo apt install --assume-yes --fix-broken'); console.log('Chrome Remote Desktop Installed!'); // Install XFCE4 Desktop Environment run('export DEBIAN_FRONTEND=noninteractive'); run('sudo apt install --assume-yes xfce4 desktop-base xfce4-terminal'); run(`sudo bash -c 'echo "exec /etc/X11/Xsession /usr/bin/xfce4-session" > /etc/chrome-remote-desktop-session'`); run('sudo apt remove --assume-yes gnome-terminal'); run('sudo apt install --assume-yes xscreensaver'); run('sudo systemctl disable lightdm.service'); console.log('Installed XFCE4 Desktop Environment!'); // Install Google Chrome run('wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb'); run('sudo dpkg --install google-chrome-stable_current_amd64.deb'); run('sudo apt install --assume-yes --fix-broken'); console.log('Google Chrome Installed!'); // Add user to chrome-remote-desktop group run(`sudo adduser ${username} chrome-remote-desktop`); // Run Chrome Remote Desktop with SSH code and pin without using sudo -u or su -u // Instead, run command as the user by switching shell context manually // Using 'sudo su - username -c "command"' is avoided as per request run(`sudo bash -c 'runuser -l ${username} -c "${CRD_SSH_Code} --pin=${Pin}"'`); // Start Chrome Remote Desktop service run('sudo service chrome-remote-desktop start'); console.log('..........................................................'); console.log('..............Upgraded by Automation Habibi...............'); console.log('..........................................................'); console.log(`Log in PIN : ${Pin}`); console.log(`User Name : ${username}`); console.log(`User Pass : ${password}`); // Keep script alive indefinitely while (true) { await new Promise(resolve => setTimeout(resolve, 1000)); } } main().catch(console.log);