@@ -26,6 +26,12 @@ xochitl_conf_path=/home/root/.config/remarkable/xochitl.conf
2626# Path to Xochitl data
2727xochitl_data_dir=/home/root/.local/share/remarkable/xochitl
2828
29+ # ANSI escapes for colors
30+ red=" \033[31m"
31+ green=" \033[32m"
32+ yellow=" \033[33m"
33+ reset=" \033[m"
34+
2935# Disconnect Xochitl from the cloud
3036#
3137# This is a necessary step when switching cloud servers to prevent the client
@@ -140,6 +146,43 @@ addr: $proxy_listen:443
140146YAML
141147}
142148
149+ # Check if a given server is an rmfakecloud host
150+ #
151+ # Output: Details on the given host status
152+ # Exit code:
153+ #
154+ # 0 - If the server seems to be a valid rmfakecloud host
155+ # 1 - If it’s definitely not
156+ check-upstream () {
157+ local url=" $upstream /service/json/1/test"
158+ local contents
159+ local wget_exit
160+ contents=" $( wget --output-document - --quiet " $url " 2>&1 ) " \
161+ && wget_exit=$? || wget_exit=$?
162+
163+ if [[ $wget_exit = 8 ]]; then
164+ # HTTP error, the page probably doesn't exist
165+ echo " invalid"
166+ return 1
167+ elif [[ $wget_exit = 4 ]]; then
168+ # Network error, the server probably doesn't exist or is offline
169+ echo " unreachable"
170+ return 1
171+ elif [[ $wget_exit != 0 ]]; then
172+ # Other error
173+ echo " error"
174+ return 1
175+ fi
176+
177+ if [[ $contents != ' {"Host":"local.appspot.com","Status":"OK"}' ]]; then
178+ echo " invalid"
179+ return 1
180+ fi
181+
182+ echo " working"
183+ return 0
184+ }
185+
143186# Generate a local certificate authority, add it to the system trust,
144187# and create a self-signed proxy certificate
145188install-certificates () {
@@ -280,7 +323,6 @@ uninstall() {
280323 disconnect-cloud
281324 mark-disabled
282325 systemctl disable --now rmfakecloud-proxy
283- rm -f " $conf_dir /config"
284326 uninstall-hosts
285327 uninstall-certificates
286328 set -e
@@ -291,8 +333,9 @@ help() {
291333Manage rmfakecloud-proxy. Available commands:
292334
293335 help Show this help message.
336+ status Check the current status of rmfakecloud-proxy.
294337 enable Enable rmfakecloud-proxy.
295- set-upstream Define the rmfakecloud server.
338+ set-upstream Set the upstream rmfakecloud server.
296339 disable Disable rmfakecloud-proxy."
297340}
298341
@@ -306,6 +349,42 @@ if [[ $0 = "${BASH_SOURCE[0]}" ]]; then
306349 shift
307350
308351 case $action in
352+ status)
353+ is-enabled && state=" ${green} enabled" || state=" ${red} disabled"
354+ service=" $( systemctl is-active rmfakecloud-proxy.service) " || true
355+
356+ if [[ $service = active ]]; then
357+ service=" $green$service "
358+ else
359+ service=" $yellow$service "
360+ fi
361+
362+ if ! upstream=" $( get-upstream) " ; then
363+ upstream=" (${yellow} not set$reset )"
364+ else
365+ if ! upstream_status=" $( check-upstream " $upstream " ) " ; then
366+ upstream=" $upstream ($red$upstream_status$reset )"
367+ else
368+ upstream=" $upstream ($green$upstream_status$reset )"
369+ fi
370+ fi
371+
372+ echo -e " Status: $state$reset ($service$reset )"
373+ echo -e " Upstream server: $upstream "
374+ echo
375+
376+ if is-enabled; then
377+ echo " Run \` rmfakecloudctl disable\` to disable \
378+ rmfakecloud-proxy."
379+ else
380+ echo " Run \` rmfakecloudctl enable\` to enable \
381+ rmfakecloud-proxy."
382+ fi
383+
384+ echo " Run \` rmfakecloudctl set-upstream https://<server>\` to \
385+ set the upstream server."
386+ ;;
387+
309388 enable)
310389 if is-enabled; then
311390 echo " rmfakecloud-proxy is already enabled."
@@ -337,14 +416,6 @@ if [[ $0 = "${BASH_SOURCE[0]}" ]]; then
337416 systemctl restart rmfakecloud-proxy
338417 fi
339418 fi
340-
341- if ! is-enabled; then
342- cat << MSG
343- Run the following command to enable rmfakecloud-proxy:
344-
345- $ rmfakecloudctl enable
346- MSG
347- fi
348419 ;;
349420
350421 help | -h | --help)
0 commit comments