Major overhaul of install script
This commit is contained in:
190
install.sh
190
install.sh
@@ -16,52 +16,164 @@
|
|||||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
if [ "$1" == "--uninstall" ]; then
|
# Color codes for messages
|
||||||
rm /bin/sns
|
readonly RED_COLOR='\033[1;31m'
|
||||||
rm /usr/share/bash-completion/completions/sns
|
readonly YELLOW_COLOR='\033[1;33m'
|
||||||
exit
|
readonly RESET_COLOR='\033[0m'
|
||||||
|
|
||||||
|
if [ "$(id -u)" != "0" ]; then
|
||||||
|
printf "$RED_COLOR!$RESET_COLOR - %s\n"\
|
||||||
|
"Please run as root or specify a PREFIX= you have write access to."
|
||||||
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -d ./build ]; then
|
S="build/sns.sh"
|
||||||
mkdir build
|
|
||||||
fi
|
|
||||||
|
|
||||||
S=build/sns.sh
|
function build {
|
||||||
|
bash header.sh
|
||||||
|
echo -e "\n# Section: Functions"
|
||||||
|
cat ./src/includes/init_store.sns.sh
|
||||||
|
cat ./src/includes/verify_store.sns.sh
|
||||||
|
cat ./src/includes/help.sns.sh
|
||||||
|
cat ./src/includes/p_header.sh
|
||||||
|
cat ./src/includes/libencryption.sns.sh
|
||||||
|
cat ./src/includes/create.sns.sh
|
||||||
|
cat ./src/includes/delete.sns.sh
|
||||||
|
cat ./src/includes/edit.sns.sh
|
||||||
|
cat ./src/includes/print.sns.sh
|
||||||
|
cat ./src/includes/list.sns.sh
|
||||||
|
printf "%s\n" "# End Section: Functions"
|
||||||
|
cat ./src/main/stage1.sns.sh
|
||||||
|
cat ./src/main/stage2.sns.sh
|
||||||
|
cat ./src/main/stage3.sns.sh
|
||||||
|
}
|
||||||
|
|
||||||
bash header.sh > "$S"
|
function install {
|
||||||
echo -e "\n# Section: Functions" >> "$S"
|
mkdir -p "$PREFIX/bin"
|
||||||
cat ./src/includes/init_store.sns.sh >> "$S"
|
mkdir -p "$PREFIX/etc/bash-completion.d"
|
||||||
cat ./src/includes/verify_store.sns.sh >> "$S"
|
chmod +x "$S"
|
||||||
cat ./src/includes/help.sns.sh >> "$S"
|
|
||||||
cat ./src/includes/p_header.sh >> "$S"
|
|
||||||
cat ./src/includes/libencryption.sns.sh >> "$S"
|
|
||||||
cat ./src/includes/create.sns.sh >> "$S"
|
|
||||||
cat ./src/includes/delete.sns.sh >> "$S"
|
|
||||||
cat ./src/includes/edit.sns.sh >> "$S"
|
|
||||||
cat ./src/includes/print.sns.sh >> "$S"
|
|
||||||
cat ./src/includes/list.sns.sh >> "$S"
|
|
||||||
printf "%s\n" "# End Section: Functions" >> "$S"
|
|
||||||
cat ./src/main/stage1.sns.sh >> "$S"
|
|
||||||
cat ./src/main/stage2.sns.sh >> "$S"
|
|
||||||
cat ./src/main/stage3.sns.sh >> "$S"
|
|
||||||
|
|
||||||
chmod +x "$S"
|
cp -f "$S" "$PREFIX/bin/sns"
|
||||||
# Install SNS
|
cp -f ./build/bash-completion "$PREFIX/etc/bash-completion.d/sns"
|
||||||
if [ ! -r "/bin/sns" ]; then
|
|
||||||
sudo cp "$S" "/bin/sns"
|
}
|
||||||
else
|
|
||||||
if grep -i "simple note system" "/bin/sns" >/dev/null; then
|
function verify {
|
||||||
sudo rm /bin/sns
|
if [ ! -r "$PREFIX/bin/sns" ]; then
|
||||||
sudo cp "$S" "/bin/sns"
|
printf "$RED_COLOR!$RESET_COLOR - %s\n"\
|
||||||
|
"could not write to $PREFIX/bin/sns"
|
||||||
|
exit 15
|
||||||
|
elif [ ! -r "$PREFIX"/etc/bash-completion.d/sns ]; then
|
||||||
|
printf "$RED_COLOR!$RESET_COLOR - %s\n"\
|
||||||
|
"could not write to $PREFIX/etc/bash-completion.d/sns"
|
||||||
|
exit 15
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -z "$(which sns)" ]; then
|
||||||
|
printf "$YELLOW_COLOR*$RESET_COLOR - %s\n\t$YELLOW_COLOR%s\n$RESET_COLOR %s\n\n"\
|
||||||
|
"sns was not found in PATH. Please add"\
|
||||||
|
"export PATH=$PREFIX/bin:\$PATH"\
|
||||||
|
"to your ~/.bashrc or ~/.bash_profile"
|
||||||
|
elif [ "$(which sns)" != "$PREFIX/bin/sns" ]; then
|
||||||
|
printf "$RED_COLOR!$RESET_COLOR - %s\n\t%s\n %s\n\n"\
|
||||||
|
"Another installation of sns "\
|
||||||
|
"($(which sns))"\
|
||||||
|
" is conflicting with this one."
|
||||||
|
else
|
||||||
|
printf "$YELLOW_COLOR*$RESET_COLOR - %s\n"\
|
||||||
|
"Simple Note System was installed to $PREFIX/bin/sns successfully."
|
||||||
|
printf "$YELLOW_COLOR*$RESET_COLOR - %s\n"\
|
||||||
|
"Bash completion was installed to $PREFIX/etc/bash-completion.d/sns successfully."
|
||||||
|
|
||||||
|
fi
|
||||||
|
if grep "source $PREFIX/etc/bash-completion.d/sns" < "$BASH_SETTINGS" > /dev/null; then
|
||||||
|
SNS_BASH_COMPLETION=1;
|
||||||
|
else
|
||||||
|
SNS_BASH_COMPLETION=0;
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$SNS_BASH_COMPLETION" != "1" ]; then
|
||||||
|
printf "$YELLOW_COLOR*$RESET_COLOR - %s\n\t$YELLOW_COLOR%s\n$RESET_COLOR %s\n\n"\
|
||||||
|
"to enable bash completion, add"\
|
||||||
|
"source $PREFIX/etc/bash-completion.d/sns"\
|
||||||
|
"to your ~/.bashrc or ~/.bash_profile"
|
||||||
|
else
|
||||||
|
printf "$YELLOW_COLOR*$RESET_COLOR - %s\n"\
|
||||||
|
"Bash completion already enabled."
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function print_help {
|
||||||
|
printf "\n%s" "usage: ./install [bchiu]"
|
||||||
|
printf "\n%s" " -b | --build-only : build, but do not install sns"
|
||||||
|
printf "\n%s" " -c | --clean : clean build directory"
|
||||||
|
printf "\n%s" " -h | --help : Print this information"
|
||||||
|
printf "\n%s" " -i | --install : build and install sns"
|
||||||
|
printf "\n%s" " -u | --uninstall : remove sns from the system (will not remove notes)"
|
||||||
|
printf "\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Platform detection
|
||||||
|
if [ -z "$PREFIX" ]; then
|
||||||
|
case "$(uname)" in
|
||||||
|
"Darwin" )
|
||||||
|
PREFIX=/usr/local/opt/sns
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
PREFIX=/opt/sns
|
||||||
|
;;
|
||||||
|
esac
|
||||||
fi
|
fi
|
||||||
# Install Bash completion
|
|
||||||
if [ ! -r "/usr/share/bash-completion/completions/sns" ]; then
|
# Sanity check
|
||||||
sudo cp "src/bash-completion/sns" "/usr/share/bash-completion/completions/sns"
|
if [ -z "$PREFIX" ]; then
|
||||||
|
printf "$RED_COLOR!$RESET_COLOR - %s\n"\
|
||||||
|
"Failed to determine an install prefix please specify with PREFIX=\n"
|
||||||
|
exit 10
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -r "$HOME"/.bash_profile ]; then
|
||||||
|
BASH_SETTINGS="$HOME/.bash_profile"
|
||||||
|
elif [ -r "$HOME"/.bashrc ]; then
|
||||||
|
BASH_SETTINGS="$HOME/.bashrc"
|
||||||
else
|
else
|
||||||
if grep -i "simple note system" "/usr/share/bash-completion/completions/sns" >/dev/null; then
|
printf "$RED_COLOR!$RESET_COLOR - %s\n"\
|
||||||
sudo rm /bin/sns
|
"Failed to determine bash settings file (e.g. ~/.bashrc)"
|
||||||
sudo cp "$S" "/bin/sns"
|
exit 13
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#Argument Parsing
|
||||||
|
for ARG in "$@"; do
|
||||||
|
case "$ARG" in
|
||||||
|
-h|--help)
|
||||||
|
print_help
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
-b|--build-only)
|
||||||
|
if [ ! -d ./build ]; then mkdir ./build; fi
|
||||||
|
build > "$S"; chmod +x "$S"
|
||||||
|
cp src/bash-completion/sns ./build/bash-completion
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
-c|--clean)
|
||||||
|
if [ -d ./build ]; then rm -rf build; fi
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
-u|--uninstall)
|
||||||
|
rm -rf $PREFIX
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
-i|--install)
|
||||||
|
if [ ! -d ./build ]; then mkdir ./build; fi
|
||||||
|
build > "$S"
|
||||||
|
cp src/bash-completion/sns ./build/bash-completion
|
||||||
|
install
|
||||||
|
verify
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
print_help
|
||||||
exit
|
exit
|
||||||
|
|||||||
Reference in New Issue
Block a user