Skip to content

Instantly share code, notes, and snippets.

@ayweak
Created March 6, 2014 16:02
Show Gist options
  • Save ayweak/9392933 to your computer and use it in GitHub Desktop.
Save ayweak/9392933 to your computer and use it in GitHub Desktop.
proxy のある生活。
#!/bin/sh
# -*- coding: utf-8 -*-
# usage1: ~$ ./proxied_cmd.sh yum update
# usage2: ~$ ./proxied_cmd.sh --raw gem install foobar
# (https://www.ruby-forum.com/topic/48641)
# 本当は proxy_user, proxy_password を使うべき。らしい。
HOST=''
PORT=''
echo -n "ID: "
read id
stty -echo
echo -n "Password: "
read password
stty echo
echo
id_and_password=''
if [ "$1" = '--raw' ]; then
shift
id_and_password="${id}:${password}"
else
id=$(echo "$id" | sed 's/["\\]/\\&/g')
password=$(echo "$password" | sed 's/["\\]/\\&/g')
import='from urllib import quote; from sys import stdout'
quoted_list="[quote(s, '') for s in (\"${id}\", \"${password}\")]"
id_and_password=$(python -c "${import}; stdout.write(':'.join(${quoted_list}))")
fi
export http_proxy="http://${id_and_password}@${HOST}:${PORT}/"
$*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment