Skip to content

Add conda and flatpak functionality #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions condarc.sh
Original file line number Diff line number Diff line change
@@ -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
95 changes: 95 additions & 0 deletions flatpak.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down