-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.sh
executable file
·161 lines (140 loc) · 5.22 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
#
# Copyright 2024 gitricko
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
set -e
track_last_command() {
last_command=$current_command
current_command=$BASH_COMMAND
}
trap track_last_command DEBUG
echo_failed_command() {
local exit_code="$?"
if [[ "$exit_code" != "0" ]]; then
echo "'$last_command': command failed with exit code $exit_code."
fi
}
trap echo_failed_command EXIT
# Global variables
export SONARLESS_SOURCES="https://raw.githubusercontent.com/gitricko/sonarless/main/makefile.sh" # URL where makefile.sh is hosted
if [ -z "$SONARLESS_DIR" ]; then
SONARLESS_DIR="$HOME/.sonarless"
fi
export SONARLESS_DIR
# Local variables
sonarless_bashrc="${HOME}/.bashrc"
sonarless_zshrc="${HOME}/.zshrc"
echo ''
echo ' _ '
echo ' ___ ___ _ __ __ _ _ __ | | ___ ___ ___ '
echo ' / __| / _ \ | "_ \ / _` || "__|| | / _ \/ __|/ __| '
echo ' \__ \| (_) || | | || (_| || | | || __/\__ \\__ \ '
echo ' |___/ \___/ |_| |_| \__,_||_| |_| \___||___/|___/ '
echo ''
echo ''
echo ' Now attempting installation...'
echo ''
# Sanity checks
echo "Looking for a previous installation of SONARLESS..."
if [ -d "$SONARLESS_DIR" ]; then
echo "SONARLESS found."
echo ""
echo "======================================================================================================"
echo " You already have SONARLESS installed."
echo " SONARLESS was found at:"
echo ""
echo " ${SONARLESS_DIR}"
echo ""
echo " Please consider uninstalling and reinstall."
echo ""
echo " $ sonarless uninstall "
echo ""
echo " or "
echo ""
echo " $ rm -rf ${SONARLESS_DIR}"
echo ""
echo "======================================================================================================"
echo ""
exit 0
fi
echo "Looking for docker..."
if ! command -v docker > /dev/null; then
echo "Not found."
echo "======================================================================================================"
echo " Please install docker on your system using your favourite package manager."
echo ""
echo " Restart after installing docker."
echo "======================================================================================================"
echo ""
exit 1
fi
echo "Looking for jq..."
if ! command -v jq > /dev/null; then
echo "Not found."
echo "======================================================================================================"
echo " Please install jq on your system using your favourite package manager."
echo ""
echo " Restart after installing jq."
echo "======================================================================================================"
echo ""
exit 1
fi
echo "Looking for sed..."
if ! command -v sed > /dev/null; then
echo "Not found."
echo "======================================================================================================"
echo " Please install sed on your system using your favourite package manager."
echo ""
echo " Restart after installing sed."
echo "======================================================================================================"
echo ""
exit 1
fi
echo "Installing Sonarless helper scripts..."
# Create directory structure
mkdir -p "${SONARLESS_DIR}"
set +e
# Download makefile.sh depending which env (git or over curl)
# Check if you are in sonarless git
LOCAL_FILE_EXIST=$([[ -d ./.git ]] && git remote get-url origin | grep -q sonarless && [[ -s ./makefile.sh ]]; echo "$?")
if [[ "${LOCAL_FILE_EXIST}" -eq "0" ]]; then
echo "* Copying from local git..."
cp -f ./makefile.sh "${SONARLESS_DIR}"
else
echo "* Downloading..."
curl --fail --location --progress-bar "${SONARLESS_SOURCES}" > "${SONARLESS_DIR}/makefile.sh"
chmod +x "${SONARLESS_DIR}/makefile.sh"
fi
# Create alias in ~/.bashrc ~/.zshrc if available
if [[ ! -s "${sonarless_bashrc}" ]] || ! grep -q 'sonarless' "${sonarless_bashrc}" ;then
echo "alias sonarless='$HOME/.sonarless/makefile.sh'" >> "${sonarless_bashrc}"
fi
if [[ ! -s "${sonarless_zshrc}" ]] || ! grep -q 'sonarless' "${sonarless_zshrc}"; then
echo "alias sonarless='$HOME/.sonarless/makefile.sh'" >> "${sonarless_zshrc}"
fi
# Dynamically create the alias during installation so that use can use it
if ! command -v sonarless > /dev/null; then
alias sonarless='$HOME/.sonarless/makefile.sh'
fi
echo ""
echo "Please open a new terminal, or run the following in the existing one:"
echo ""
echo " alias sonarless='$HOME/.sonarless/makefile.sh' "
echo ""
echo "Then issue the following command:"
echo ""
echo " sonarless help"
echo ""
echo "Enjoy!!!"