A more organised and robust install file

This commit is contained in:
Tiago Almeida 2019-10-27 22:42:16 +00:00
parent 29702014e0
commit 8442d3ad35

View File

@ -15,12 +15,39 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
# Bash Variables
# Ativate or not the erros (1=activated)
OPTERR=1
# Separator (useful for simulate arrays)
IFS=" "
# check for unzip before we continue # Global Variables
if [ ! "$(command -v unzip)" ]; then G_NANORC_FILE="~/.nanorc"
echo 'unzip is required but was not found. Install unzip first and then run this script again.' >&2 G_DEPS="unzip sed wget"
exit 1
fi # Functions
# Check dependencies
f_check_deps(){
DEPS_MISSED=""
# If there isn't the dependency the $DEPS_MISSED will be populated.
for DEP in $G_DEPS; do
if [ ! "$(command -v "$DEP")" ]; then
DEPS_MISSED="${DEP} ${DEPS_MISSED}"
fi
done
# Error if $DEPS_MISSED is populated.
if [ "$DEPS_MISSED" = "" ]; then
return 0
else
for DEP in $DEPS_MISSED; do
echo "The '${DEP}' program is required but was not found. Install '${DEP}' first and then run this script again." >&2
done
return 1
fi
}
_fetch_sources(){ _fetch_sources(){
wget -O /tmp/nanorc.zip https://github.com/scopatz/nanorc/archive/master.zip wget -O /tmp/nanorc.zip https://github.com/scopatz/nanorc/archive/master.zip
@ -48,15 +75,12 @@ _update_nanorc_lite(){
sed -i '/include "\/usr\/share\/nano\/\*\.nanorc"/i include "~\/.nano\/*.nanorc"' "${NANORC_FILE}" sed -i '/include "\/usr\/share\/nano\/\*\.nanorc"/i include "~\/.nano\/*.nanorc"' "${NANORC_FILE}"
} }
# Good start / docs
# start constants
# list and check the needed programs
# check parameters # check parameters
# init main # init main
# get the git # get the git
# updat/create the nanorc # updat/create the nanorc
f_check_deps
NANORC_FILE=~/.nanorc
case "$1" in case "$1" in
-l|--lite) -l|--lite)