Skip to content

Commit

Permalink
install [bim]: Rewrote installation script
Browse files Browse the repository at this point in the history
Signed-off-by: Vihan B <contact@vihan.org>
  • Loading branch information
vihanb committed Dec 27, 2016
1 parent 2f52151 commit 8b389ef
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 108 deletions.
45 changes: 0 additions & 45 deletions bin/alias

This file was deleted.

9 changes: 0 additions & 9 deletions bin/cleanup

This file was deleted.

16 changes: 16 additions & 0 deletions bin/colors.sh
@@ -0,0 +1,16 @@
# Source: http://stackoverflow.com/a/16844327/1620622

RCol='\033[0m' # Text Reset

Bol='\033[1m'
Dim='\033[2m'

# Regular Bold Underline High Intensity BoldHigh Intens Background High Intensity Backgrounds
Bla='\033[0;30m'; BBla='\033[1;30m'; UBla='\033[4;30m'; IBla='\033[0;90m'; BIBla='\033[1;90m'; On_Bla='\033[40m'; On_IBla='\033[0;100m';
Red='\033[0;31m'; BRed='\033[1;31m'; URed='\033[4;31m'; IRed='\033[0;91m'; BIRed='\033[1;91m'; On_Red='\033[41m'; On_IRed='\033[0;101m';
Gre='\033[0;32m'; BGre='\033[1;32m'; UGre='\033[4;32m'; IGre='\033[0;92m'; BIGre='\033[1;92m'; On_Gre='\033[42m'; On_IGre='\033[0;102m';
Yel='\033[0;33m'; BYel='\033[1;33m'; UYel='\033[4;33m'; IYel='\033[0;93m'; BIYel='\033[1;93m'; On_Yel='\033[43m'; On_IYel='\033[0;103m';
Blu='\033[0;34m'; BBlu='\033[1;34m'; UBlu='\033[4;34m'; IBlu='\033[0;94m'; BIBlu='\033[1;94m'; On_Blu='\033[44m'; On_IBlu='\033[0;104m';
Pur='\033[0;35m'; BPur='\033[1;35m'; UPur='\033[4;35m'; IPur='\033[0;95m'; BIPur='\033[1;95m'; On_Pur='\033[45m'; On_IPur='\033[0;105m';
Cya='\033[0;36m'; BCya='\033[1;36m'; UCya='\033[4;36m'; ICya='\033[0;96m'; BICya='\033[1;96m'; On_Cya='\033[46m'; On_ICya='\033[0;106m';
Whi='\033[0;37m'; BWhi='\033[1;37m'; UWhi='\033[4;37m'; IWhi='\033[0;97m'; BIWhi='\033[1;97m'; On_Whi='\033[47m'; On_IWhi='\033[0;107m';
Empty file removed bin/cpm
Empty file.
105 changes: 105 additions & 0 deletions bin/gendeps.sh
@@ -0,0 +1,105 @@
source colors.sh

# Prompts
echo
echo -e " Verifying Dependencies..."
echo -e "${Dim}--------------------------------------------------------${RCol}"

# Dependency management
MISSING_DEPENDENCIES=()
report_error() {
echo -e " ${BRed}Missing${RCol}: ${Bol}$1"
}
report_found() {
echo -e " ${BGre}Found:${RCol} ${Bol}$1${RCol} $2"
}

prompt_install() {
echo -e " ${Bol}$1${RCol} not found."
while true; do
printf " is ${Bol}$1${RCol} installed (Yn): "
read -n 1 prompt_response
if [[ ! -z "$prompt_response" ]]; then
case "$prompt_response" in
Y)
should_install=true
break 2;;
n)
should_install=false
break 2;;
*) printf "\r\033[K"; ;;
esac
else
printf "\033[1A\033[K"
fi
done
echo

printf "\033[1A\033[K\033[1A\033[K"

if [ "$should_install" = true ]; then
should_rm_last=false
while true; do
printf " Path for ${Bol}$1${RCol}: "
read res_path

if [[ ! -z "$res_path" ]]; then
if [[ ! -e "$res_path" ]]; then
if [ $should_rm_last = true ]; then
printf "\033[1A\033[2K"
fi
printf "\033[1A\033[K"
echo -e " '$res_path' does not exist."
should_rm_last=true
else
if [ $should_rm_last = true ]; then
printf "\033[1A\033[K\033"
fi

