Created
March 15, 2015 18:32
-
-
Save errzey/c92b7273325fb210bf13 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
C_RST='\e[0m' | |
C_BLUE='\e[0;34m' | |
C_RED='\e[0;31m' | |
C_BRED='\e[1;31m' | |
C_BGREEN='\e[1;32m' | |
C_BBLUE='\e[1;34m' | |
C_BMAGENTA='\e[1;35m' | |
if [ -z "$INSTALL_PREFIX" ] ; then | |
INSTALL_PREFIX="/usr/local/bin" | |
fi | |
usage() { | |
echo -e -n "Usage: ${C_BLUE}[ENV]${C_RST} $0 " | |
echo -e -n "[ ${C_BGREEN}install${C_RST} | " | |
echo -e -n " ${C_BRED}uninstall${C_RST} | " | |
echo -e " ${C_BMAGENTA}about${C_RST} ]" | |
echo -e -n "\nEnvs\n ${C_BLUE}INSTALL_PREFIX${C_RST}=${C_BBLUE}$INSTALL_PREFIX ${C_RST}\n\n" | |
} | |
about() { | |
usage | |
cat << EOF | |
c is a very simple, but useful utlility for quickly | |
compiling and executing C code without any hubbubb. | |
even in the case of blah.c, 'make blah', will leave | |
annoying artifacts which must be removed afterwards. | |
EOF | |
echo -e -n ${C_BRED} | |
cat <<EOF | |
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | |
DO NOT USE THIS AS BUILD SYSTEM, FAILURE AWAITS YOU | |
IF USED AS WHICH!! | |
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | |
EOF | |
echo -e -n ${C_RST} | |
} | |
if [ ! -f ./c ]; then | |
has_script=0 | |
else | |
has_script=1 | |
fi | |
case "${1}" in | |
uninst) | |
echo -e "${C_RED}Uninstalling c from $INSTALL_PREFIX${C_RST}" | |
if [ -d "$INSTALL_PREFIX" ]; then | |
rm -vf "$INSTALL_PREFIX/c" | |
else | |
echo -e "${C_BMAGENTA}" | |
echo "'$INSTALL_PREFIX' dir not found." | |
echo "Maybe set the INSTALL_PREFIX env?" | |
echo -e "${C_RST}" | |
exit 1 | |
fi | |
exit | |
;; | |
help) | |
usage | |
exit 1 | |
;; | |
about) | |
about | |
exit 1 | |
;; | |
inst) | |
script_file="./c" | |
if [ $has_script -eq 0 ]; then | |
curl -s https://raw.githubusercontent.com/ryanmjacobs/c/master/c >/tmp/c | |
script_file="/tmp/c" | |
fi | |
install -v -d -m 0755 "$INSTALL_PREFIX" | |
if [ $? -ne 0 ]; then | |
exit 1 | |
fi | |
install -v -m 0755 "${script_file}" "$INSTALL_PREFIX" | |
if [ $? -ne 0 ]; then | |
exit 1 | |
fi | |
if [ $has_script -eq 0 ]; then | |
if [ -f $script_file ]; then | |
rm -rf $script_file | |
fi | |
fi | |
exit 0 | |
;; | |
*) | |
usage | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment