File size: 3,379 Bytes
da88730
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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);