printf "\033[1A\033[K"
report_found "$1" "at ${res_path}"
break
fi
fi
done
response="$res_path"
else
report_error "$1"
fi
}

# Make
if ! type "make" &> /dev/null; then
MISSING_DEPENDENCIES+="build-essential"
report_error "Make"
else
report_found "Make"
fi

# Python2
if ! type "python2-config" &> /dev/null; then
# Prompt for python
prompt_install "Python 2" "python2-config"
if [[ -z "$response" ]]; then
MISSING_DEPENDENCIES+="python2"
else
export PYTHON_PATH="$response"
fi
else
report_found "Python 2"
fi

# Insatll Dependencies
echo
for i in "${MISSING_DEPENDENCIES[@]}"; do
case "$i" in
python2)
echo -e "Installing ${Bol}Python 2.7-dev${RCol}"
if type "apt-get" &> /dev/null; then
apt-get install python2.7-dev 1> /dev/null
elif type "yum" &> /dev/null; then
yum install python-devel 1> /dev/null
fi
break;;
esac
done
60 changes: 60 additions & 0 deletions bin/genopt.sh
@@ -0,0 +1,60 @@
source colors.sh

echo
echo -e " Configuration"
echo -e "${Dim}--------------------------------------------------------${RCol}"

do_prompt_yn() {
while true; do
printf " $1 (Yn)[${Bol}$2${RCol}]: "
read -n 1 prompt_response
if [[ ! -z "$prompt_response" ]]; then
case $prompt_response in
Y)
respond_with=true
break 2;;
n)
respond_with=false
break 2;;
*) printf "\r\033[K"; ;;
esac
else
respond_with="$2"
break
fi
done

RESULT="${respond_with}"
}

do_prompt_path() {
has_run=false
while true; do
printf " $1 [${Bol}$2${RCol}]: "
read RESULT

if [[ -z "$RESULT" ]]; then
RESULT="$2"
break
elif [[ ! -e "$RESULT" ]]; then
printf "\033[K\033[A\033[K"
if [ "$has_run" = true ]; then
printf "\033[A\033[K"
fi
echo " '${RESULT}' does not exist."
has_run=true
else
break
fi
done

printf "\033[A\033K"
}

# Installation Location
do_prompt_path "Installation Location" "/usr/local/bin"
CHEDDAR_TARGET="$RESULT"

# Python
do_prompt_yn "Install Python Bindings" "Y"
CHEDDAR_BINDINGS_PYTHON="$RESULT"
37 changes: 24 additions & 13 deletions bin/install
@@ -1,14 +1,25 @@
#!/usr/bin/env bash
echo "Downloading..."
npm install
echo "Installing..."
cpath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

which realpath &> /dev/null
if [ $? -eq 0 ]; then
rp="realpath"
else
rp="readlink -f"
fi

"$($rp "$cpath/path")" /usr/local
CHEDDAR_FIG=' ________ __ __
/ ____/ /_ ___ ____/ /___/ /___ ______
/ / / __ \/ _ \/ __ / __ / __ `/ ___/
/ /___/ / / / __/ /_/ / /_/ / /_/ / /
\____/_/ /_/\___/\__,_/\__,_/\__,_/_/
'

# Colors
source colors.sh

# Print intro
echo -e "${Yel}${CHEDDAR_FIG}${RCol}"

echo -e " Welcome to the ${Bol}Cheddar${RCol} installer."
echo -e "${Dim}--------------------------------------------------------${RCol}"
echo -e "You will be prompted for various installation options"
echo -e "Press enter to specify the default value if available"
echo

# Handle Dependencies
source gendeps.sh

# Generate Script Configuration
source genopt.sh
9 changes: 0 additions & 9 deletions bin/locrc

This file was deleted.

31 changes: 0 additions & 31 deletions bin/path

This file was deleted.

4 changes: 3 additions & 1 deletion build.js
Expand Up @@ -10,6 +10,8 @@ var item;
for (var i = 0; i < dirs.length; i++) {
if (dirs[i] !== "index.js") {
item = __dirname + "/bindings/" + dirs[i] + "/";
child_process.execFileSync(path.join(__dirname, "./node_modules/.bin/node-gyp"), [ "rebuild", "-C", item ]);
let res = child_process.spawnSync(path.join(__dirname, "./node_modules/.bin/node-gyp"), [ "rebuild", "-C", item ]);
process.stdout.write(res.stdout);
process.stderr.write(res.stderr);
}
}

0 comments on commit 8b389ef

Please sign in to comment.