Skip to content

Commit

Permalink
Updating version of release to 0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
asa1997 committed Oct 14, 2022
1 parent c219647 commit 7e5a565
Showing 1 changed file with 352 additions and 0 deletions.
352 changes: 352 additions & 0 deletions scripts/get.besman.io
Original file line number Diff line number Diff line change
@@ -0,0 +1,352 @@
#!/bin/bash

#Install: stable

# Global variables
BESMAN_PLATFORM=$(uname)
export BESMAN_SERVICE="https://raw.githubusercontent.com"


# BESMAN_DIST_BRANCH=${BESMAN_DIST_BRANCH:-REL-${BESMAN_VERSION}}

BESMAN_NAMESPACE="Be-Secure"
BESMAN_VERSION="0.0.2"
BESMAN_ENV_REPOS="$BESMAN_NAMESPACE/besecure-ce-env-repo"
# BESMAN_DIST_BRANCH=${BESMAN_DIST_BRANCH:-REL-${BESMAN_VERSION}}



if [ -z "$BESMAN_DIR" ]; then
BESMAN_DIR="$HOME/.besman"
fi

# variables
besman_bin_folder="${BESMAN_DIR}/bin"
besman_src_folder="${BESMAN_DIR}/src"
besman_tmp_folder="${BESMAN_DIR}/tmp"
besman_stage_folder="${besman_tmp_folder}/stage"
besman_zip_file="${besman_tmp_folder}/besman-${BESMAN_VERSION}.zip"
besman_env_folder="${BESMAN_DIR}/envs"
besman_stage_folder="${besman_tmp_folder}/stage"
besman_etc_folder="${BESMAN_DIR}/etc"
besman_var_folder="${BESMAN_DIR}/var"
besman_config_file="${besman_etc_folder}/config"
besman_user_config_file="${besman_etc_folder}/user-config.cfg"
besman_bash_profile="${HOME}/.bash_profile"
besman_profile="${HOME}/.profile"
besman_bashrc="${HOME}/.bashrc"
besman_zshrc="${HOME}/.zshrc"




besman_init_snippet=$( cat << EOF
#THIS MUST BE AT THE END OF THE FILE FOR BESMAN TO WORK!!!
export BESMAN_DIR="$BESMAN_DIR"
[[ -s "${BESMAN_DIR}/bin/besman-init.sh" ]] && source "${BESMAN_DIR}/bin/besman-init.sh"
EOF
)

# OS specific support (must be 'true' or 'false').
cygwin=false;
darwin=false;
solaris=false;
freebsd=false;
case "$(uname)" in
CYGWIN*)
cygwin=true
;;
Darwin*)
darwin=true
;;
SunOS*)
solaris=true
;;
FreeBSD*)
freebsd=true
esac


echo "Looking for figlet..."
if [ -z $(which figlet) ]; then
echo "Not found."
echo "======================================================================================================"
echo " so installing figlet on your system "
sudo apt install -y figlet
#echo ""
#echo " Execute after installing figlet."
#echo "======================================================================================================"
#echo ""
#exit 1
fi

figlet Setting up BeSman >> besman.txt
cat besman.txt
rm besman.txt
# Sanity checks

echo "Looking for a previous installation of BeSman..."
if [ -d $BESMAN_DIR/bin ]; then
echo "BeSman found."
echo ""
echo "======================================================================================================"
echo " You already have BeSman installed."
echo " BeSman was found at:"
echo ""
echo " ${BESMAN_DIR}"
echo ""
echo " Please consider running the following if you need to upgrade."
echo ""
echo " $ bes selfupdate force"
echo ""
echo "======================================================================================================"
echo ""
exit 0
fi

echo "Looking for unzip..."
if [ -z $(which unzip) ]; then
echo "Not found."
echo "======================================================================================================"
echo " so installing unzip on your system "
sudo apt install -y unzip
#echo " Please install unzip on your system using your favourite package manager."
#echo ""
#echo " Restart after installing unzip."
#echo "======================================================================================================"
#echo ""
#exit 1
fi

echo "Looking for zip..."
if [ -z $(which zip) ]; then
echo "Not found."
echo "======================================================================================================"
echo " so installing zip on your system "
sudo apt install -y zip
#echo " Please install zip on your system using your favourite package manager."
#echo ""
#echo " Restart after installing zip."
#echo "======================================================================================================"
#echo ""
#exit 1
fi

