Proton bridge

Proton bridge je brána pro standartní IMAP/SMTP klienty pro připojení do sítě k placenému účtu na Protonmail.

proton-bridge
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
### BEGIN INIT INFO
# Provides:       proton-start
# Required-Start: $local_fs $remote_fs
# Required-Stop:  $local_fs $remote_fs
# Should-Start:   $network
# Should-Stop:    $network
# Default-Start:  2 3 4 5
# Default-Stop:   0 1 6
# Short-Description: ProtonMail init script
# Description: ProtonMail init script
### END INIT INFO
 
## Requires GNU Screen
# Username what you want to run the script as.
USERNAME="chytrex"
as_user() {
        local user="$(whoami)"
        if [ "$user" == "$1" ]; then
                bash -c "$2"
        else
                if [ "$user" == "root" ]; then
                        su - "$1" -s /bin/bash -c "$2"
                else
                        if [[ "$1" == "root" ]]; then
                                error_exit INVALID_USER "This command must be executed as the user \"$1\"."
                        else
                                error_exit INVALID_USER "This command must be executed as the user \"$1\" or \"root\"."
                        fi
                fi
        fi
}
 
start(){
        nohup socat -lf /var/log/socat-imap.log tcp4-listen:1143,reuseaddr,fork,bind=10.0.3.3,su=nobody tcp:localhost:1143 &
        nohup socat -lf /var/log/socat-smtp.log tcp4-listen:1025,reuseaddr,fork,bind=10.0.3.3,su=nobody tcp:localhost:1025 &
        as_user $USERNAME "screen -dmS proton proton-bridge --cli"
        #su - chytrex -s /bin/bash -c "nohup /usr/local/bin/protonmail-bridge --noninteractive > /var/log/proton-bridge.log 2>&1 &"
}
 
stop(){
        as_user $USERNAME "/usr/bin/screen -S proton -X stuff "`echo -ne \"stop\r\"`""
        as_user $USERNAME "screen -X -S proton quit"
        pkill socat
}
 
case "$1" in
        start)
                start
        ;;
        stop)
                stop
        ;;
        restart)
                stop
                start
        ;;
esac