Bash doesn't interpet \x20 as a space in directory path

182 views Asked by At

I am trying to convert a systemd service to sysvinit, while trying to run the following service named mullvad-vpn;

#!/bin/sh
.....

. /lib/lsb/init-functions
prog=mullvad-daemon
PIDFILE=/var/run/$prog.pid
DESC="Mullvad VPN daemon"
start() {
    log_daemon_msg "Starting $DESC" "$prog"
    start_daemon -p $PIDFILE /opt/Mullvad\x20VPN/resources/mullvad-daemon -v --disable-stdout-timestamps
    if [ $? -ne 0 ]; then
        log_end_msg 1
        exit 1
    fi
    if [ $? -eq 0 ]; then
        log_end_msg 0
    fi
    exit 0
}

stop() {
    log_daemon_msg "Stopping $DESC" "$prog"
    killproc -p $PIDFILE /opt/Mullvad\x20VPN/resources/mullvad-daemon
    if [ $? -ne 0 ]; then
        log_end_msg 1
        exit 1
    fi
    if [ $? -eq 0 ]; then
        log_end_msg 0
    fi
.....

Giving me the following result;

sudo service mullvad-daemon.sh start
Starting Mullvad VPN daemon: mullvad-daemon/sbin/start-stop-daemon: unable to stat /opt/Mullvadx20VPN/resources/mullvad-daemon (No such file or directory)

I tried; double quotes around path with just a space, single quotes path with just a space, and with backslashes, double backward backslashes, to try and escape further. All with combinations of \x20 or \xa0. It works if I remove the space from the folder name and adjust directory, and while it's usable it obviously fails to load some assets. This is probably very simple and the only thing stopping it from being fully functional.

1

There are 1 answers

0
localdegen On

Thank you @user1934428 and @GordonDavisson for putting me on the right track. The solution was to wrap $exec in quotes on line 58 in /lib/lsb/init-functions;

 --chdir "$PWD" --exec "$exec" --oknodo --pidfile "$pidfile" -- "$@"

my /etc/init.d/mullvad-daemon.sh now looks like this

#!/bin/sh
### BEGIN INIT INFO
# Provides: mullvad-daemon
# Required-Start:   $syslog $local_fs 
# Required-Stop:    $syslog $local_fs 
# Should-Start: $network 
# Default-Start:    2 3 4 5
# Default-Stop:     0 1 6
# Short-Description: Mullvad VPN daemon
### END INIT INFO

. /lib/lsb/init-functions
prog=mullvad-daemon
PIDFILE=/var/run/$prog.pid
DESC="Mullvad VPN daemon"
start() {
    log_daemon_msg "Starting $DESC" "$prog"
    start_daemon -p $PIDFILE "/opt/Mullvad VPN/resources/mullvad-daemon" -v --disable-stdout-timestamps
    if [ $? -ne 0 ]; then
        log_end_msg 1
        exit 1
    fi
    if [ $? -eq 0 ]; then
        log_end_msg 0
    fi
    exit 0
}

stop() {
    log_daemon_msg "Stopping $DESC" "$prog"
    killproc -p $PIDFILE "/opt/Mullvad VPN/resources/mullvad-daemon"
    if [ $? -ne 0 ]; then
        log_end_msg 1
        exit 1
    fi
    if [ $? -eq 0 ]; then
        log_end_msg 0
    fi
}

force_reload() {
    stop
    start

}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    force-reload)
        force_reload
        ;;
    restart)
        stop
        start
        ;;

    *)
        echo "$Usage: $prog {start|stop|force-reload|restart}"
        exit 2
esac