echo "Looking for curl..."
if [ -z $(which curl) ]; then
echo "Not found."
echo ""
echo "======================================================================================================"
echo " so installing curl on your system "
sudo apt install -y curl
#echo " Please install curl on your system using your favourite package manager."
#echo ""
#echo " Restart after installing curl."
#echo "======================================================================================================"
#echo ""
#exit 1
fi

if [[ "$solaris" == true ]]; then
echo "Looking for gsed..."
if [ -z $(which gsed) ]; then
echo "Not found."
echo ""
echo "======================================================================================================"
echo " Please install gsed on your solaris system."
echo ""
echo " BeSman uses gsed extensively."
echo ""
echo " Restart after installing gsed."
echo "======================================================================================================"
echo ""
exit 1
fi
else
echo "Looking for sed..."
if [ -z $(which sed) ]; then
echo "Not found."
echo ""
echo "======================================================================================================"
echo " Please install sed on your system using your favourite package manager."
echo ""
echo " Restart after installing sed."
echo "======================================================================================================"
echo ""
exit 1
fi
fi


echo "Installing BeSMAN scripts..."


# Create directory structure

echo "Create distribution directories..."
mkdir -p "$besman_bin_folder"
mkdir -p "$besman_src_folder"
mkdir -p "$besman_tmp_folder"
mkdir -p "$besman_stage_folder"
mkdir -p "$besman_env_folder"
mkdir -p "$besman_etc_folder"
mkdir -p "$besman_var_folder"



echo "Prime the config file..."
echo "config selfupdate/debug_mode = true"

touch "$besman_config_file"
echo "besman_auto_answer=false" >> "$besman_config_file"
echo "besman_auto_selfupdate=false" >> "$besman_config_file"
echo "besman_insecure_ssl=false" >> "$besman_config_file"
echo "besman_curl_connect_timeout=7" >> "$besman_config_file"
echo "besman_curl_max_time=10" >> "$besman_config_file"
echo "besman_beta_channel=false" >> "$besman_config_file"
echo "besman_debug_mode=true" >> "$besman_config_file"
echo "besman_colour_enable=true" >> "$besman_config_file"

echo "Setting up user configs"
touch "$besman_user_config_file"
echo "BESMAN_VERSION=$BESMAN_VERSION" >> "$besman_user_config_file"
echo "BESMAN_USER_NAMESPACE=" >> "$besman_user_config_file"
echo "BESMAN_ENV_ROOT=$HOME/BeSman_env" >> "$besman_user_config_file"
echo "BESMAN_NAMESPACE=$BESMAN_NAMESPACE" >> "$besman_user_config_file"
echo "BESMAN_INTERACTIVE_USER_MODE=true" >> "$besman_user_config_file"
echo "BESMAN_DIR=$HOME/.besman" >> "$besman_user_config_file"
echo "BESMAN_ENV_REPOS=$BESMAN_ENV_REPOS" >> "$besman_user_config_file"
echo "BESMAN_PLAYBOOK_REPO=besecure-ce-playbook-repo" >> "$besman_user_config_file"
echo "BESMAN_GH_TOKEN=" >> "$besman_user_config_file"

echo "Download script archive..."

# once move to besman namespace needs to update besman-latest.zip
#curl -sL --location --progress-bar "${BESMAN_SERVICE}/${BESMAN_NAMESPACE}/BESman/dist/dist/besman-latest.zip" > "$besman_zip_file"
curl -sL --location --progress-bar "${BESMAN_SERVICE}/${BESMAN_NAMESPACE}/BeSman/dist/dist/besman-latest.zip" > "$besman_zip_file"
#cp "/vagrant/ProEnv/besman-latest.zip" "$besman_zip_file"


ARCHIVE_OK=$(unzip -qt "$besman_zip_file" | grep 'No errors detected in compressed data')
if [[ -z "$ARCHIVE_OK" ]]; then
echo "Downloaded zip archive corrupt. Are you connected to the internet?"
echo ""
echo "If problems persist, please ask for help on our Github:"
echo "* easy sign up: https://github.com/"
echo "https://github.com/${BESMAN_NAMESPACE}/BeSman/issues"
rm -rf "$BESMAN_DIR"
exit 2
fi

echo "Extract script archive..."
if [[ "$cygwin" == 'true' ]]; then
echo "Cygwin detected - normalizing paths for unzip..."
besman_zip_file=$(cygpath -w "$besman_zip_file")
besman_stage_folder=$(cygpath -w "$besman_stage_folder")
fi
unzip -qo "$besman_zip_file" -d "$besman_stage_folder"


echo "Install scripts..."


