-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathinstall
executable file
·93 lines (88 loc) · 3.04 KB
/
install
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
#
# Usage: install
# 1. Creates .standard_aliases directory in home directory.
# 2. Makes a symbolic link from there to standard_functions file
# located in projects root.
# 3. Copies standard_rc from projects root to home directory as
# .standardrc
# 4. Adds command to the end of .bashrc, that will update
# project every time bash starts (by running make in projects
# root) and import standard_functions and automatically
# generated file ~/.standard_aliases/aliases
# Stops execution if any command fails.
set -eo pipefail
createLinkSafely() {
link="$1"
targetDirectory=$(dirname "$link")
file="$2"
# Creates directory if it doesn't exist.
if [ ! -d "$targetDirectory" ]; then
echo "install: Creating directory $targetDirectory."
mkdir -p "$targetDirectory"
fi
# Creates link if file doesn't exist.
if [[ ! -f "$link" ]]; then
echo "install: Creating link $link"
ln -s $(pwd)/"$file" "$link"
else
echo "install: Did not create link $link, because file with same name already exists."
fi
}
copyFileSafely() {
destination="$1"
origin="$2"
# Copies file if file doesn't exist.
if [[ ! -f "$destination" ]]; then
echo "install: Copying file $origin to $destination"
cp "$origin" "$destination"
else
echo "install: Did not copy file $link, because file with same name already exists."
fi
}
main() {
# Checks if make is installed.
make --help &> /dev/null
makeInstalled=1
if [[ "$?" != 0 ]]; then
makeInstalled=0
fi
# 1. Creates .standard_aliases directory in home directory.
# 2. Makes a symbolic link from there to standard_functions file
# located in projects root.
createLinkSafely ~/.standard_aliases/functions standard_functions
# 3. Copies standard_rc from projects root to home directory as
# .standardrc (also comments out functions whose names have
# already been taken by an alias (specified in .bashrc,
# .profile or .bash_aliases).
(cd scripts
temp=$(mktemp /tmp/XXXXXXXX)
./remove-conflicts-from-rc.py > "$temp"
copyFileSafely ~/.standardrc "$temp"
)
# Creates ~/.bashrc if it doesn't exist.
if [[ ! -f ~/.bashrc ]]; then
touch ~/.bashrc
fi
# 4. Adds command to the end of .bashrc, that will update
# project every time bash starts (by running make in projects
# root) and import standard_functions and automatically
# generated file ~/.standard_aliases/aliases
if [[ -z $(grep ". ~/.standard_aliases" ~/.bashrc) ]]; then
cat ./scripts/resources/append-to-bashrc >> ~/.bashrc
fi
# Prints information on how to install Make if it is not
# installed, otherwise runs `bash`, so that changes take
# effect.
if [[ ! "$makeInstalled" ]]; then
echo "Make command is missing, you need to install it first with:"
echo " sudo apt-get install make"
echo "if you're running Debian/Ubuntu/Mint... or"
echo " sudo yum install make"
echo "if you're running RedHat/Fedora/CentOS..."
echo "After installing Make, run 'bash' for changes to take effect."
else
bash
fi
}
main "$@"