-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·119 lines (90 loc) · 2.52 KB
/
install.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
interface=$1
scope=$2
print_usage() {
echo "usage: $0 gui|terminal local|system"
exit 1
}
# Parse arguments
case $interface in
gui)
echo "installing interface version"
;;
terminal)
echo "installing terminal version"
;;
*)
print_usage
;;
esac
local_installation=false
root=false
case $scope in
local)
echo "installing locally"
local_installation=true
;;
system)
root=true
echo "installing system wide"
;;
*)
print_usage
;;
esac
# edit files as root?
user="normal"
if $root; then
user="root"
echo "editing files as root"
else
echo "editing files as $USER"
fi
# install deps
./scripts/install/install-python.sh
./scripts/install/setup-venv.sh
# which bashrc file to edit?
bashrc="/etc/bash.bashrc"
bashrc_template="./templates/system-bashrc-template"
if $local_installation; then
bashrc="$HOME/.bashrc"
bashrc_template="./templates/local-bashrc-template"
fi
echo "Editing file: $bashrc"
echo "Using bashrc template file: $bashrc_template"
# where to store cd_history file
hist_file="/opt/.cd_history"
if $local_installation; then
hist_file="$HOME/.cd_history"
fi
echo "cd hist file location: $hist_file"
# create hist file if not there yet
if $local_installation; then
[ ! -f "$hist_file" ] && touch "$hist_file"
else
[ ! -f "$hist_file" ] && sudo touch "$hist_file"
sudo chmod a+rw "$hist_file"
fi
# backup
./scripts/install/backup.sh "$scope" "$bashrc"
# add paragraph
start_pattern="# CD HISTORY START"
end_pattern="# CD HISTORY END"
start_found=$(cat "$bashrc" | grep --count "$start_pattern")
end_found=$(cat "$bashrc" | grep --count "$end_pattern")
template_file=$(mktemp)
cat "$bashrc_template" > "$template_file"
bash ./scripts/install/replace_or_add_line.sh "$template_file" "export CD_HIST_FILE=" "export CD_HIST_FILE=$hist_file" "$user"
bash ./scripts/install/replace_or_add_line.sh "$template_file" "export CD_HIST_MODE=" "export CD_HIST_MODE=$interface" "$user"
echo "paragraph to add:"
cat "$template_file"
echo "adding bashrc paragraph"
bash ./scripts/install/replace_or_add_paragraph.sh "$bashrc" "$start_pattern" "$end_pattern" "$template_file" "$user"
echo "done updating bashrc"
# create symlinks if needed
./scripts/install/create-symlink.sh "./cd-history" $scope
./scripts/install/create-symlink.sh "./bin/cd-hist-get" $scope
# done
echo "installed"
echo "current installations: $installations"
echo "restart terminal for changes to take effect"