curl -sL "https://raw.githubusercontent.com/${BESMAN_NAMESPACE}/BeSman/master/dist/environments" > tmp.txt
#echo "BESman" > tmp.txt
sed -i 's/,/ /g' tmp.txt
environments=$(<tmp.txt)
for i in $environments;
do
mv "$besman_stage_folder"/besman-$i.sh "$besman_env_folder"
done
rm tmp.txt
mv "${besman_stage_folder}/besman-init.sh" "$besman_bin_folder"
mv "$besman_stage_folder"/besman-* "$besman_src_folder"
mv "$besman_stage_folder"/list.txt "$besman_var_folder"
[[ -d ${besman_stage_folder} ]] && rm -rf ${besman_stage_folder}/*

echo "Set version to $BESMAN_VERSION ..."
echo "$BESMAN_VERSION" > "${BESMAN_DIR}/var/version.txt"
function download_from_env_repo
{
echo "checking for external repos..."
env_repos=$(echo "$BESMAN_ENV_REPOS" | sed 's/,/ /g')
cached_list="$BESMAN_DIR/var/list.txt"
zip_stage_folder="$HOME/zip_stage_folder"
mkdir -p "$zip_stage_folder"
echo "Downloading environment files from $BESMAN_ENV_REPOS"
for i in ${env_repos[@]}; do
namespace=$(echo $i | cut -d "/" -f 1)
repo_name=$(echo $i | cut -d "/" -f 2)
if curl -s "https://api.github.com/repos/$namespace/$repo_name" | grep -q "Not Found"
then
continue
fi
curl -sL "https://github.com/$namespace/$repo_name/archive/master.zip" -o "$HOME/$repo_name.zip"
unzip -q "$HOME/$repo_name.zip" -d "$zip_stage_folder"
remote_list="$zip_stage_folder/$repo_name-master/list.txt"
if [[ ! -f "$remote_list" ]]; then
echo "Error:No list file found for $repo_name"
rm -rf "$zip_stage_folder"
continue
fi
environment_files=$(find $zip_stage_folder/$repo_name-master -type f -name "besman-*.sh")
if [[ -z "${environment_files}" ]]; then
echo "No environment files found for $namespace/$repo_name"
continue
fi
for j in ${environment_files[@]}; do
trimmed_file_name="${j##*/}"
environment=$(echo "$trimmed_file_name" | cut -d "-" -f 2 | sed 's/.sh//g')
if cat "$cached_list" | grep -qw "$namespace/$repo_name/$environment"
then
continue
fi
mv "$j" "$BESMAN_DIR"/envs/
echo "" >> $cached_list
cat "$remote_list" | grep "$namespace/$repo_name/$environment" >> "$cached_list"
done
rm "$HOME/$repo_name.zip"
done
if [[ -d $zip_stage_folder ]]; then
rm -rf $zip_stage_folder
fi
unset environment_files namespace repo_name trimmed_file_name environment zip_stage_folder cached_list remote_list
}
download_from_env_repo
#cp "/vagrant/ProEnv/master/besman-BESman.sh" "$BESMAN_DIR"/envs/
if [[ $darwin == true ]]; then
touch "$besman_bash_profile"
echo "Attempt update of login bash profile on OSX..."
if [[ -z $(grep 'besman-init.sh' "$besman_bash_profile") ]]; then
echo -e "\n$besman_init_snippet" >> "$besman_bash_profile"
echo "Added besman init snippet to $besman_bash_profile"
fi
else
echo "Attempt update of interactive bash profile on regular UNIX..."
touch "${besman_bashrc}"
if [[ -z $(grep 'besman-init.sh' "$besman_bashrc") ]]; then
echo -e "\n$besman_init_snippet" >> "$besman_bashrc"
echo "Added besman init snippet to $besman_bashrc"
fi
fi

echo "Attempt update of zsh profile..."
touch "$besman_zshrc"
if [[ -z $(grep 'besman-init.sh' "$besman_zshrc") ]]; then
echo -e "\n$besman_init_snippet" >> "$besman_zshrc"
echo "Updated existing ${besman_zshrc}"
fi

echo -e "\n\n\nAll done!\n\n"

echo "Please open a new terminal, or run the following in the existing one:"
echo ""
echo " source \"${BESMAN_DIR}/bin/besman-init.sh\""

echo " "
echo "Then issue the following command:"
echo ""
echo " bes help"
echo ""

echo "Enjoy!!!"

0 comments on commit 7e5a565

Please sign in to comment.