Hello to everyone,

Richard,thanks. I've launched the script inside the .profile file that's
inside the root folder and it worked. Thank you.

Plan B : From time to time the cloudflare connection stops working,so there
is the needing to repeat these commands :

warp-cli disconnect
warp-cli connect

At this point,I've modified the script like this one : (yes,I've been a
happy coder of BASIC and I feel the nostalgia of GOTO).


function jumpto
{
        label=$1
        cmd=$(sed -n "/$label:/{:a;n;p;ba};" $0 | grep -v ':$')
        eval "$cmd"
        exit
}

start=${1:-"start"}

jumpto $start

start:
warp-cli disconnect
OLD_IP="$(curl -s api.ipify.org)"
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -A POSTROUTING -t nat -s 192.168.1.5 -j MASQUERADE
warp-cli connect
NEW_IP="$(curl -s api.ipify.org)"
echo Connected to Cloudflare Warp...
echo OLD IP is $OLD_IP , NEW IP is $NEW_IP

mid :
if [ "$OLD_IP = $NEW_IP ]
then
echo OLD IP is $OLD_IP , NEW IP is $NEW_IP : it does not work
anymore,reconnecting...
sleep 10
jump foo
else
echo OLD IP is $OLD_IP , NEW IP is $NEW_IP : it still works.
sleep 10
fi
jumpto mid

foo:
warp-cli disconnect
OLD_IP="$(curl -s api.ipify.org)"
warp-cli connect
NEW_IP="$(curl -s api.ipify.org)"
echo OLD IP is $OLD_IP , NEW IP is $NEW_IP : it works again.
jumpto mid

On Mon, May 13, 2024 at 7:36 AM Richard <rrosn...@gmail.com> wrote:

> Should be as easy as executing the script from the .profile of root - that
> means if "log in as root" actually means root, not just sudo'ing. .profile
> will always be read as soon as the user logs in, no matter how. Through a
> terminal, a GUI, doesn't matter. No idea if doing this through systemd is
> even possible.
>
> Best
> Richard
>
> On Mon, May 13, 2024, 04:10 Mario Marietto <marietto2...@gmail.com> wrote:
>
>> Hello to everyone.
>>
>> I'm using Debian 12. I'm configuring a little Debian 12 vm with qemu that
>> I will use to forward the cloudflare connection to FreeBD.
>> What I want to do is to run the script below as soon as root has logged
>> in.
>>
>> I've configured the automatic login of root adding to this service file :
>>
>> nano /etc/systemd/system/getty.target.wants/getty@tty1.service
>>
>> this line :
>>
>> ExecStart=/sbin/agetty -o '-p -f -- \\u" --noclear --autologin root %I
>> $TERM
>>
>> Now,what I want to do is that the script below is ran as soon root is
>> able to logged in automatically :
>>
>> /usr/bin/warp
>>
>> warp-cli disconnect
>> echo 1 > /proc/sys/net/ipv4/ip_forward
>> iptables -A POSTROUTING -t nat -s 192.168.1.5 -j MASQUERADE
>> OLD_IP="$(curl -s api.ipify.org)"
>> warp-cli connect
>> NEW_IP="$(curl -s api.ipify.org)"
>> echo Connected to Cloudflare Warp...
>> echo OLD IP is : $OLD_IP,NEW IP is : $NEW_IP
>>
>> [Forgot to say that I switched boot target to text with this command :
>>
>> sudo systemctl set-default multi-user.target]
>>
>> What I tried right now has been to create a respawn service with systemd.
>> I created a file in /etc/systemd/system/ i.e. warp.service
>>
>> [Unit]
>> Desription=warp with systemd, respawn
>> After=pre-network.target
>>
>> [Service]
>> ExecStart=/usr/bin/warp
>> Restart=always
>>
>> [Install]
>> WantedBy=multi-user.target
>>
>>
>> and I've activated it :
>>
>> systemctl enable warp.service
>>
>>
>> rebooted and started it manually :
>>
>> systemctl daemon-reload
>> systemctl start warp.service
>>
>> It does not work and anyway it does not seem to be what I want...
>>
>> [image: Istantanea_2024-05-12_23-46-37.png]
>>
>> I want that the warp script is run everytime root is logged in,not
>> more,not less.
>> I suspect that the solution is easier than what I'm trying to do...
>>
>> --
>> Mario.
>>
>

-- 
Mario.

Reply via email to