Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matheus Rocha Vieira committed May 9, 2019
1 parent 0dbad04 commit 03ae492
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 45 deletions.
8 changes: 4 additions & 4 deletions bootstrap/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{
"program": "ssh",
"name": "Secure Shell (SSH)",
"installation": "true",
"installation": "false",
"default": "true"
},
{
Expand Down Expand Up @@ -179,13 +179,13 @@
{
"program": "python3",
"name": "Python3",
"installation": "true",
"installation": "false",
"default": "true"
},
{
"program": "python-pip",
"name": "Python PIP",
"installation": "true",
"installation": "false",
"default": "true",
"dependencies": "python3"
},
Expand Down Expand Up @@ -257,7 +257,7 @@
{
"program": "mosh",
"name": "Mosh",
"installation": "true",
"installation": "false",
"default": "true"
},
{
Expand Down
2 changes: 1 addition & 1 deletion configurations/alias.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
PREVIOUS_PWD="$(jq -r '.pwd' "${HOME}"/tmp/pwd.json)"
PREVIOUS_PWD="$1"
if [ "$(jq -r '.configurations.debug' "${PREVIOUS_PWD}"/bootstrap/settings.json)" == true ]; then
set +e
else
Expand Down
2 changes: 1 addition & 1 deletion configurations/git/alias-git.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
PREVIOUS_PWD="$(jq -r '.pwd' "${HOME}"/tmp/pwd.json)"
PREVIOUS_PWD="$1"
if [ "$(jq -r '.configurations.debug' "${PREVIOUS_PWD}"/bootstrap/settings.json)" == true ]; then
set +e
else
Expand Down
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ EOF
sudo rm -f -R "${HOME}"/tmp
fi
mkdir -p "${HOME}"/tmp
cd "${HOME}"/tmp && printf "\n [ SUCESS ] cd ${HOME}/tmp\n" || return && printf "\n [ ERROR ] cd ${HOME}/tmp\n"
cd "${HOME}"/tmp || return
: '
printf "\n [ START ] Version Management Control\n"
starttime=$(date +%s)
Expand Down
91 changes: 53 additions & 38 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@
PREVIOUS_PWD="$1"
printf "\n [ START ] Configuring System Run\n"
starttime=$(date +%s)
JSON_STRING=$(jq -n --arg pwd "${PREVIOUS_PWD}" '{pwd: $pwd}')
echo "${JSON_STRING}" >>"${HOME}"/tmp/pwd.json
sudo apt -qq update
endtime=$(date +%s)
printf " [ DONE ] Configuring System Run ... %s seconds\n" "$((endtime - starttime))"
printf "\n [ START ] Instaling Major Requirements\n"
starttime=$(date +%s)
trap '' 2
if ! git clone https://github.com/molovo/lumberjack; then
echo "Download failed downloading molovo/lumberjack! Exiting."
kill $$
fi
echo "Download failed downloading molovo/lumberjack! Exiting."
kill $$
fi
if [ -d /usr/local/bin/lj ]; then
sudo rm -f -R /usr/local/bin/lj
sudo mv lumberjack/lj /usr/local/bin
sudo mv lumberjack/lj /usr/local/bin
fi
sudo apt -y install jq moreutils
if [ ! -n "$(command -v jq)" ] || [ ! -n "$(command -v sponge)" ]; then
Expand Down Expand Up @@ -73,7 +71,7 @@
lj " [ DONE ] Instaling Common Requirements ... %s seconds\n" "$((endtime - starttime))"
printf "\n [ START ] Configurating Command Alias\n"
starttime=$(date +%s)
"${PREVIOUS_PWD}"/configurations/alias.sh
"${PREVIOUS_PWD}"/configurations/alias.sh "${PREVIOUS_PWD}"
wait
endtime=$(date +%s)
printf " [ DONE ] Configurating Command Alias ... %s seconds\n" "$((endtime - starttime))"
Expand Down Expand Up @@ -183,30 +181,42 @@
_jq() {
echo "${row}" | base64 --decode | jq -r "${1}"
}
programdefault=$(_jq '.default')
if [ "$programdefault" == true ]; then
defaultoption="(Y/n)"
else
defaultoption="(y/N)"
fi
printf "\n Install %s %s: " "$(_jq '.name')" "$defaultoption"
read -r programname
if [ "$programname" == Y ] || [ "$programname" == y ]; then
programinstallation=true
elif [ -z "$programname" ]; then
programinstallation="${programdefault}"
echo "${programdefault}"
programslug="$(_jq '.program')"
programdependencies="$(jq -r '.programs[] | select(.program=="'"${programslug}"'").dependencies' "${PREVIOUS_PWD}"/bootstrap/settings.json)"
dependencieinstallation="$(jq -r '.programs[] | select(.program=="'"${programdependencies}"'").installation' "${PREVIOUS_PWD}"/bootstrap/settings.json)"
if [ "${programdependencies}" == "null" ] || [ "${dependencieinstallation}" == true ]; then
programdefault=$(_jq '.default')
if [ "$programdefault" == true ]; then
defaultoption="(Y/n)"
else
defaultoption="(y/N)"
fi
printf "\n Install %s %s: " "$(_jq '.name')" "$defaultoption"
read -r programname
if [ "$programname" == Y ] || [ "$programname" == y ]; then
programinstallation=true
elif [ -z "$programname" ]; then
programinstallation="${programdefault}"
echo "${programdefault}"
else
programinstallation=false
fi
jq '.programs['"${i}"'].installation = "'"${programinstallation}"'"' "${PREVIOUS_PWD}"/bootstrap/settings.json | sponge "${PREVIOUS_PWD}"/bootstrap/settings.json
else
programinstallation=false
programname="$(_jq '.name')"
printf "\n You can't install %s without %s\n" "$programname" "$programdependencies"
fi
jq '.programs['"${i}"'].installation = "'"${programinstallation}"'"' "${PREVIOUS_PWD}"/bootstrap/settings.json | sponge "${PREVIOUS_PWD}"/bootstrap/settings.json
((i++))
unset programname
done
unset programinstallation
unset programdefault
unset programname
unset defaultoption
unset i
variables=(
programname
programdefault
programinstallation
defaultoption
i
)
unset "${variables[@]}"
else
kill $$
fi
Expand All @@ -230,11 +240,6 @@
if [ "${installflag}" == true ]; then
printf "\n [ START ] %s\n" "$($programname)"
starttime=$(date +%s)
#if [ ! -f "${PREVIOUS_PWD}"/programs/"${programslug}".sh ]; then
# if ! curl programs/"${programslug}".sh -L https://raw.githubusercontent.com/MatheusRV/dotfiles/master/programs/"${programslug}".sh --create-dirs -o "${PREVIOUS_PWD}"//,sh ; then
# echo "${programslug} download failed! Exiting."
# fi
#i
"${PREVIOUS_PWD}"/programs/"${programslug}".sh "${PREVIOUS_PWD}" || installationerror=true
wait
if [ "${installationerror}" == true ]; then
Expand All @@ -260,11 +265,13 @@
fi
fi
done
unset installflag
unset installationerror
unset programname
unset programdependencies
unset dependencieinstallation
variables=(
installflag
installationerror
programname
dependencieinstallation
)
unset "${variables[@]}"
printf "\n [ START ] Common Requirements\n"
starttime=$(date +%s)
apps=(
Expand All @@ -273,7 +280,6 @@
shellcheck
)
sudo apt -y install "${apps[@]}"
unset apps
endtime=$(date +%s)
printf " [ DONE ] Common Requirements ... %s seconds\n" "$((endtime - starttime))"
printf "\n [ START ] Cleaning\n"
Expand All @@ -285,4 +291,13 @@
printf " [ DONE ] Cleaning ... %s seconds\n" "$((endtime - starttime))"
endtotaltime=$(date +%s)
printf "\n Total Execution Time ... %s seconds\n" "$((endtotaltime - starttotaltime))"
variables=(
PREVIOUS_PWD
starttotaltime
endtotaltime
starttime
endtime
apps
)
unset "${variables[@]}"
}

0 comments on commit 03ae492

Please sign in to comment.