ProtonVPN / proton-vpn-gtk-app

Official ProtonVPN Linux app
https://protonvpn.com/download-linux
GNU General Public License v3.0
152 stars 20 forks source link

Systemctl autostart protonvpn-cli without call to login #26

Closed CodeGorila closed 2 months ago

CodeGorila commented 5 months ago

Hi @natanjunges, don't you have to call protonvpn-cli login first? Also, how do you specify the password as it isn't an argument to the command?

Hey @toxpal So to answer to some of your questions:

  1. It is planned, but until then you could use something that linux already offers out-of-the box, a .service configuration within --user space. Also not sure by what you mean about the killswitch, could you please provide more details ?

How exactly would one go about doing this? I currently have Protonvpn configured to start on boot using Manjaro's Autostart feature, however the VPN will not automatically turn on, and must be activated manually. Is there a way to auto-activate the connection in addition to simply auto-opening the application? If not, is this feature in the works?

I created a systemd service in user space, as @calexandru2018 mentioned. It works quite well, it waits for network-online.target (it needs NetworkManager to be fully initialized), connects automatically, opens the GUI and disconnects automatically on logout. It also restarts itself in case it fails to start.

[Unit]
Description=ProtonVPN autostart

[Service]
Type=oneshot
RemainAfterExit=yes
# Waits until it is online. It is required because system targets cannot be used in user services.
ExecStartPre=sh -c "until systemctl is-active network-online.target; do sleep 1; done"
ExecStart=protonvpn-cli c -f
ExecStartPost=-sh -c "protonvpn &"
TimeoutStartSec=30
ExecStop=protonvpn-cli d
Restart=on-failure

[Install]
WantedBy=default.target

To use it, just save it in ~/.config/systemd/user/protonvpn-autostart.service, reload the systemd daemon with systemctl --user daemon-reload and enable it with systemctl --user enable protonvpn-autostart.

I could not get it working reliably with Kill Switch enabled at first, but the solution from https://github.com/ProtonVPN/linux-cli/issues/44#issuecomment-911701915 seems to have worked. Just insert these two lines after RemainAfterExit=yes:

ExecStartPre=-protonvpn-cli ks --off
ExecStartPre=-protonvpn-cli ks --on

Then reload the systemd daemon with systemctl --user daemon-reload.

Originally posted by @natanjunges in https://github.com/ProtonVPN/linux-app/issues/4#issuecomment-953313052

CodeGorila commented 5 months ago

I am interested in your answer. However, in the interim, for others, I had to create a shell script with expect/send:

/usr/bin/expect <<EOD

spawn protonvpn-cli login YourUserNameHere
expect "Enter your Proton VPN password*"
send "YourPasswordHere\r"
expect eof

spawn protonvpn-cli c -f
expect eof

EOD
calexandru2018 commented 2 months ago

Closing this ticket as it's not relevant for this project.