Skip to content

Instantly share code, notes, and snippets.

@zhanglianxin
Last active October 21, 2021 02:47
Show Gist options
  • Save zhanglianxin/04c31310a7a908e4723e9e02d1f500df to your computer and use it in GitHub Desktop.
Save zhanglianxin/04c31310a7a908e4723e9e02d1f500df to your computer and use it in GitHub Desktop.
Generate ss address and qrcode from running docker image
#!/bin/bash
if [ ! -f /tmp/qrcli ]; then
osname=$(echo `uname` | tr '[:upper:]' '[:lower:]')
wget -qO /tmp/qrcli "https://github.com/zhanglianxin/qrc/releases/download/v0.2.0/qrc_${osname}_amd64"
fi
chmod +x /tmp/qrcli
#PUBLIC_IP4=$(wget -4t1 -qO- https://ident.me/)
PUBLIC_IP4=$(curl -s4 https://ident.me/)
#PUBLIC_IP6=$(wget -6t1 -qO- https://ident.me/)
PUBLIC_IP6=$(curl -s6 https://ident.me/)
# image: shadowsocks/shadowsocks-libev
ids=$(docker ps --filter label=maintainer='kev <noreply@datageek.info>, Sah <contact@leesah.name>' --format '{{.ID}}')
for id in $ids
do
HOST_PORT=$(docker port $id | grep 'tcp' | awk -F '->' '{print $2}' | awk -F ':' '{print $2}')
envs=$(docker inspect --format='{{range .Config.Env}}{{println .}}{{end}}' $id)
PASSWORD=$(echo $envs | tr -s ' ' '\n' | awk -F 'PASSWORD=' '{printf $2}')
METHOD=$(echo $envs | tr -s ' ' '\n' | awk -F 'METHOD=' '{printf $2}')
REMARK4="$PUBLIC_IP4:$HOST_PORT"
[[ $PUBLIC_IP6 ]] && REMARK6="[$PUBLIC_IP6]:$HOST_PORT"
printf "\nmethod=$METHOD,pwd=${PASSWORD:-$id}\n"
basecode=$(echo -n "$METHOD:${PASSWORD:-$id}" | base64)
SS_ADDR4="ss://$basecode@$PUBLIC_IP4:$HOST_PORT/?#$REMARK4"
[[ $PUBLIC_IP6 ]] && SS_ADDR6="ss://$basecode@[$PUBLIC_IP6]:$HOST_PORT/?#$REMARK6"
printf "\n$SS_ADDR4\n" && /tmp/qrcli $SS_ADDR4 && printf "\n"
[[ $PUBLIC_IP6 ]] && printf "\n$SS_ADDR6\n" && /tmp/qrcli $SS_ADDR6 && printf "\n"
done
#!/bin/bash
if [ ! -f /tmp/qrcli ]; then
osname=$(echo `uname` | tr '[:upper:]' '[:lower:]')
wget -qO /tmp/qrcli "https://github.com/zhanglianxin/qrc/releases/download/v0.2.0/qrc_${osname}_amd64"
fi
chmod +x /tmp/qrcli
PUBLIC_IP4=$(wget -4t1 -qO- https://ident.me/)
PUBLIC_IP6=$(wget -6t1 -qO- https://ident.me/)
# image: breakwa11/shadowsocksr
ids=$(docker ps --filter ancestor='breakwa11/shadowsocksr' --format '{{.ID}}')
for id in $ids
do
HOST_PORT=$(docker port $id | grep tcp | awk -F '->' '{print $2}' | awk -F ':' '{print $2}')
envs=$(docker inspect --format='{{range .Config.Env}}{{println .}}{{end}}' $id)
PASSWORD=$(echo $envs | tr -s ' ' '\n' | awk -F 'PASSWORD=' '{printf $2}')
METHOD=$(echo $envs | tr -s ' ' '\n' | awk -F 'METHOD=' '{printf $2}')
PROTOCOL=$(echo $envs | tr -s ' ' '\n' | awk -F 'PROTOCOL=' '{printf $2}')
PROTOCOLPARAM=$(echo $envs | tr -s ' ' '\n' | awk -F 'PROTOCOLPARAM=' '{printf $2}')
OBFS=$(echo $envs | tr -s ' ' '\n' | awk -F 'OBFS=' '{printf $2}')
[[ "tls1.2_ticket_auth_compatible" == $OBFS ]] && OBFS=tls1.2_ticket_auth
OBFSPARAM=$(echo $envs | tr -s ' ' '\n' | awk -F 'OBFSPARAM=' '{printf $2}')
REMARK="$PUBLIC_IP4:$HOST_PORT"
[[ $PUBLIC_IP6 ]] && REMARK6="[$PUBLIC_IP6]:$HOST_PORT"
GROUP=""
printf "protocol=$PROTOCOL,method=$METHOD,obfs=$OBFS,pwd=$PASSWORD\n"
base64pass=$(echo -n $PASSWORD | base64 | sed 's/=//g')
base64obfsparam=$(echo -n $OBFSPARAM | base64 | sed 's/=//g')
base64protoparam=$(echo -n $PROTOCOLPARAM | base64 | sed 's/=//g')
base64remarks=$(echo -n $REMARK | base64 | sed 's/=//g')
[[ $PUBLIC_IP6 ]] && base64remarks6=$(echo -n $REMARK6 | base64 | sed 's/=//g')
base64group=$(echo -n $GROUP | base64 | sed 's/=//g')
code4="$PUBLIC_IP4:$HOST_PORT:$PROTOCOL:$METHOD:$OBFS:$base64pass/?obfsparam=$base64obfsparam&protoparam=$base64protoparam&remarks=$base64remarks&group=$base64group&udpport=0&uot=0"
[[ $PUBLIC_IP6 ]] && code6="$PUBLIC_IP6:$HOST_PORT:$PROTOCOL:$METHOD:$OBFS:$base64pass/?obfsparam=$base64obfsparam&protoparam=$base64protoparam&remarks=$base64remarks6&group=$base64group&udpport=0&uot=0"
base64code4=$(echo -n $code4 | base64 | tr -d '\n' | sed 's/=//g')
[[ $PUBLIC_IP6 ]] && base64code6=$(echo -n $code6 | base64 | tr -d '\n' | sed 's/=//g')
SSR_ADDR4="ssr://$base64code4"
[[ $PUBLIC_IP6 ]] && SSR_ADDR6="ssr://$base64code6"
printf "\n$SSR_ADDR4\n" && /tmp/qrcli $SSR_ADDR4 && printf "\n"
[[ $PUBLIC_IP6 ]] && printf "\n$SSR_ADDR6\n" && /tmp/qrcli $SSR_ADDR6 && printf "\n"
done
@zhanglianxin
Copy link
Author

zhanglianxin commented Sep 23, 2019

How to use:

  • With wget

    wget -qO - https://raw | bash
  • With curl

    curl -sL https://raw | bash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment