Created
July 22, 2024 14:40
-
-
Save Joaquim3/71206732f7f94c70b8eb191fb2c83d0b to your computer and use it in GitHub Desktop.
SH -> restart rustdesk service and app after having selected a Network
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| #--------------------------------------------------------------- | |
| # -> filename : rustdesk.sh | |
| # -> sudo chmod u+x rustdesk.sh | |
| # -> Usage : ./rustdesk.sh | |
| # | |
| # This tool implies, that you have set multiple RustDesk Servers. | |
| # | |
| # change : xxx.xxx.xxx.xxx by your first network | |
| # change : zzz.zzz.zzz.zzz by your another network | |
| # change : MYPASSWORD by your local machine ROOT password | |
| # change : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx by the key belonging to this server | |
| # change : zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz by the key belonging to this server | |
| # change : MYUSERNAME by your local machine user name | |
| #---------------------------------------------------------------------------------------------------------------- | |
| clear | |
| echo "┌────────────────────────────────────────────────────────────────────────────┐" | |
| echo "│ This app is used for RUSTDESK │" | |
| echo "│ Purpose : restart rustdesk service and app after having selected a Network │" | |
| echo "└────────────────────────────────────────────────────────────────────────────┘" | |
| echo | |
| echo "┌─────────────────────────────────────┐" | |
| echo "│ Please, Select your Network below ! │" | |
| echo "│─────────────────────────────────────│" | |
| echo "│(0) - no server │" | |
| echo "│(1) - CLIENT 1 : xxx.xxx.xxx.xxx │" | |
| echo "│(2) - CLIENT 2 : zzz.zzz.zzz.zzz │" | |
| echo "│(*) - quit │" | |
| echo "└─────────────────────────────────────┘" | |
| #---------------------------------------------------------- | |
| #this function replaces rustdeskfile and restarts rustdesk | |
| fnc_restart_rustdesk() { | |
| array=("$@") | |
| #--------------------------------- | |
| # saving array to file | |
| #--------------------------------- | |
| rm $rustdeskfile | |
| for element in "${array[@]}" | |
| do | |
| echo "$element" >> $rustdeskfile | |
| done | |
| echo $textdisplay | |
| #restart rustdesk service | |
| #trust zone only for clear password !! | |
| echo "MYPASSWORD" | sudo -S service rustdesk restart 2> /dev/null | |
| #stop rustdesk application | |
| echo "MYPASSWORD" | sudo -S killall rustdesk 2> /dev/null | |
| echo "RustDesk Service Restarted" | |
| echo | |
| nohup rustdesk &>/dev/null & | |
| } | |
| #---------------------------------------------------------- | |
| #get the local IP Address | |
| mylocalip=$(hostname -I | cut -f1 -d' ') | |
| #rustdeskconfig file | |
| rustdeskfile="/home/MYUSERNAME/.config/rustdesk/RustDesk2.toml" | |
| #asks the user to select his network | |
| read -p "Network : " rustdesknetwork | |
| #replace content of rustdeskconfig file using user's choice | |
| case $rustdesknetwork in | |
| #--------------------------------- | |
| 0) #user selected no server | |
| array=("") | |
| textdisplay="no server : Selected." | |
| fnc_restart_rustdesk "${array[@]}" | |
| ;; | |
| #--------------------------------- | |
| 1) #user selected xxx.xxx.xxx.xxx | |
| array=("rendezvous_server = 'xxx.xxx.xxx.xxx:21116'" | |
| "nat_type = 1" | |
| "serial = 0" | |
| "[options]" | |
| "allow-linux-headless = 'Y'" | |
| "custom-rendezvous-server = 'xxx.xxx.xxx.xxx'" | |
| "local-ip-addr = '$mylocalip'" | |
| "direct-server = 'Y'" | |
| "key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'" | |
| "verification-method = 'use-permanent-password'") | |
| textdisplay="CLIENT 1 : xxx.xxx.xxx.xxx Selected." | |
| fnc_restart_rustdesk "${array[@]}" | |
| ;; | |
| #--------------------------------- | |
| 2) #user selected zzz.zzz.zzz.zzz | |
| array=("rendezvous_server = 'zzz.zzz.zzz.zzz:21116'" | |
| "nat_type = 1" | |
| "serial = 0" | |
| "[options]" | |
| "allow-linux-headless = 'Y'" | |
| "custom-rendezvous-server = 'zzz.zzz.zzz.zzz'" | |
| "local-ip-addr = '$mylocalip'" | |
| "direct-server = 'Y'" | |
| "key = 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'" | |
| "verification-method = 'use-permanent-password'") | |
| textdisplay="CLIENT 2 : zzz.zzz.zzz.zzz Selected." | |
| fnc_restart_rustdesk "${array[@]}" | |
| ;; | |
| #--------------------------------- | |
| *) #user selected any other choice | |
| echo "no choice: bye" | |
| ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment