mirror of
https://github.com/Hizenberg469/environment-setup.git
synced 2026-04-19 21:12:23 +03:00
need to resolve issues
This commit is contained in:
266
env_setup.sh
266
env_setup.sh
@@ -5,38 +5,52 @@
|
|||||||
#ORIGINAL_DIR: Directory where this script is present
|
#ORIGINAL_DIR: Directory where this script is present
|
||||||
# along with other required utility
|
# along with other required utility
|
||||||
# to setup the Dev environment.
|
# to setup the Dev environment.
|
||||||
|
#
|
||||||
#REPO_HOSTING_PLATFORM ( Eg. github, gitlab, etc )
|
#REPO_HOSTING_PLATFORM ( Eg. github, gitlab, etc )
|
||||||
|
#
|
||||||
#CODEQUERY_GUI
|
#CODEQUERY_GUI
|
||||||
# YES - To install codequery with GUI.
|
# YES - To install codequery with GUI.
|
||||||
# NO - To install codequery without GUI.
|
# NO - To install codequery without GUI.
|
||||||
#
|
#
|
||||||
|
#INSTALL_YCM
|
||||||
|
# YES - To setup the YCM
|
||||||
|
# NO - To not setup the YCM
|
||||||
|
#
|
||||||
|
#INSTALL_CODEQUERY
|
||||||
|
# YES - To setup the codequery
|
||||||
|
# NO - To not setup the codequery
|
||||||
|
#
|
||||||
|
#INSTALL_VIM_CODEQUERY
|
||||||
|
# YES - To setup the vim-codequery
|
||||||
|
# NO - To not setup the vim-codequery
|
||||||
|
#
|
||||||
# Peform the below command before executing this script.
|
# Peform the below command before executing this script.
|
||||||
# source $PWD/env_variable
|
# source $PWD/env_variable
|
||||||
|
|
||||||
RETURN_SUCCESS=0
|
RETURN_SUCCESS=0
|
||||||
RETURN_FAILURE=255
|
RETURN_FAILURE=255
|
||||||
|
PASSWORD=""
|
||||||
my_vimrc='$ORIGINAL_DIR/my_vimrc'
|
my_vimrc='$ORIGINAL_DIR/my_vimrc'
|
||||||
essential_plugins=(
|
essential_plugins=(
|
||||||
WolfgangMehner/bash-support,
|
"WolfgangMehner/bash-support",
|
||||||
WolfgangMehner/c-support,
|
"WolfgangMehner/c-support",
|
||||||
WolfgangMehner/perl-support,
|
"WolfgangMehner/perl-support",
|
||||||
preservim/nerdtree,
|
"preservim/nerdtree",
|
||||||
luochen1990/rainbow,
|
"luochen1990/rainbow",
|
||||||
preservim/tagbar,
|
"preservim/tagbar",
|
||||||
mbbill/undotree,
|
"mbbill/undotree",
|
||||||
vim-airline/vim-airline,
|
"vim-airline/vim-airline",
|
||||||
vim-airline/vim-airline-themes,
|
"vim-airline/vim-airline-themes",
|
||||||
bfrg/vim-c-cpp-modern,
|
"bfrg/vim-c-cpp-modern",
|
||||||
kovetskiy/vim-bash,
|
"kovetskiy/vim-bash",
|
||||||
tomasiser/vim-code-dark,
|
"tomasiser/vim-code-dark",
|
||||||
ArthurSonzogni/Diagon,
|
"ArthurSonzogni/Diagon",
|
||||||
tpope/vim-commentary,
|
"tpope/vim-commentary",
|
||||||
tpope/vim-fugitive
|
"tpope/vim-fugitive"
|
||||||
)
|
)
|
||||||
|
|
||||||
optional_plugins=(
|
optional_plugins=(
|
||||||
dense-analysis/ale,
|
"dense-analysis/ale"
|
||||||
ycm-core/YouCompleteMe
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# checkStatus 1 -- To exit the script
|
# checkStatus 1 -- To exit the script
|
||||||
@@ -76,7 +90,7 @@ function printStatus {
|
|||||||
message=$1
|
message=$1
|
||||||
status=$2
|
status=$2
|
||||||
|
|
||||||
expected_status_number=0
|
expected_status_number=$RETURN_SUCCESS
|
||||||
if [ $# -gt 2 ] ; then
|
if [ $# -gt 2 ] ; then
|
||||||
expected_status_number=$2
|
expected_status_number=$2
|
||||||
fi
|
fi
|
||||||
@@ -86,7 +100,36 @@ function printStatus {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# findFileOrDir <file or dir name> {(opt)dir} {(opt)type[t|d]} {(opt)maxdepth}
|
# printStatus <message> <status> {(optional}expected-status>
|
||||||
|
function logStatus {
|
||||||
|
|
||||||
|
if [ $# -lt 2 ] || [ $# -gt 3 ] ; then
|
||||||
|
echo -e "Status message and status return value is not passed.\nNeed to fail due to incorrect script."
|
||||||
|
exit $RETURN_FAILURE
|
||||||
|
fi
|
||||||
|
|
||||||
|
message=$1
|
||||||
|
status=$2
|
||||||
|
|
||||||
|
expected_status_number=$RETURN_SUCCESS
|
||||||
|
if [ $# -gt 2 ] ; then
|
||||||
|
expected_status_number=$2
|
||||||
|
fi
|
||||||
|
|
||||||
|
findFileOrDir "status.txt" "$ORIGINAL_DIR" "f"
|
||||||
|
status=$?
|
||||||
|
if [ "$status" -ne $RETURN_SUCCESS ] ; then
|
||||||
|
touch "$ORIGINAL_DIR/status.txt"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $status -ne $expected_status_number ] ; then
|
||||||
|
echo -e "$message : Failure" >> $ORIGINAL_DIR/status.txt
|
||||||
|
else
|
||||||
|
echo -e "$message : Done" >> $ORIGINAL_DIR/status.txt
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# findFileOrDir <file or dir name> {(opt)dir} {(opt)type[f|d]}
|
||||||
# return "" if not found
|
# return "" if not found
|
||||||
# return path to where it is present if found
|
# return path to where it is present if found
|
||||||
function findFileOrDir {
|
function findFileOrDir {
|
||||||
@@ -99,7 +142,7 @@ properly used."
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
name=$1
|
name=$1
|
||||||
seach_dir="."
|
search_dir="."
|
||||||
type="f"
|
type="f"
|
||||||
|
|
||||||
if [ $# -gt 1 ] ; then
|
if [ $# -gt 1 ] ; then
|
||||||
@@ -110,16 +153,13 @@ properly used."
|
|||||||
type=$3
|
type=$3
|
||||||
fi
|
fi
|
||||||
|
|
||||||
is_present=""
|
is_present=$(find "$search_dir" -type "$type" -name "$name" | head -1)
|
||||||
if [ $# -gt 3 ] ; then
|
|
||||||
mx_depth=$3
|
|
||||||
is_present=$(find $search_dir -maxdepth $mx_depth -type $type -name $name | head -1)
|
|
||||||
else
|
|
||||||
is_present=$(find $search_dir -type $type -name $name | head -1)
|
|
||||||
fi
|
|
||||||
|
|
||||||
checkStatus 0
|
checkStatus 0
|
||||||
return $is_present
|
|
||||||
|
if [ "$is_present" = "$search_dir/$name" ] ; then
|
||||||
|
return $RETURN_SUCCESS
|
||||||
|
fi
|
||||||
|
return $RETURN_FAILURE
|
||||||
}
|
}
|
||||||
|
|
||||||
# checkPkgIsInstalled <pkg-name> {(opt)number -- whether to install the package}
|
# checkPkgIsInstalled <pkg-name> {(opt)number -- whether to install the package}
|
||||||
@@ -139,14 +179,14 @@ function checkPkgIsInstalled {
|
|||||||
to_install=$2
|
to_install=$2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
is_installed=$(dpkg-query -W -f='${binary:Package}\n' | grep -wo 'qmake' | head -1)
|
is_installed=$(dpkg-query -W -f='${binary:Package}\n' | grep -wo "$pkg_name" | head -1)
|
||||||
if [ '$is_installed' = '$pkg_name' ] ; then
|
if [ "$is_installed" = "$pkg_name" ] ; then
|
||||||
echo "$pkg_name is already installed"
|
echo "$pkg_name is already installed"
|
||||||
return $RETURN_SUCCESS # Installed
|
return $RETURN_SUCCESS # Installed
|
||||||
else
|
else
|
||||||
if [ $to_install -eq 1 ] ; then
|
if [ $to_install -eq 1 ] ; then
|
||||||
echo "Installing the package: $pkg_name"
|
echo "Installing the package: $pkg_name"
|
||||||
sudo apt install $pkg_name -y
|
echo $PASSWORD | sudo -S apt install $pkg_name -y
|
||||||
checkStatus 0 "Unsuccessful in installing $pkg_name"
|
checkStatus 0 "Unsuccessful in installing $pkg_name"
|
||||||
status=$?
|
status=$?
|
||||||
if [ $status -eq 0 ] ; then
|
if [ $status -eq 0 ] ; then
|
||||||
@@ -159,7 +199,7 @@ function checkPkgIsInstalled {
|
|||||||
return $RETURN_FAILURE # Not Installed
|
return $RETURN_FAILURE # Not Installed
|
||||||
}
|
}
|
||||||
|
|
||||||
#checkReposIsCloned <repo> <path> {(opt)to be cloned or not} {(opt)to clone recursively} {(opt)
|
#checkRepoIsCloned <repo> <path> {(opt)to be cloned or not} {(opt)to clone recursively} {(opt)
|
||||||
#hosting platform}
|
#hosting platform}
|
||||||
#{ to be cloned or not} : 1 for clonning , 0 for not clonning
|
#{ to be cloned or not} : 1 for clonning , 0 for not clonning
|
||||||
#{ to clone recursively} : 1 for YES, 0 for no
|
#{ to clone recursively} : 1 for YES, 0 for no
|
||||||
@@ -172,6 +212,7 @@ function checkRepoIsCloned {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
repo=$1
|
repo=$1
|
||||||
|
repo_name="${repo##*/}"
|
||||||
path=$2
|
path=$2
|
||||||
to_cloned=0
|
to_cloned=0
|
||||||
if [ $# -gt 2 ] ; then
|
if [ $# -gt 2 ] ; then
|
||||||
@@ -188,11 +229,11 @@ function checkRepoIsCloned {
|
|||||||
repo_hosting_platform=$4
|
repo_hosting_platform=$4
|
||||||
fi
|
fi
|
||||||
|
|
||||||
findFileOrDir "$1" "$2" "d" "1"
|
findFileOrDir "$repo_name" "$path" "d" 1
|
||||||
is_dir_present=$?
|
is_dir_present=$?
|
||||||
if [ "$is_dir_present" != "$2/$1" ] ; then
|
if [ "$is_dir_present" -eq $RETURN_FAILURE ] ; then
|
||||||
if [ $to_cloned -eq 1 ] ; then
|
if [ $to_cloned -eq 1 ] ; then
|
||||||
if [ $is_recursize -eq 1 ] ; then
|
if [ $is_recursive -eq 1 ] ; then
|
||||||
git clone --recurse-submodules "$repo_hosting_platform/$repo.git" "$path"
|
git clone --recurse-submodules "$repo_hosting_platform/$repo.git" "$path"
|
||||||
else
|
else
|
||||||
git clone "$repo_hosting_platorm/$repo.git" "$path"
|
git clone "$repo_hosting_platorm/$repo.git" "$path"
|
||||||
@@ -262,7 +303,7 @@ function setUpPluginDir {
|
|||||||
|
|
||||||
echo ".vim directory is created for plugins"
|
echo ".vim directory is created for plugins"
|
||||||
else
|
else
|
||||||
echo ".vim directoyr is already present for plugins"
|
echo ".vim directory is already present for plugins"
|
||||||
fi
|
fi
|
||||||
return $RETURN_SUCCESS
|
return $RETURN_SUCCESS
|
||||||
}
|
}
|
||||||
@@ -271,10 +312,10 @@ function setUpPluginDir {
|
|||||||
|
|
||||||
function setUpYCM {
|
function setUpYCM {
|
||||||
|
|
||||||
checkRepoIsCloned "${optional_plugins[ ${#optional_plugins[@]} - 1 ] }.git" "$HOME/.vim/pack/default/opt/" 1 1
|
checkRepoIsCloned "ycm-core/YouCompleteMe" "$HOME/.vim/pack/default/opt" 1 1
|
||||||
|
|
||||||
checkPkgIsInstalled "build-essential" 1
|
checkPkgIsInstalled "build-essential" 1
|
||||||
checkPkgIsInstalled "cmake3" 1
|
checkPkgIsInstalled "cmake" 1
|
||||||
checkPkgIsInstalled "python3-dev" 1
|
checkPkgIsInstalled "python3-dev" 1
|
||||||
|
|
||||||
cd ~/.vim/pack/default/opt/YouCompleteMe
|
cd ~/.vim/pack/default/opt/YouCompleteMe
|
||||||
@@ -283,6 +324,7 @@ function setUpYCM {
|
|||||||
checkStatus 0 "Failure!!! YCM is not configured for C/C++ projects"
|
checkStatus 0 "Failure!!! YCM is not configured for C/C++ projects"
|
||||||
status=$?
|
status=$?
|
||||||
|
|
||||||
|
cd $ORIGINAL_DIR
|
||||||
return $status
|
return $status
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,9 +374,9 @@ function setUpCodeQuery {
|
|||||||
return $RETURN_FAILURE
|
return $RETURN_FAILURE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
findFileOrDir "codequery" "$HOME/tools" "d" "2"
|
findFileOrDir "codequery" "$HOME/tools" "d"
|
||||||
is_dir_present=$?
|
is_dir_present=$?
|
||||||
if [ "$is_dir_present" != "$HOME/tools/codequery" ] ; then
|
if [ "$is_dir_present" -eq $RETURN_FAILURE ] ; then
|
||||||
mkdir -p $HOME/tools/codequery
|
mkdir -p $HOME/tools/codequery
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -356,7 +398,20 @@ function setUpCodeQuery {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
cmake --build build
|
cmake --build build
|
||||||
sudo cmake --install build
|
status=$?
|
||||||
|
checkStatus 0 "Unsuccessful in building the codequery"
|
||||||
|
if [ $status -ne 0 ] ; then
|
||||||
|
return $RETURN_FAILURE
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo $PASSWORD | sudo -S cmake --install build
|
||||||
|
status=$?
|
||||||
|
checkStatus 0 "Unsuccessful in installing the codequery"
|
||||||
|
if [ $status -ne 0 ] ; then
|
||||||
|
return $RETURN_FAILURE
|
||||||
|
fi
|
||||||
|
|
||||||
|
return $RETURN_SUCCESS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -368,7 +423,7 @@ function setUpVimCodeQuery {
|
|||||||
return $RETURN_FAILURE
|
return $RETURN_FAILURE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
checkReposIsCloned "devjoe/vim-codequery" "$HOME/.vim/pack/default/opt/" 1
|
checkRepoIsCloned "devjoe/vim-codequery" "$HOME/.vim/pack/default/opt/" 1
|
||||||
status=$?
|
status=$?
|
||||||
if [ $status -ne 0 ] ; then
|
if [ $status -ne 0 ] ; then
|
||||||
return $RETURN_FAILURE
|
return $RETURN_FAILURE
|
||||||
@@ -381,4 +436,129 @@ BANNER=$(<banner.txt)
|
|||||||
echo "$BANNER"
|
echo "$BANNER"
|
||||||
|
|
||||||
|
|
||||||
|
# Start the setup
|
||||||
|
environment_variable=(
|
||||||
|
"ORIGINAL_DIR",
|
||||||
|
"REPO_HOSTING_PLATFORM",
|
||||||
|
"CODEQUERY_GUI",
|
||||||
|
"INSTALL_YCM",
|
||||||
|
"INSTALL_CODEQUERY",
|
||||||
|
"INSTALL_VIM_CODEQUERY"
|
||||||
|
)
|
||||||
|
|
||||||
|
echo "Do you want to create the template for env_variable file to configure you setup?"
|
||||||
|
choise=""
|
||||||
|
echo "yes : To create the template and quit to configure it"
|
||||||
|
echo "no : To move on with configuration"
|
||||||
|
read -p "Your choise : " choise
|
||||||
|
|
||||||
|
if [ "$choise" = "yes" ] ; then
|
||||||
|
rm $PWD/env_variable
|
||||||
|
touch $PWD/env_variable
|
||||||
|
|
||||||
|
|
||||||
|
for env_var in "${!environment_variable[@]}";
|
||||||
|
do
|
||||||
|
echo "$env_var=" >> $PWD/env_variable
|
||||||
|
done
|
||||||
|
|
||||||
|
exit $RETURN_SUCCESS
|
||||||
|
elif [ "$choise" = "no" ] ; then
|
||||||
|
|
||||||
|
findFileOrDir "env_variable" "$PWD" "f"
|
||||||
|
status=$?
|
||||||
|
if [ "$status" -eq $RETURN_FAILURE ] ; then
|
||||||
|
echo "env_variable is not present"
|
||||||
|
echo "Create the template and configure it first"
|
||||||
|
exit $RETURN_FAILURE
|
||||||
|
fi
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
echo "Error: Entered unknown choise"
|
||||||
|
exit $RETURN_FAILURE
|
||||||
|
fi
|
||||||
|
|
||||||
|
source "$PWD/env_variable"
|
||||||
|
declare -A env_var_map=(
|
||||||
|
["ORIGINAL_DIR"]="$ORIGINAL_DIR"
|
||||||
|
["REPO_HOSTING_PLATFORM"]="$REPO_HOSTING_PLATFORM"
|
||||||
|
["CODEQUERY_GUI"]="$CODEQUERY_GUI"
|
||||||
|
["INSTALL_YCM"]="$INSTALL_YCM"
|
||||||
|
["INSTALL_CODEQUERY"]="$INSTALL_CODEQUERY"
|
||||||
|
["INSTALL_VIM_CODEQUERY"]="$INSTALL_VIM_CODEQUERY"
|
||||||
|
)
|
||||||
|
|
||||||
|
echo "Are you sure about the below configuration?"
|
||||||
|
for env_var in "${!env_var_map[@]}";
|
||||||
|
do
|
||||||
|
echo "$env_var : ${env_var_map["$env_var"]}"
|
||||||
|
done
|
||||||
|
|
||||||
|
choise=""
|
||||||
|
echo "yes : To move on with the current configuration for setup"
|
||||||
|
echo "no : To quit the setup"
|
||||||
|
read -p "Your choise : " choise
|
||||||
|
|
||||||
|
if [ "$choise" = "no" ] ; then
|
||||||
|
exit $RETURN_SUCCESS
|
||||||
|
elif [ "$choise" = "yes" ] ; then
|
||||||
|
echo "Moving forward with configuration"
|
||||||
|
else
|
||||||
|
echo "Error: Entered unknown choice"
|
||||||
|
exit $RETURN_FAILURE
|
||||||
|
fi
|
||||||
|
|
||||||
|
read -sp "Your password to executing requiring sudo access:" PASSWORD
|
||||||
|
|
||||||
|
rm $ORIGINAL_DIR/status.txt
|
||||||
|
# Setting the .vimrc first
|
||||||
|
setUpVimrc
|
||||||
|
status=$?
|
||||||
|
logStatus "Setting up .virmc: " $status
|
||||||
|
|
||||||
|
# Setting up the plugin directory
|
||||||
|
setUpPluginDir
|
||||||
|
status=$?
|
||||||
|
logStatus "Setting up Plugin directory: " $status
|
||||||
|
|
||||||
|
touch status.txt
|
||||||
|
# Installing the plugins
|
||||||
|
for plugins in essential_plugins
|
||||||
|
do
|
||||||
|
checkRepoIsCloned "$plugins" "$HOME/.vim/pack/default/start" 1
|
||||||
|
status=$?
|
||||||
|
logStatus "Installing $plugins: " $status
|
||||||
|
done
|
||||||
|
|
||||||
|
for plugins in optional_plugins
|
||||||
|
do
|
||||||
|
checkRepoIsCloned "$plugins" "$HOME/.vim/pack/default/opt" 1
|
||||||
|
status=$?
|
||||||
|
logStatus "Setting up $plugins: " $status
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "$INSTALL_YCM" = "YES" ] ; then
|
||||||
|
setUpYCM
|
||||||
|
status=$?
|
||||||
|
logStatus "Setting up YCM: " $status
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$INSTALL_CODEQUERY" = "YES" ] ; then
|
||||||
|
setUpCodeQuery
|
||||||
|
status=$?
|
||||||
|
logStatus "Setting up codequery: " $status
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$INSTALL_VIM_CODEQUERY" = "YES" ] ; then
|
||||||
|
setUpVimCodeQuery
|
||||||
|
status=$?
|
||||||
|
logStatus "Setting up vim-codequery: " $status
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "==================================================================="
|
||||||
|
echo "Configuration of Dev status is complete"
|
||||||
|
echo "==================================================================="
|
||||||
|
echo "Status of the configuration"
|
||||||
|
echo "+++++++++++++++++++++++++++++++++++++"
|
||||||
|
cat $ORIGINAL_DIR/status.txt
|
||||||
|
|||||||
6
env_variable
Normal file
6
env_variable
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
ORIGINAL_DIR=$PWD
|
||||||
|
INSTALL_VIM_CODEQUERY=YES
|
||||||
|
CODEQUERY_GUI=NO
|
||||||
|
INSTALL_CODEQUERY=YES
|
||||||
|
REPO_HOSTING_PLATFORM="https://github.com"
|
||||||
|
INSTALL_YCM=YES
|
||||||
4
status.txt
Normal file
4
status.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
Setting up .virmc: : Failure
|
||||||
|
Setting up Plugin directory: : Done
|
||||||
|
Installing essential_plugins: : Done
|
||||||
|
Setting up optional_plusins: : Done
|
||||||
Reference in New Issue
Block a user