summarylogtreecommitdiffstats
path: root/crd
blob: 373786c69789633733f3673db040f4005807f5d3 (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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#! /bin/bash

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

crd_status=$(/opt/google/chrome-remote-desktop/chrome-remote-desktop --get-status)

case $1 in

--status)
  echo "CRD status: ${crd_status}"
  exit
  ;;

--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
  ;;

--reload)
  /opt/google/chrome-remote-desktop/chrome-remote-desktop --reload
  exit
  ;;

--stop)
  /opt/google/chrome-remote-desktop/chrome-remote-desktop --stop
  rm -rf $HOME/.config/chrome-remote-desktop/pulseaudio*
  exit
  ;;

--start)
  if [ ! -f $HOME/.chrome-remote-desktop-session ] | [ ! -f $HOME/.config/chrome-remote-desktop/Size ]
  then
    echo "Seems like you haven't set this up yet. Try running crd --setup."
    exit
  fi

  if [ ! -f $HOME/.config/chrome-remote-desktop/host#*.json ]
  then
    echo "Seems like you haven't activated CRD in your browser. Please do"
    echo "that before trying to run the server."
    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
  exit
  ;;

--setup)
  sudo gpasswd -a $USER chrome-remote-desktop
  echo "Checking working directory and session file are present"
  echo "That would be $HOME/.config/chrome-remote-desktop and"
  echo "$HOME/.chrome-remote-desktop-session"
  [ -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
    echo 'Now entering the editor to make the appropriate changes to'
    echo 'your session file.'
    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
    echo "Default size is set to 1366x768 in"
    echo "$HOME/.config/chrome-remote-desktop/Size."
    echo "Change this if you want another screen size on your client."
    echo "Remember that this will affect all clients you use."
    echo "Now entering the editor to make the appropriate changes to"
    echo "your Size file. Do not enter any comments to this file"
    read -rsp $'Press any key to continue...\n' -n1 key
    nano $HOME/.config/chrome-remote-desktop/Size
  fi

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

  exit
  ;;

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

*)
  if [ ! -f $HOME/.chrome-remote-desktop-session ] | [ ! -f $HOME/.config/chrome-remote-desktop/Size ]
  then
    echo "Seems like you haven't set this up yet. Try running crd --setup."
    exit
  fi

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

  if [[ $crd_status = "STARTED" ]]
  then
    echo "CRD is already running; stopping."
    /opt/google/chrome-remote-desktop/chrome-remote-desktop --stop
    rm -rf $HOME/.config/chrome-remote-desktop/pulseaudio*
    echo "Deleted old pulse audio files"
    exit
  else
    echo "CRD is not running; starting."
    echo "Deleting old pulse audio files"
    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
    exit
  fi
  ;;

esac