Skip to content

Instantly share code, notes, and snippets.

@nomsi
Last active July 4, 2025 01:05
Show Gist options
  • Save nomsi/569786a4f5895d17f296258bd73814c1 to your computer and use it in GitHub Desktop.
Save nomsi/569786a4f5895d17f296258bd73814c1 to your computer and use it in GitHub Desktop.
~/.local/bin/speedy - A speedify_cli (Speedify) wrapper for linux
#!/sbin/openrc-run
# OpenRC service file for speedify (this is how I installed it by the way
# just setup links to where you extracted it to the correct spots. (i installed in /opt)
# This isn't needed for systems using systemd, speedify packages a systemd file
name="speedify"
description="Speedify VPN Service"
command="/usr/share/speedify/SpeedifyStartup.sh"
command_args=""
#command_background=true
depend() {
after net
need net
}
start_pre() {
# no checks, just start
return 0
}
stop() {
ebegin "Stopping Speedify"
sh /usr/share/speedify/SpeedifyShutdown.sh
eend $?
}
#!/bin/bash
# emi jade <[email protected]>
# This is a wrapper for speedify_cli because i cba to setup libwebkitgtk4.0 on gentoo
# also you need a nerdfont of some kind because why not
#
# I wrote this on gentoo because thats what I use, you can download their .deb package,
# extract it, and install it accordingly.
bold=$(tput bold)
normal=$(tput sgr0)
green='\033[1;32m'
red='\033[1;31m'
cyan='\033[1;36m'
reset='\033[0m'
spinner="⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏"
spin_delay=0.1
spinner_wait() {
local pid=$1
local i=0
tput civis
while kill -0 $pid 2>/dev/null; do
printf "\r${cyan} Running speedtest... %s${reset}" "${spinner:i++%${#spinner}:1}"
sleep $spin_delay
done
tput cnorm
echo -ne "\r${cyan} Done! ${reset}\n"
}
case "$1" in
status)
adapters=$(sudo speedify_cli show adapters 2>/dev/null)
if echo "$adapters" | jq -e '.[] | select(.state == "connected")' >/dev/null; then
server=$(sudo speedify_cli show currentserver 2>/dev/null)
name=$(echo "$server" | jq -r '.friendlyName')
city=$(echo "$server" | jq -r '.city')
country=$(echo "$server" | jq -r '.country' | tr 'a-z' 'A-Z')
ip=$(echo "$server" | jq -r '.publicIP[0]')
echo -e "${green}${bold}Connected to:${reset} $bold$name$normal ($city, $country)"
echo -e "${cyan}${bold}IP:${reset} $ip"
adapter_count=$(echo "$adapters" | jq length)
if [ "$adapter_count" -ge 2 ]; then
phone_adapter=$(echo "$adapters" | jq '.[1]')
phone_name=$(echo "$phone_adapter" | jq -r '.name')
phone_isp=$(echo "$phone_adapter" | jq -r '.isp')
phone_state=$(echo "$phone_adapter" | jq -r '.state')
if [[ "$phone_state" == "connected" ]]; then
echo -e "${green}${bold}Phone:${reset} $phone_name ($phone_isp) – Connected"
else
echo -e "${red}${bold}Phone:${reset} $phone_name ($phone_isp) – Disconnected"
fi
fi
else
echo -e "${red} ! ${bold}Speedify: Disconnected${reset}"
fi
;;
connect)
target="$2"
if [[ -z "$target" ]]; then
echo -e "${red} ! ${bold}Usage:${reset} $0 connect [closest|p2p|<country>]"
exit 1
fi
result=$(sudo speedify_cli connect "$target" 2>/dev/null)
if echo "$result" | jq empty >/dev/null 2>&1; then
name=$(echo "$result" | jq -r '.friendlyName')
city=$(echo "$result" | jq -r '.city')
country=$(echo "$result" | jq -r '.country' | tr 'a-z' 'A-Z')
echo -e "${green}${bold}Connected to:${reset} $bold$name$normal ($city, $country)"
else
echo -e "${red} ! ${bold}Connection failed or unexpected output:${reset}"
echo "$result"
fi
;;
disconnect)
sudo speedify_cli disconnect >/dev/null 2>&1
echo -e "${red} ! ${bold}Disconnected${reset}"
;;
speedtest)
start_time=$(date +%s)
tmpfile=$(mktemp)
(sudo speedify_cli speedtest > "$tmpfile" 2>/dev/null) &
spinner_wait $!
result=$(<"$tmpfile")
rm "$tmpfile"
end_time=$(date +%s)
elapsed_time=$((end_time - start_time))
if ! echo "$result" | jq empty >/dev/null 2>&1; then
echo -e "${red} ! ${bold}Error:${reset} Invalid speedtest result."
echo "$result"
exit 1
fi
city=$(echo "$result" | jq -r '.[0].city // empty')
country=$(echo "$result" | jq -r '.[0].country // empty' | tr 'a-z' 'A-Z')
latency=$(echo "$result" | jq -r '.[0].latency // empty')
download_speed=$(echo "$result" | jq -r '.[0].downloadSpeed // empty')
upload_speed=$(echo "$result" | jq -r '.[0].uploadSpeed // empty')
if [[ ! "$download_speed" =~ ^[0-9]+([.][0-9]+)?$ || ! "$upload_speed" =~ ^[0-9]+([.][0-9]+)?$ ]]; then
echo -e "${red} ! ${bold}Error:${reset} Could not retrieve valid speedtest data."
exit 1
fi
download_mbps=$(echo "scale=2; $download_speed / 1000000" | bc -l)
upload_mbps=$(echo "scale=2; $upload_speed / 1000000" | bc -l)
echo -e "${bold}${cyan} Speedtest Results:${reset}"
echo -e " Location: ${city:-Unknown}, ${country:-Unknown}"
echo -e " Latency: ${latency:-??} ms"
echo -e "${bold}Download:${reset} ${download_mbps} Mbps"
echo -e "${bold}Upload:${reset} ${upload_mbps} Mbps"
echo -e "${green} Took ${elapsed_time}s${reset}"
;;
show)
shift
cmd="$*"
if [[ -z "$cmd" ]]; then
echo -e "${red} ! ${bold}Usage:${reset} $0 show <args>"
exit 1
fi
output=$(sudo speedify_cli show $cmd 2>/dev/null)
if echo "$output" | jq empty 2>/dev/null; then
echo "$output" | jq
else
echo "$output"
fi
;;
help|-h|--help)
echo -e "${bold}Speedify CLI Wrapper ([email protected])${normal}"
echo -e "${cyan}Usage:${reset} $0 {status|connect <closest|p2p|country>|disconnect|speedtest|show <args>}"
;;
*)
echo "Run with '$0 help' for usage."
exit 1
;;
*)
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment