summarylogtreecommitdiffstats
path: root/crd
blob: b95d4c5f21d8e1b8f6415bad77e6ebee65f477c3 (plain)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash

if [[ $(whoami) = "root" ]]
then
  echo "Please run this as a normal user!"
  exit
fi

function print_red() {
  printf "$(tput setaf 1)$1$(tput sgr0)"
}

function print_green() {
  printf "$(tput setaf 2)$1$(tput sgr0)"
}

function print_blue() {
  printf "$(tput setaf 4)$1$(tput sgr0)"
}

function status() {
  crd_status=$(/opt/google/chrome-remote-desktop/chrome-remote-desktop --get-status)
  print_blue "CRD status: ${crd_status}\n"
}

function restart() {
  /opt/google/chrome-remote-desktop/chrome-remote-desktop --stop
  rm -rf ${HOME}/.config/chrome-remote-desktop/pulseaudio*
  crd_size=$(cat ${HOME}/.config/chrome-remote-desktop/Size)
  /opt/google/chrome-remote-desktop/chrome-remote-desktop --size="${crd_size}" --start
}

function reload() {
  /opt/google/chrome-remote-desktop/chrome-remote-desktop --reload
}

function stop() {
  /opt/google/chrome-remote-desktop/chrome-remote-desktop --stop
  rm -rf ${HOME}/.config/chrome-remote-desktop/pulseaudio*
}

function start() {
  if [ ! -f ${HOME}/.chrome-remote-desktop-session ] | [ ! -f ${HOME}/.config/chrome-remote-desktop/Size ]
  then
    print_red "Seems like you haven't set this up yet. Try running "; print_green "crd --setup"; print_red ".\n"
    exit
  fi

  if [ ! -f ${HOME}/.config/chrome-remote-desktop/host#*.json ]
  then
    print_red "Seems like you haven't activated CRD in your browser. Please do that before trying to run the server.\n"
    exit
  fi

  rm -rf ${HOME}/.config/chrome-remote-desktop/pulseaudio*
  crd_size=$(cat ${HOME}/.config/chrome-remote-desktop/Size)
  /opt/google/chrome-remote-desktop/chrome-remote-desktop --size="${crd_size}" --start
}

function setup() {
  sudo gpasswd -a ${USER} chrome-remote-desktop
  print_blue "Checking working directory and session file are present\n"
  print_blue "That would be ${HOME}/.config/chrome-remote-desktop and\n"
  print_blue "${HOME}/.chrome-remote-desktop-session\n"
  [ -d ${HOME}/.config/chrome-remote-desktop ] || mkdir ${HOME}/.config/chrome-remote-desktop
  touch ${HOME}/.chrome-remote-desktop-session
  touch ${HOME}/.config/chrome-remote-desktop/Size

  if [[ -z $(cat ${HOME}/.chrome-remote-desktop-session) ]]
  then
    echo '# You will have to uncomment one of the following lines for CRD to work' > ${HOME}/.chrome-remote-desktop-session
    echo '# Remove the # and select ctrl-X to finish.' >> ${HOME}/.chrome-remote-desktop-session
    echo '# ' >> ${HOME}/.chrome-remote-desktop-session
    echo 'export $(dbus-launch)' >> ${HOME}/.chrome-remote-desktop-session
    grep -R '^Exec=' /usr/share/xsessions/ | sed 's|/usr/.*=|# exec |' >> ${HOME}/.chrome-remote-desktop-session
    print_blue 'Now entering the editor to make the appropriate changes to your session file.\n'
    read -rsp $'Press any key to continue...\n' -n1 key
    nano ${HOME}/.chrome-remote-desktop-session
  fi

  if [[ -z $(cat ${HOME}/.config/chrome-remote-desktop/Size) ]]
  then
    echo "1366x768" > ${HOME}/.config/chrome-remote-desktop/Size
    print_blue "Default size is set to 1366x768 in\n"
    print_blue "${HOME}/.config/chrome-remote-desktop/Size.\n"
    print_blue "Change this if you want another screen size on your client.\n"
    print_blue "Remember that this will affect all clients you use.\n"
    print_blue "Now entering the editor to make the appropriate changes to\n"
    print_blue "your Size file. Do not enter any comments to this file\n"
    read -rsp $'Press any key to continue...\n' -n1 key
    nano ${HOME}/.config/chrome-remote-desktop/Size
  fi

  print_blue "This completes the setup.\n\n"
  print_blue "Please remember that you will need to allow Chrome or Chromium\n"
  print_blue "to act as a server for this to work at all.\n\n"
  print_blue "To do that, open CRD in your chrome or chromium browser\n"
  print_blue "and follow the instructions. Clicking the computer will open\n"
  print_blue "it in the browser window in default resolution.\n"
  print_blue "For a more pleasant chromoting experience, just issue the command\n"
  print_green "crd --restart"
  print_blue "\nHappy chromoting! :)\n"
}

function help() {
  print_blue "Note: You will have to go into chrome or chromium to enable remote\n"
  print_blue "connections to this computer before you can run CRD on this machine.\n\n"
  print_blue "Usage: "; print_green "crd [option]"; print_blue "\n\n"
  print_blue "Options:\n\n"
  print_green "--status"
  print_blue "\nChecks whether CRD is running and returns its status\n\n"
  print_green "--start"
  print_blue "\nStarts CRD after destroying old pulse files\n\n"
  print_green "--stop"
  print_blue "\nStops CRD if running, deletes old pulse files\n\n"
  print_green "--restart"
  print_blue "\nStops and starts CRD, destroying non-functioning pulse files\n\n"
  print_green "--reload"
  print_blue "\nJust reloads CRD\n\n"
  print_green "--help, -h"
  print_blue "\nThis help message\n\n"
  print_green "--setup"
  print_blue "\nSets up CRD for your system by adding folders, sessions, users\n"
  print_blue "and stuff. You should do this first, after a fresh install. This\n"
  print_blue "will be done automatically if you just run crd without options.\n\n"
  print_blue "No sound on client? Try returning the files /etc/pulse/daemon.conf\n"
  print_blue "and /etc/pulse/client.conf to their default values, that is, the\n"
  print_blue "values commented out with a ';' – deleting any uncommented settings\n"
  print_blue "might do the trick, but use your common sense here.\n\n"
  print_blue "Need another resolution and your Display function on the client\n"
  print_blue "throws an error? You can change the client resolution in th host by\n"
  print_blue "issuing the command:\n\n"
  print_green "nano ${HOME}/.config/chrome-remote-desktop/Size"
  print_blue "\n\nand adjusting it to whatever resolution you need.\n"
  print_blue "This will affect all clients though.\n"
}

case $1 in

--status)
  status
  ;;

--restart)
  restart
  ;;

--reload)
  reload
  ;;

--stop)
  stop
  ;;

--start)
  start
  ;;

--setup)
  setup
  ;;

--help|-h)
  help
  ;;

*)
  help
  ;;

esac