Skip to content

Instantly share code, notes, and snippets.

@nbr23
Created October 10, 2017 22:55
Show Gist options
  • Select an option

  • Save nbr23/633dd90ba9cd885c8f45a4d10077e15e to your computer and use it in GitHub Desktop.

Select an option

Save nbr23/633dd90ba9cd885c8f45a4d10077e15e to your computer and use it in GitHub Desktop.
s/http/https/g on github repo
#! /bin/bash
if [ $# -lt 3 ]; then
echo "Usage: ./$0 repository destination exclusions"
exit 1
fi
git clone $1 $2
find $2 -type f -exec ./replace_in_file.sh {} "$3" \;
cd $2 && git status
#! /bin/bash
i=1
exclusions=$2
cat $1 | while read line; do
http=`echo $line | grep -oE 'http://[^[:space:]]+'`
if [ "$http" ]; then
if ! echo "$exclusions" | grep --quiet "$http" ; then
https=`echo $http | sed -e 's/http:\/\//https:\/\//'`
if curl -sI $https > /dev/null; then
http2=$(echo $http | sed 's/\//\\\//g')
https2=$(echo $https | sed 's/\//\\\//g' | sed 's/&/\\&/g')
echo -e "\e[32m$1: replacing $http with ${https}\e[39m"
sed -ie "$i s/$http2/$https2/" $1
else
echo -e "\e[31m$1Err: $https\e[39m"
fi
fi
fi
i=$(($i+1))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment