dmenu run scripts v2.0
This commit is contained in:
parent
02dfa63d82
commit
17ab0d5f94
171
dmenu_protonvpn
Executable file
171
dmenu_protonvpn
Executable file
|
@ -0,0 +1,171 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
################################################################
|
||||||
|
# Script for manage your ProtonVPN connections (Dmenu VERSION) #
|
||||||
|
# Last change: 28-05-2022 #
|
||||||
|
# Author: q3aql #
|
||||||
|
# Contact: q3aql@duck.com #
|
||||||
|
# License: GPL v2.0 #
|
||||||
|
################################################################
|
||||||
|
VERSION="2.0"
|
||||||
|
M_DATE="280522"
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
protonFiles="${HOME}/protonFiles"
|
||||||
|
url_download="https://account.protonvpn.com/downloads"
|
||||||
|
url_credentials="https://account.protonvpn.com/account#openvpn"
|
||||||
|
file_credentials="/opt/dmenu_protonvpn/proton-credentials.txt"
|
||||||
|
sed_file_credentials="\/opt\/dmenu_protonvpn\/proton-credentials.txt"
|
||||||
|
menu_files="/opt/dmenu_protonvpn/menu"
|
||||||
|
|
||||||
|
list_show_files() {
|
||||||
|
echo "About"
|
||||||
|
echo "Download ProtonVPN files"
|
||||||
|
echo "Edit Credentials"
|
||||||
|
if [ -d "${protonFiles}" ] ; then
|
||||||
|
ls -1 "${protonFiles}/"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
list_show_icons() {
|
||||||
|
list_show_files | while read current_menu ; do
|
||||||
|
if [ "${current_menu}" == "About" ] ; then
|
||||||
|
echo " ${current_menu}"
|
||||||
|
elif [ "${current_menu}" == "Download ProtonVPN files" ] ; then
|
||||||
|
echo "ﯲ ${current_menu}"
|
||||||
|
elif [ "${current_menu}" == "Edit Credentials" ] ; then
|
||||||
|
echo " ${current_menu}"
|
||||||
|
else
|
||||||
|
echo " ${current_menu}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
case "${TERM}" in
|
||||||
|
xterm-color|*-256color) color_prompt=yes;;
|
||||||
|
esac
|
||||||
|
if [ "${color_prompt}" == "yes" ] ; then
|
||||||
|
blue='\e[34m' ; red='\e[31m' ; yellow='\e[33m'
|
||||||
|
purple='\e[35m' ; green='\e[32m' ; end='\e[0m'
|
||||||
|
else
|
||||||
|
blue='' ; red='' ; yellow='' ; morado=''
|
||||||
|
verde='' ; end=''
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f /usr/bin/kitty ] ; then
|
||||||
|
termrun="kitty --title dmenu_proton -c=/opt/dmenu_protonvpn/config/kitty.conf -e"
|
||||||
|
else
|
||||||
|
xrdb -load /opt/dmenu_protonvpn/config/Xresources
|
||||||
|
termrun="xterm -T dmenu_proton -e"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create proton-openvpn-files folder
|
||||||
|
mkdir -p ${protonFiles}
|
||||||
|
|
||||||
|
function openBrowser() {
|
||||||
|
if [ -f /usr/bin/x-www-browser ] ; then
|
||||||
|
/usr/bin/x-www-browser ${1} &
|
||||||
|
else
|
||||||
|
if [ -f /usr/bin/firefox ] ; then
|
||||||
|
/usr/bin/firefox ${1}
|
||||||
|
else
|
||||||
|
if [ -f /usr/bin/brave-browser ] ; then
|
||||||
|
/usr/bin/brave-browser ${1}
|
||||||
|
else
|
||||||
|
if [ -f /usr/bin/google-chrome ] ; then
|
||||||
|
/usr/bin/google-chrome ${1} &
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function insertCredentials() {
|
||||||
|
if [ -f "${1}" ] ; then
|
||||||
|
check_credentials=$(cat "${1}" | grep "auth-user-pass ${file_credentials}")
|
||||||
|
if [ -z "${check_credentials}" ] ; then
|
||||||
|
sed -i "s/auth-user-pass/auth-user-pass ${sed_file_credentials}/g" "${1}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function editCredentials() {
|
||||||
|
user_openvpn=$(zenity --entry --title "dmenu_protonvpn ${VERSION} (${M_DATE})" \
|
||||||
|
--text "URL Credentials ${url_credentials}\n\nUser OpenVPN / IKEv2:" --entry-text "USER-HERE")
|
||||||
|
pass_openvpn=$(zenity --entry --title "dmenu_protonvpn ${VERSION} (${M_DATE})" \
|
||||||
|
--text "URL Credentials ${url_credentials}\n\nPassword OpenVPN / IKEv2:" --entry-text "PASSWORD-HERE")
|
||||||
|
if [ -z "${user_openvpn}" ] ; then
|
||||||
|
echo "# User / Password canceled"
|
||||||
|
else
|
||||||
|
echo "${user_openvpn}" > ${file_credentials}
|
||||||
|
echo "${pass_openvpn}" >> ${file_credentials}
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkFileCredentials() {
|
||||||
|
check_file=$(cat ${file_credentials} 2> /dev/null | wc -l)
|
||||||
|
if [ ${check_file} -ne 2 ] ; then
|
||||||
|
editCredentials
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function showAbout() {
|
||||||
|
zenity --title "About" --window-icon=${iconPath} --info --width=330 \
|
||||||
|
--text "Software: dmenu_protonvpn ${VERSION} (${M_DATE})\nAuthor: q3aql\nContact: q3aql@duck.com\nLicense: GPL v2.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
function downloadProtonVPNFiles() {
|
||||||
|
openBrowser "${url_download}"
|
||||||
|
zenity --title "dmenu_protonvpn ${VERSION} (${M_DATE})" --window-icon=${iconPath} --info --width=400 \
|
||||||
|
--text "* Steps for download .ovpn files:\n\n - Open URL: ${url_download}\n - Login with your Proton account\n - Click to Downloads > OpenVPN configuration files\n - Download .ovpn files and copy to ${HOME}/protonFiles\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
list_output=$(list_show_icons | /opt/dmenu_protonvpn/dmenu "$@" -p "嬨 dmenu_protonvpn v${VERSION}")
|
||||||
|
run_output=$(echo "${list_output}" | cut -c4-999)
|
||||||
|
echo "${run_output} # Selected"
|
||||||
|
if [ "${run_output}" == " About" ] ; then
|
||||||
|
if [ -f /usr/bin/zenity ] ; then
|
||||||
|
showAbout
|
||||||
|
else
|
||||||
|
echo ${termrun} ${menu_files}/about.sh
|
||||||
|
${termrun} ${menu_files}/about.sh
|
||||||
|
fi
|
||||||
|
elif [ "${run_output}" == " Download ProtonVPN files" ] ; then
|
||||||
|
if [ -f /usr/bin/zenity ] ; then
|
||||||
|
downloadProtonVPNFiles
|
||||||
|
else
|
||||||
|
echo ${termrun} "${menu_files}/download-protonvpn-files.sh"
|
||||||
|
${termrun} "${menu_files}/download-protonvpn-files.sh"
|
||||||
|
fi
|
||||||
|
elif [ "${run_output}" == " Edit Credentials" ] ; then
|
||||||
|
if [ -f /usr/bin/zenity ] ; then
|
||||||
|
editCredentials
|
||||||
|
else
|
||||||
|
echo ${termrun} "${menu_files}/edit-credentials.sh"
|
||||||
|
${termrun} "${menu_files}/edit-credentials.sh"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if [ -z "${run_output}" ] ; then
|
||||||
|
echo > /dev/null
|
||||||
|
else
|
||||||
|
if [ -f /usr/bin/sudo ] ; then
|
||||||
|
run_output=$(echo ${run_output} | tr -s " ")
|
||||||
|
cp -rf ${protonFiles}/${run_output} /tmp/
|
||||||
|
insertCredentials /tmp/${run_output}
|
||||||
|
echo ""
|
||||||
|
echo -e "${green}* Connecting using file ${end}${yellow}${protonFiles}/${run_output}${end}${purple}"
|
||||||
|
${termrun} sudo openvpn /tmp/${run_output}
|
||||||
|
echo -e "${end}${red}* Connection closed${end}"
|
||||||
|
echo -ne "${green}+ Press ${end}${purple}ENTER${end}${green} to return menu${end} " ; read return
|
||||||
|
else
|
||||||
|
run_output=$(echo ${run_output} | tr -s " ")
|
||||||
|
cp -rf ${protonFiles}/${run_output} /tmp/
|
||||||
|
insertCredentials /tmp/${run_output}
|
||||||
|
echo ""
|
||||||
|
echo -e "${green}* Connecting using file ${end}${yellow}${protonFiles}/${run_output}${end}${purple}"
|
||||||
|
${termrun} su -c "openvpn /tmp/${run_output}"
|
||||||
|
echo -e "${end}${red}* Connection closed${end}"
|
||||||
|
echo -ne "${green}+ Press ${end}${purple}ENTER${end}${green} to return menu${end} " ; read return
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
244
dmenu_protonvpn_cli
Executable file
244
dmenu_protonvpn_cli
Executable file
|
@ -0,0 +1,244 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
################################################################
|
||||||
|
# Script for manage your ProtonVPN connections (CLI VERSION) #
|
||||||
|
# Last change: 28-05-2022 #
|
||||||
|
# Author: q3aql #
|
||||||
|
# Contact: q3aql@duck.com #
|
||||||
|
# License: GPL v2.0 #
|
||||||
|
################################################################
|
||||||
|
VERSION="2.0"
|
||||||
|
M_DATE="280522"
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
protonFiles="${HOME}/protonFiles"
|
||||||
|
url_download="https://account.protonvpn.com/downloads"
|
||||||
|
url_credentials="https://account.protonvpn.com/account#openvpn"
|
||||||
|
file_credentials="/opt/dmenu_protonvpn/proton-credentials.txt"
|
||||||
|
sed_file_credentials="\/opt\/dmenu_protonvpn\/proton-credentials.txt"
|
||||||
|
menu_files="/opt/dmenu_protonvpn/menu"
|
||||||
|
|
||||||
|
case "${TERM}" in
|
||||||
|
xterm-color|*-256color) color_prompt=yes;;
|
||||||
|
esac
|
||||||
|
if [ "${color_prompt}" == "yes" ] ; then
|
||||||
|
blue='\e[34m' ; red='\e[31m' ; yellow='\e[33m'
|
||||||
|
purple='\e[35m' ; green='\e[32m' ; end='\e[0m'
|
||||||
|
else
|
||||||
|
blue='' ; red='' ; yellow='' ; morado=''
|
||||||
|
verde='' ; end=''
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create proton-openvpn-files folder
|
||||||
|
mkdir -p ${protonFiles}
|
||||||
|
|
||||||
|
list_dependencies="openvpn sed"
|
||||||
|
for dep in ${list_dependencies}; do
|
||||||
|
if [ -f /usr/bin/${dep} ] ; then
|
||||||
|
echo > /dev/null
|
||||||
|
elif [ -f /bin/${dep} ] ; then
|
||||||
|
echo > /dev/null
|
||||||
|
elif [ -f /usr/sbin/${dep} ] ; then
|
||||||
|
echo > /dev/null
|
||||||
|
elif [ -f /usr/local/bin/${dep} ] ; then
|
||||||
|
echo > /dev/null
|
||||||
|
elif [ -f /usr/local/sbin/${dep} ] ; then
|
||||||
|
echo > /dev/null
|
||||||
|
else
|
||||||
|
echo ""
|
||||||
|
echo -e "${green}* dmenu_protonvpn_cli${end}${purple} v${VERSION} ${end}${green}(${M_DATE})${end}"
|
||||||
|
echo ""
|
||||||
|
echo -e "${blue}+ The ${end}${red}'${dep}' ${end}${blue}tool is not installed!${end}"
|
||||||
|
echo ""
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
function insertCredentials() {
|
||||||
|
if [ -f "${1}" ] ; then
|
||||||
|
check_credentials=$(cat "${1}" | grep "auth-user-pass ${file_credentials}")
|
||||||
|
if [ -z "${check_credentials}" ] ; then
|
||||||
|
sed -i "s/auth-user-pass/auth-user-pass ${sed_file_credentials}/g" "${1}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function editCredentials() {
|
||||||
|
clear
|
||||||
|
echo ""
|
||||||
|
echo -e "${green}* dmenu_protonvpn_cli${end}${purple} v${VERSION} ${end}${green}(${M_DATE})${end}"
|
||||||
|
echo ""
|
||||||
|
echo -e "${purple}+ URL Credentials:${end}${yellow} ${url_credentials}${end}"
|
||||||
|
echo ""
|
||||||
|
echo -ne "${green}* User OpenVPN / IKEv2:${end} " ; read user_openvpn
|
||||||
|
echo -ne "${green}* Password OpenVPN / IKEv2:${end} " ; read pass_openvpn
|
||||||
|
if [ -z "${user_openvpn}" ] ; then
|
||||||
|
echo "# User / Password canceled"
|
||||||
|
else
|
||||||
|
echo "${user_openvpn}" > ${file_credentials}
|
||||||
|
echo "${pass_openvpn}" >> ${file_credentials}
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkFileCredentials() {
|
||||||
|
check_file=$(cat ${file_credentials} 2> /dev/null | wc -l)
|
||||||
|
if [ ${check_file} -ne 2 ] ; then
|
||||||
|
editCredentials
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function connectprotonVPN() {
|
||||||
|
listTotal=$(ls -1 ${protonFiles}/*.ovpn 2> /dev/null | wc -l)
|
||||||
|
if [ ${listTotal} -eq 0 ] ; then
|
||||||
|
clear
|
||||||
|
echo ""
|
||||||
|
echo -e "${green}* dmenu_protonvpn_cli${end}${purple} v${VERSION} ${end}${green}(${M_DATE})${end}"
|
||||||
|
echo ""
|
||||||
|
echo -e "${green}+ ProtonVPN files:${end} ${purple}${HOME}/protonFiles${end}"
|
||||||
|
echo ""
|
||||||
|
echo -e "${red}* No configuration files found! (*.ovpn)${end}"
|
||||||
|
echo ""
|
||||||
|
echo -e "${yellow}+ INFO:${end}${green} Follow the steps to download the configuration files${end}"
|
||||||
|
echo ""
|
||||||
|
echo -ne "${green}+ Press ${end}${purple}ENTER${end}${green} to return menu${end} " ; read return
|
||||||
|
else
|
||||||
|
clear
|
||||||
|
checkFileCredentials
|
||||||
|
initialList=1
|
||||||
|
completeList=""
|
||||||
|
clear
|
||||||
|
echo ""
|
||||||
|
echo -e "${green}* dmenu_protonvpn_cli${end}${purple} v${VERSION} ${end}${green}(${M_DATE})${end}"
|
||||||
|
echo ""
|
||||||
|
echo -e "${green}+ ProtonVPN files:${end} ${purple}${HOME}/protonFiles${end}"
|
||||||
|
echo ""
|
||||||
|
echo -e "${green}* Type number of entry to connect ProtonVPN:${end}"
|
||||||
|
echo ""
|
||||||
|
cd ${protonFiles}
|
||||||
|
ls -1 *.ovpn > /tmp/dmenu_protonvpn-tmp
|
||||||
|
while [ ${initialList} -le ${listTotal} ] ; do
|
||||||
|
entryRead=$(cat /tmp/dmenu_protonvpn-tmp | head -${initialList} | tail -1)
|
||||||
|
echo -e " ${red}${initialList}${end}${purple} -->${end}${green} ${entryRead}${end}"
|
||||||
|
initialList=$(expr ${initialList} + 1)
|
||||||
|
done
|
||||||
|
rm -rf /tmp/dmenu_protonvpn-tmp
|
||||||
|
echo ""
|
||||||
|
echo -e " ${red}r${end}${purple} -->${end}${green} Return to menu (cancel)${end}"
|
||||||
|
echo ""
|
||||||
|
echo -ne "${green}+ ${end}${purple}[Default:${end}${red} r${end}${purple}]${end}${green} Type option:${end} " ; read option_proton
|
||||||
|
if [ -z "${option_proton}" ] ; then
|
||||||
|
showMainMenu
|
||||||
|
elif [ "${option_proton}" == "r" ] ; then
|
||||||
|
showMainMenu
|
||||||
|
else
|
||||||
|
if [ -z "${option_proton}" ] ; then
|
||||||
|
showMainMenu
|
||||||
|
else
|
||||||
|
entryRead=$(cat /tmp/dmenu_protonvpn-tmp | head -${option_proton} | tail -1)
|
||||||
|
insertCredentials ${protonFiles}/${entryRead}
|
||||||
|
echo ""
|
||||||
|
echo -e "${green}* Connecting using file ${end}${yellow}${protonFiles}/${entryRead}${end}${purple}"
|
||||||
|
if [ -f /usr/bin/sudo ] ; then
|
||||||
|
sudo openvpn ${protonFiles}/${entryRead}
|
||||||
|
else
|
||||||
|
su -c "openvpn ${protonFiles}/${entryRead}"
|
||||||
|
fi
|
||||||
|
echo -e "${end}${red}* Connection closed${end}"
|
||||||
|
echo -ne "${green}+ Press ${end}${purple}ENTER${end}${green} to return menu${end} " ; read return
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function showAbout() {
|
||||||
|
clear
|
||||||
|
echo ""
|
||||||
|
echo -e "${green}* About:${end}"
|
||||||
|
echo ""
|
||||||
|
echo -e " ${red}-${end} ${green}Software:${end}${purple} dmenu_protonvpn_cli ${VERSION} (${M_DATE})${end}"
|
||||||
|
echo -e " ${red}-${end} ${green}Author:${end}${purple} q3aql${end}"
|
||||||
|
echo -e " ${red}-${end} ${green}Contact:${end}${purple} q3aql@duck.com${end}"
|
||||||
|
echo -e " ${red}-${end} ${green}License:${end}${purple} GPL v2.0${end}"
|
||||||
|
echo ""
|
||||||
|
echo -ne "${green}+ Press ${end}${purple}ENTER${end}${green} to return menu${end} " ; read return
|
||||||
|
}
|
||||||
|
|
||||||
|
function downloadProtonVPNFiles() {
|
||||||
|
clear
|
||||||
|
echo ""
|
||||||
|
echo -e "${green}* dmenu_protonvpn_cli${end}${purple} v${VERSION} ${end}${green}(${M_DATE})${end}"
|
||||||
|
echo ""
|
||||||
|
echo -e " ${purple}* Steps for download .ovpn files:${end}"
|
||||||
|
echo ""
|
||||||
|
echo -e " ${red}-${end}${green} Open URL: ${end}${yellow}${url_download}${end}"
|
||||||
|
echo -e " ${red}-${end}${green} Login with your Proton account${end}"
|
||||||
|
echo -e " ${red}-${end}${green} Click to Downloads > OpenVPN configuration files${end}"
|
||||||
|
echo -e " ${red}-${end}${green} Download *.ovpn files and copy to ${end}${yellow}/home/<user>/protonFiles${end}"
|
||||||
|
echo ""
|
||||||
|
echo -ne "${green}+ Press ${end}${purple}ENTER${end}${green} to return menu${end} " ; read return
|
||||||
|
}
|
||||||
|
|
||||||
|
function showMainMenu() {
|
||||||
|
showMenu=0
|
||||||
|
while [ ${showMenu} -eq 0 ] ; do
|
||||||
|
clear
|
||||||
|
echo ""
|
||||||
|
echo -e "${green}* dmenu_protonvpn_cli${end}${purple} v${VERSION} ${end}${green}(${M_DATE})${end}"
|
||||||
|
echo ""
|
||||||
|
echo -e "${green}+ ProtonVPN files:${end} ${purple}${HOME}/protonFiles${end}"
|
||||||
|
echo ""
|
||||||
|
echo -e " ${red}c${end}${purple} --> ${end}${green}Select protonVPN file to connect${end}"
|
||||||
|
echo -e " ${red}d${end}${purple} --> ${end}${green}Download ProtonVPN files${end}"
|
||||||
|
echo -e " ${red}e${end}${purple} --> ${end}${green}Edit Credentials${end}"
|
||||||
|
echo -e " ${red}a${end}${purple} --> ${end}${green}About${end}"
|
||||||
|
echo ""
|
||||||
|
echo -e " ${red}q${end}${purple} --> ${end}${green}Exit${end}"
|
||||||
|
echo ""
|
||||||
|
echo -ne "${green}* Type the option (example: ${end}${purple}c${end}${green}):${end} " ; read opcion
|
||||||
|
cancel=$?
|
||||||
|
if [ ${cancel} -eq 1 ] ; then
|
||||||
|
showMenu=1
|
||||||
|
exit
|
||||||
|
else
|
||||||
|
if [ "${opcion}" == "c" ] ; then
|
||||||
|
connectprotonVPN
|
||||||
|
elif [ "${opcion}" == "s" ] ; then
|
||||||
|
showprotonVPNfiles
|
||||||
|
elif [ "${opcion}" == "d" ] ; then
|
||||||
|
downloadProtonVPNFiles
|
||||||
|
elif [ "${opcion}" == "e" ] ; then
|
||||||
|
editCredentials
|
||||||
|
elif [ "${opcion}" == "a" ] ; then
|
||||||
|
showAbout
|
||||||
|
elif [ "${opcion}" == "q" ] ; then
|
||||||
|
rm -rf /tmp/proton-openvpn-home
|
||||||
|
showMenu=1
|
||||||
|
exit
|
||||||
|
else
|
||||||
|
echo ""
|
||||||
|
echo -e "${red}+ Choose one of the menu options.${end}"
|
||||||
|
echo ""
|
||||||
|
echo -ne "${green}+ Press ${end}${purple}ENTER${end}${green} to return menu${end} " ; read return
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
function createProtonDir() {
|
||||||
|
mkdir -p ${protonFiles}
|
||||||
|
chmod 777 -R ${protonFiles}
|
||||||
|
lista_usuarios=$(ls -1 /home)
|
||||||
|
for usuario in ${lista_usuarios} ; do
|
||||||
|
if [ -d /home/${usuario}/protonFiles ] ; then
|
||||||
|
echo > /dev/null
|
||||||
|
else
|
||||||
|
cd /home/${usuario}
|
||||||
|
ln -s ${protonFiles} protonFiles
|
||||||
|
chmod 777 -R protonFiles
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
checkAdministrator
|
||||||
|
createProtonDir
|
||||||
|
showMainMenu
|
Loading…
Reference in New Issue
Block a user