-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-scripts
More file actions
executable file
·69 lines (57 loc) · 2.12 KB
/
install-scripts
File metadata and controls
executable file
·69 lines (57 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env bash
# Installs scripts from GitHub repository
# Environment setup
set -o pipefail
function print_usage() {
cat <<EOF
Usage: $(basename "$0") [-h]
Installs scripts from GitHub repository to ${HOME}/bin/scripts and updates PATH.
Dependencies:
git Required to clone the repository
Optional arguments:
-h, --help Show this help message and exit
EOF
}
if [[ $# -gt 0 || "${1}" == "-h" || "${1}" == "--help" ]]; then
print_usage
exit 1
fi
echo
echo "Installing grantcarthew/scripts"
echo "License: Mozilla Public License Version 2.0"
echo "Checking Dependencies"
if ! command -v git >/dev/null; then
echo "ERROR: Missing dependency - 'git'" >&2
exit 1
fi
echo "Checking Target Directory"
readonly target_dir="${HOME}/bin/scripts"
if [[ -d "${target_dir}" ]]; then
echo "Directory '${target_dir}' already exists, skipping creation"
else
mkdir -p "${target_dir}" || { echo "ERROR: Failed to create '${target_dir}'" >&2; exit 1; }
fi
echo "Cloning Repository"
if [[ -d "${target_dir}/.git" ]]; then
echo "Repository already cloned in '${target_dir}', skipping clone"
echo "Pulling updates"
cd "${target_dir}" || { echo "ERROR: Failed to change directory to '${target_dir}'" >&2; exit 1; }
git pull || { echo "ERROR: Failed to update repository" >&2; exit 1; }
cd - || { echo "ERROR: Failed to change directory back to original location" >&2; exit 1; }
else
git clone git@github.com:grantcarthew/scripts.git "${target_dir}" || { echo "ERROR: Failed to clone repository" >&2; exit 1; }
echo "Cloned repository to '${target_dir}'"
fi
echo "Updating PATH in .bashrc"
bashrc_file="${HOME}/.bashrc"
#shellcheck disable=SC2016
path_entry='export PATH="${PATH}:${HOME}/bin/scripts"'
if grep -Fx "${path_entry}" "${bashrc_file}" >/dev/null; then
echo "PATH entry already exists in '${bashrc_file}'"
else
echo "${path_entry}" >> "${bashrc_file}" || { echo "ERROR: Failed to update '${bashrc_file}'" >&2; exit 1; }
echo "Added PATH entry to '${bashrc_file}'"
fi
echo "Installation complete."
echo "Either run 'source ${bashrc_file}' to update your current session"
echo "or restart your terminal."