After creating the file ./_generic_installer.sh
with the _generic_installer.sh
snippet contents bellow, change/tweak it as you would like.
Then, you can run/use it like the following, i.e., by importing/sourcing it and calling its convenience functions.
You can see all confience functions by calling the help command. Just see the first usage example sample output.
test.sh
#!/bin/bash
thing_name="sshfs";
git_server="https://github.com/libfuse/sshfs";
# https://github.com/evandrocoan/MyLinuxSettings/blob/master/.local/bin/_generic_installer.sh
source _generic_installer.sh;
parse_command_line "${@}";
if [ -z "${branch_or_tag}" ]
then
tags_columns_width=25;
branches_columns_width=40;
list_git_tags;
else
run git clone --recursive --depth 1 --branch "${branch_or_tag}" "${git_server}" "${clone_directory}"
fi;
run ls -a;
run ls -la;
runalways ls;
runset test1 cho 'cool value';
printf "test1 is = '${test1}'\\n";
# ask_to_run ls -la;
from_installation_path="$(getabsolutepath "$clone_directory")";
printf "Current directory '%s'...\\n" "${from_installation_path}";
Example usage:
-
Just calling
./test.sh
user@user$ ./test.sh Usage instructions, you can call this script with the following named arguments: -y to answer all questions as yes -n to answer all questions as no -h to show this help message -s number to skip the first nº instructions -v version to install the selected version from git You can call this script with the following positional arguments: 1. version to install the selected version from git 2. number to skip the first nº instructions If you are going to call the 'list_git_tags' function, these the global variables must be defined before calling the 'parse_command_line' function '${thing_name}', the target directory to save the cloned git repositories '${git_server}', the targer git repository to fetch data from And these global variables are optional for the 'list_git_tags' function '${tags_columns_width}', the minimum length of each git tags column '${branches_columns_width}', the minimum length of each git branches column These are the available global variables after calling 'parse_command_line' '${branch_or_tag}', it has the same value/saves the version command line argument '${clone_directory}', the full path to where clone the git repository Usage examples: ./test.sh ./test.sh v1.8.4 ./test.sh v1.8.4 20 ./test.sh -h ./test.sh -v v1.8.4 ./test.sh -v v1.8.4 -s 10 ./test.sh -y ./test.sh -y -s 20 ./test.sh -y -s 20 -v v1.8.4 API Documentation Function parse_command_line Validate and get all named and positional line arguments from $1 to $n. Example: parse_command_line "${@}"; Function run Run the given command, only when we are not skipping the first nº commands. Example: run ls -la; Function runalways Always run the given command, even when we are skipping the first nº commands. Example: runalways ls -la; Function runset Set a global variable value as the output of the following shell command. This outputs to the console the assigned variable contents. Example: runset myglobalvar ls -la; Function runsets Set a global variable value as the output of the following shell command. This does NOT outputs (silent assignment) to the console the assigned variable contents. Example: runsets myglobalvar ls -la; Function ask_to_run Before running a command, ask whether the command should run or skipped. Example: ask_to_run ls -la; Function list_git_tags Fetch a git repository remote tags and list them. This function does not take any parameters. Example: list_git_tags; Loading 'sshfs' versions from 'https://github.com/libfuse/sshfs'... This should take about 10 seconds... Setting the variable 'git_raw_string' with the command 'git ls-remote https://github.com/libfuse/sshfs '... (/cygdrive/d/User/Downloads) Done loading... These are the available git remote 'sshfs' versions: sshfs-2.10 sshfs-2.7 sshfs-2.9 sshfs-3.0.0 sshfs-3.1.0 sshfs-3.2.0 sshfs-3.3.0 sshfs-3.3.1 sshfs-3.3.2 sshfs-3.4.0 sshfs-3.5.0 sshfs-3.5.1 sshfs-3.5.2 sshfs_0_1 sshfs_1_0 sshfs_1_1 sshfs_1_2 sshfs_1_3 sshfs_1_4 sshfs_1_5 sshfs_1_6 sshfs_1_7 sshfs_1_8 sshfs_1_9 sshfs_2.8 sshfs_2_0 sshfs_2_1 sshfs_2_2 sshfs_2_3 sshfs_2_4 sshfs_2_5 sshfs_2_6 start These are the available git remote 'sshfs' branches: master parallel_conns sshfs_2.x Now, choose which 'sshfs' version you would like to install by running: ./test.sh version
-
Calling
./test.sh sshfs_2.8
user@user$ ./test.sh sshfs_2.8 Setting the 1 positional command line argument 'branch_or_tag=sshfs_2.8'... Running '1º' required command 'git clone --recursive --depth 1 --branch sshfs_2.8 https://github.com/libfuse/sshfs ./sshfs/sshfs_2.8 ' (/home/user/Downloads) fatal: destination path './sshfs/sshfs_2.8' already exists and is not an empty directory. The last '1º' command 'git clone --recursive --depth 1 --branch sshfs_2.8 https://github.com/libfuse/sshfs ./sshfs/sshfs_2.8 ' returned with the error code '128'... Type 'q' and press 'Enter' to continue the main script execution... Type 'r' and press 'Enter' to repeat the last '1º' command... Type 'e' to edit in memory the '1º' command... If you would like, press 'Ctrl+C' to abort this and the main script... Beyond these options, you can also run any command you would like as 'cd dir', 'ls -la', etc... Command: r Repeating the last '1º' command 'git clone --recursive --depth 1 --branch sshfs_2.8 https://github.com/libfuse/sshfs ./sshfs/sshfs_2.8 '... (/home/user/Downloads) fatal: destination path './sshfs/sshfs_2.8' already exists and is not an empty directory. The last '1º' command 'git clone --recursive --depth 1 --branch sshfs_2.8 https://github.com/libfuse/sshfs ./sshfs/sshfs_2.8 ' returned with the error code '128'... Type 'q' and press 'Enter' to continue the main script execution... Type 'r' and press 'Enter' to repeat the last '1º' command... Type 'e' to edit in memory the '1º' command... If you would like, press 'Ctrl+C' to abort this and the main script... Beyond these options, you can also run any command you would like as 'cd dir', 'ls -la', etc... Command: e Changing the last '1' command 'git clone --recursive --depth 1 --branch sshfs_2.8 https://github.com/libfuse/sshfs ./sshfs/sshfs_2.8 ' to... (/home/user/Downloads) Edit command: git clone --recursive --depth 1 --branch sshfs_1_1 https://github.com/libfuse/sshfs ./sshfs/sshfs_1_1 Cloning into './sshfs/sshfs_1_1'... remote: Enumerating objects: 14, done. remote: Counting objects: 100% (14/14), done. remote: Compressing objects: 100% (13/13), done. remote: Total 14 (delta 0), reused 2 (delta 0), pack-reused 0 Unpacking objects: 100% (14/14), done. Note: checking out 'b3aac4e035e572e4fc01ad32e2fe936e40ab5b09'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b <new-branch-name> Running '2º' required command 'ls -a ' (/home/user/Downloads) . A_short_survey_on_quantum_computers.pdf fastfilepackage SaveLater test.sh TODO.txt ToViewNext .. desktop.ini installation_model.sh sshfs Thumbs.db Torrents Running '3º' required command 'ls -la ' (/home/user/Downloads) total 1481 drwx---r-x+ 1 user Unknown+Group 0 Jun 29 17:09 . drwxrwxr-x+ 1 user Unknown+Group 0 Jun 19 21:58 .. -rwx---r-x+ 1 user None 729178 Jun 28 23:16 A_short_survey_on_quantum_computers.pdf -rwx---r-x+ 1 user Unknown+Group 374 Aug 15 2018 desktop.ini drwx---r-x+ 1 user None 0 Jun 29 16:11 fastfilepackage -rwx---r-x+ 1 user None 20234 Jun 29 23:12 installation_model.sh drwx---r-x+ 1 user None 0 Jun 21 23:44 SaveLater drwx---r-x+ 1 user None 0 Jun 29 23:19 sshfs -rwx---r-x+ 1 user None 537 Jun 29 23:18 test.sh -rwx---r-x+ 1 user Unknown+Group 643072 Jun 1 2017 Thumbs.db -rwx---r-x+ 1 user None 4655 May 15 21:25 TODO.txt drwx---r-x+ 1 user None 0 Jun 29 02:24 Torrents drwx---r-x+ 1 user None 0 Jun 22 16:24 ToViewNext Running the '4º' always command 'ls ' (/home/user/Downloads) A_short_survey_on_quantum_computers.pdf fastfilepackage SaveLater test.sh TODO.txt ToViewNext desktop.ini installation_model.sh sshfs Thumbs.db Torrents Setting the variable 'test1' with the command 'cho cool value '... (/home/user/Downloads) ./installation_model.sh: line 348: cho: command not found The last set command 'test1=cho cool value ' on step '4º' returned with the error code '127'... Type 'q' and press 'Enter' to continue the main script execution... Type 'r' to run again the last set command... Type 's' to manually set the 'test1' variable value. Type 'e' to edit in memory the 'test1' variable set command... If you would like, press 'Ctrl+C' to abort this and the main script... Beyond these options, you can also run any command you would like as 'cd dir', 'ls -la', etc... Command: r Repeating the last set command 'cho cool value ' on step '4º'... (/home/user/Downloads) Setting the variable 'test1' with the command 'cho cool value'... (/home/user/Downloads) ./installation_model.sh: line 386: cho: command not found The last set command 'test1=cho cool value' on step '4º' returned with the error code '127'... Type 'q' and press 'Enter' to continue the main script execution... Type 'r' to run again the last set command... Type 's' to manually set the 'test1' variable value. Type 'e' to edit in memory the 'test1' variable set command... If you would like, press 'Ctrl+C' to abort this and the main script... Beyond these options, you can also run any command you would like as 'cd dir', 'ls -la', etc... Command: e Changing the last set command 'cho cool value' on step '4º' to... (/home/user/Downloads) test1=echo cool value now!!!! Setting the variable 'test1' with the command 'echo cool value now!!!!'... (/home/user/Downloads) The new variable value set on step '4º' is 'test1=cool value now!!!!'... test1 is = 'cool value now'!!!! Current directory '/home/user/Downloads/sshfs/sshfs_2.8'...