Skip to content

Instantly share code, notes, and snippets.

@shouhei
Created June 12, 2016 07:25
Show Gist options
  • Save shouhei/3b226e492800b10635cc7d6b2d901320 to your computer and use it in GitHub Desktop.
Save shouhei/3b226e492800b10635cc7d6b2d901320 to your computer and use it in GitHub Desktop.
golang をてけとーにインストールするやーつ
#! /bin/bash
## check requirements commands
which wget 1>/dev/null 2>/dev/null;
wget_res=$?
if [ $wget_res -eq 1 ];
then
echo -e "\033[0;31merror\033[0;39m"
echo "please install wget";
exit 1;
fi
which sha256sum 1>/dev/null 2>/dev/null;
sha256_sum_res=$?
if [ $sha256_sum_res -eq 1 ];
then
echo -e "\033[0;31merror\033[0;39m"
echo "please install sha256sum";
exit 1;
fi
## check arguments
if [ $# -ne 2 ]; then
echo -e "\033[0;31merror\033[0;39m"
echo "First argument is go's binary url";
echo "Second argument is go's checksum";
exit 1
fi
## download file
#wget $1
## check sum
array=( `echo $1 | tr -s '/' ' '`)
last_index=`expr ${#array[@]} - 1`
download=${array[${last_index}]}
check_sum=`sha256sum $download`;
check_sum_result_array=(`echo $check_sum`)
if [ ${check_sum_result_array[0]} != $2 ]; then
echo -e "\033[0;31merror\033[0;39m"
echo "download file is invalid"
echo "please check url or checksum"
fi
## install go
sudo tar -C /usr/local/ -xzf $download
cat << EOC >> ~/.bashrc
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:/usr/local/go/bin
EOC
echo -e "\033[0;32minstall success\033[0;39m";
echo -e "please 'exec $SHELL' or 'source ~/.bashrc'"
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment