-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·78 lines (65 loc) · 1.27 KB
/
setup.sh
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
70
71
72
73
74
75
76
77
78
#!/usr/bin/env bash
#
# Copyright (C) 2019 Saalim Quadri (danascape)
#
# SPDX-License-Identifier: Apache-2.0 license
#
declare -r app_name='sw'
##
## Following are the install paths
##
# Paths used during the installation process]
declare -r binpath="$HOME/.local/bin"
declare -r srcpath="$HOME/.local/$app_name"
declare -r swbinpath="$HOME/.local/bin/$app_name"
# Source code references
declare -r SRCDIR='src'
safe_append()
{
if [[ $(grep -c -x "$1" "$2") == 0 ]]; then
printf '%s\n' "$1" >> "$2"
fi
}
synchronize_files()
{
echo "sworkflow: Installing files"
mkdir -p "$srcpath"
cp $app_name "$swbinpath"
rsync -vr $SRCDIR "$srcpath"
if [[ -z "$(which bash)" ]]; then
echo "error: No bash"
else
if [[ -f "$HOME/.bashrc" ]]; then
update_path '.bashrc'
else
echo "warning: Unable to find a .bashrc file"
fi
fi
}
update_path()
{
local shellrc=${1:-'.bashrc'}
IFS=':' read -ra ALL_PATHS <<< "$PATH"
for path in "${ALL_PATHS[@]}"; do
[[ "$path" -ef "$binpath" ]] && return
done
safe_append "PATH=${HOME}/.local/bin:\$PATH # sw" "${HOME}/${shellrc}"
}
setup()
{
argument="$1"
case "$argument" in
install | -i)
(
echo "Installing sworkflow"
synchronize_files
)
;;
*)
(
echo "error: Invalid Option"
)
;;
esac
}
setup "$@"