diff --git a/condarc.sh b/condarc.sh new file mode 100644 index 0000000..41978f6 --- /dev/null +++ b/condarc.sh @@ -0,0 +1,89 @@ +#!/bin/bash +# plugin to set "conda" proxy settings for ProxyMan +# privileges has to be set by the process which starts this script + + + + + +CONF_FILE=`readlink -f $HOME/.condarc` + +fix_new_line() { + if [[ $(tail -c 1 "$CONF_FILE" | wc --lines ) = 0 ]]; then + echo >> "$1" + fi +} + +list_proxy() { + # inefficient way as the file is read twice.. think of some better way + echo + echo "${bold}Conda proxy settings : ${normal}" + if [ "$(cat $CONF_FILE | grep PROXYMAN -i | wc -l)" -gt 0 ]; then + firstline=$(("$(grep -n -m 1 "###### START PROXYMAN CONFIG ######" $CONF_FILE | cut -d: -f1)"+1)) + lastline=$(("$(grep -n -m 1 "###### END PROXYMAN CONFIG ######" $CONF_FILE | cut -d: -f1)"-1)) + sed -n "${firstline},${lastline}p" $CONF_FILE + else + echo "${red}None${normal}" + fi +} + +unset_proxy() { + if [ ! -e "$CONF_FILE" ]; then + return + fi + if [ "$(cat $CONF_FILE | grep PROXYMAN -i | wc -l)" -gt 0 ]; then + firstline="$(grep -n -m 1 "###### START PROXYMAN CONFIG ######" $CONF_FILE | cut -d: -f1)" + lastline="$(grep -n -m 1 "###### END PROXYMAN CONFIG ######" $CONF_FILE | cut -d: -f1)" + sed -i "${firstline},${lastline}d" $CONF_FILE + fi +} + + +set_proxy() { + unset_proxy + if [ ! -e "$CONF_FILE" ]; then + touch "$CONF_FILE" + fi + + local stmt="" + if [ "$use_auth" = "y" ]; then + stmt="${username}:${password}@" + fi + + # caution: do not use / after stmt + + echo "###### START PROXYMAN CONFIG ######" >> "$CONF_FILE" + echo "proxy_servers:" >> "$CONF_FILE" + echo " http: http://${stmt}${http_host}:${http_port}" \ + >> "$CONF_FILE" + if [ "$USE_HTTP_PROXY_FOR_HTTPS" = "true" ]; then + echo " https: http://${stmt}${https_host}:${https_port}" \ + >> "$CONF_FILE" + else + echo " https: https://${stmt}${https_host}:${https_port}" \ + >> "$CONF_FILE" + fi + echo "###### END PROXYMAN CONFIG ######" >> "$CONF_FILE" +} + +which conda &> /dev/null +if [ "$?" != 0 ]; then + exit +fi + +if [ "$#" = 0 ]; then + exit +fi + + +what_to_do=$1 +case $what_to_do in + set) set_proxy + ;; + unset) unset_proxy + ;; + list) list_proxy; + ;; + *) + ;; +esac diff --git a/flatpak.sh b/flatpak.sh new file mode 100644 index 0000000..26fcddd --- /dev/null +++ b/flatpak.sh @@ -0,0 +1,95 @@ +#!/bin/bash +# plugin to set "flatpak" proxy settings for ProxyMan +# privileges has to be set by the process which starts this script + + + + + +CONF_FILE=`readlink -m $HOME/.local/share/flatpak/overrides/global` + +fix_new_line() { + if [[ $(tail -c 1 "$CONF_FILE" | wc --lines ) = 0 ]]; then + echo >> "$1" + fi +} + +list_proxy() { + echo + echo "${bold}flatpak proxy settings : ${normal}" + if [ "$(cat $CONF_FILE | grep PROXYMAN -i | wc -l)" -gt 0 ]; then + firstline=$(("$(grep -n -m 1 "###### START PROXYMAN CONFIG ######" $CONF_FILE | cut -d: -f1)"+1)) + lastline=$(("$(grep -n -m 1 "###### END PROXYMAN CONFIG ######" $CONF_FILE | cut -d: -f1)"-1)) + sed -n "${firstline},${lastline}p" $CONF_FILE + else + echo "${red}None${normal}" + fi +} + +unset_proxy() { + if [ ! -e "$CONF_FILE" ]; then + return + fi + if [ "$(cat $CONF_FILE | grep PROXYMAN -i | wc -l)" -gt 0 ]; then + firstline="$(grep -n -m 1 "###### START PROXYMAN CONFIG ######" $CONF_FILE | cut -d: -f1)" + lastline="$(grep -n -m 1 "###### END PROXYMAN CONFIG ######" $CONF_FILE | cut -d: -f1)" + sed -i "${firstline},${lastline}d" $CONF_FILE + fi +} + + +set_proxy() { + unset_proxy + if [ ! -e "$CONF_FILE" ]; then + mkdir -p $(dirname "$CONF_FILE") + touch "$CONF_FILE" + fi + + local stmt="" + if [ "$use_auth" = "y" ]; then + stmt="${username}:${password}@" + fi + + # caution: do not use / after stmt + + echo "###### START PROXYMAN CONFIG ######" >> "$CONF_FILE" + echo "[Environment]" >> "$CONF_FILE" + echo " http_proxy=http://${stmt}${http_host}:${http_port}" \ + >> "$CONF_FILE" + echo " HTTP_PROXY=http://${stmt}${http_host}:${http_port}" \ + >> "$CONF_FILE" + if [ "$USE_HTTP_PROXY_FOR_HTTPS" = "true" ]; then + echo " https_proxy=http://${stmt}${https_host}:${https_port}" \ + >> "$CONF_FILE" + echo " HTTPS_PROXY=http://${stmt}${https_host}:${https_port}" \ + >> "$CONF_FILE" + else + echo " https_proxy=https://${stmt}${https_host}:${https_port}" \ + >> "$CONF_FILE" + echo " HTTPS_PROXY=http://${stmt}${https_host}:${https_port}" \ + >> "$CONF_FILE" + fi + echo "###### END PROXYMAN CONFIG ######" >> "$CONF_FILE" +} + +which flatpak &> /dev/null +if [ "$?" != 0 ]; then + exit +fi + +if [ "$#" = 0 ]; then + exit +fi + + +what_to_do=$1 +case $what_to_do in + set) set_proxy + ;; + unset) unset_proxy + ;; + list) list_proxy + ;; + *) + ;; +esac diff --git a/main.sh b/main.sh index 02184a3..cabafb0 100755 --- a/main.sh +++ b/main.sh @@ -29,6 +29,8 @@ function _do_it_for_all() { bash "npm.sh" "$what_to_do" bash "dropbox.sh" "$what_to_do" bash "git.sh" "$what_to_do" + bash "condarc.sh" "$what_to_do" + bash "flatpak.sh" "$what_to_do" # isn't required, but still checked to avoid sudo in main all the time SUDO_CMDS="apt dnf docker" @@ -61,6 +63,10 @@ function _do_it_for_all() { ;; 9) sudo -E bash "docker.sh" "$what_to_do" ;; + 10) bash "condarc.sh" "$what_to_do" + ;; + 11) bash "flatpak.sh" "$what_to_do" + ;; *) ;; esac done @@ -152,6 +158,8 @@ function prompt_for_proxy_targets() { echo "|${bold}${red} 7 ${normal}| Dropbox" echo "|${bold}${red} 8 ${normal}| Git" echo "|${bold}${red} 9 ${normal}| Docker" + echo "|${bold}${red} 10 ${normal}| Conda" + echo "|${bold}${red} 11 ${normal}| Flatpak" echo echo "Separate multiple choices with space" echo -ne "\e[5m ? \e[0m" ; read targets