Skip to content

Commit 8ed953b

Browse files
authored
fix(shellcheck): SC2312 (#466)
* fix(monitor-installer): SC2312 * fix(openemr-env-migrator): SC2312 * fix(openemr-env-installer): SC2312
1 parent c5173c3 commit 8ed953b

File tree

3 files changed

+47
-52
lines changed

3 files changed

+47
-52
lines changed

utilities/openemr-env-installer/openemr-env-installer

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ script_run_as_root(){
2323
# Install git
2424
install_git() {
2525
# Check the os distribution ubuntu/debian/rhel/fedora/centos
26-
os_distribution=$(grep ^HOME_URL /etc/os-release| awk -F'[/.]' '{print $(NF-2)}')
26+
os_distribution=$(awk -F'[/.]' '/^HOME_URL/ {print $(NF-2)}' /etc/os-release)
2727
if command -v git &>/dev/null; then
2828
echo -e "\033[30m===>\033[0m \033[32mGit is already installed. \033[0m"
2929
echo
@@ -70,33 +70,33 @@ installer_script_usage() {
7070
git_clone_function(){
7171
code_location=$1
7272
github_account=$2
73-
cd ${code_location} && [[ $(pwd) != "${code_location}" ]] && cd ${code_location}
74-
echo -e "\033[30m===>\033[0m \033[32mDownloading OpenEMR repository... \033[0m"
75-
echo
76-
# For openemr repos
77-
git clone https://github.com/${github_account}/openemr.git
78-
cd ${code_location}/openemr && [[ $(pwd) != "${code_location}/openemr" ]] && cd ${code_location}/openemr
79-
git remote add upstream https://github.com/openemr/openemr.git
80-
git fetch upstream
81-
echo
82-
echo -e "\033[30m===>\033[0m \033[32mPulling the latest data... \033[0m"
83-
echo
84-
git pull upstream master
85-
echo
73+
(
74+
set -euo pipefail
75+
cd -P "${code_location}"
76+
echo -e "\033[30m===>\033[0m \033[32mDownloading OpenEMR repository... \033[0m"
77+
echo
78+
# For openemr repos
79+
git clone https://github.com/${github_account}/openemr.git
80+
git -C openemr remote add upstream https://github.com/openemr/openemr.git
81+
git -C openemr fetch upstream
82+
echo
83+
echo -e "\033[30m===>\033[0m \033[32mPulling the latest data... \033[0m"
84+
echo
85+
git -C openemr pull upstream master
86+
echo
8687

87-
# For openemr-devops repos
88-
cd ${code_location} && [[ $(pwd) != "${code_location}" ]] && cd ${code_location}
89-
echo -e "\033[30m===>\033[0m \033[32mDownloading OpenEMR-devops repository... \033[0m"
90-
echo
91-
git clone https://github.com/${github_account}/openemr-devops.git
92-
cd ${code_location}/openemr-devops && [[ $(pwd) != "${code_location}/openemr-devops" ]] && cd ${code_location}/openemr-devops
93-
git remote add upstream https://github.com/openemr/openemr-devops.git
94-
git fetch upstream
95-
echo
96-
echo -e "\033[30m===>\033[0m \033[32mPulling the latest data... \033[0m"
97-
echo
98-
git pull upstream master
99-
echo
88+
# For openemr-devops repos
89+
echo -e "\033[30m===>\033[0m \033[32mDownloading OpenEMR-devops repository... \033[0m"
90+
echo
91+
git clone https://github.com/${github_account}/openemr-devops.git
92+
git -C openemr-devops remote add upstream https://github.com/openemr/openemr-devops.git
93+
git -C openemr-devops fetch upstream
94+
echo
95+
echo -e "\033[30m===>\033[0m \033[32mPulling the latest data... \033[0m"
96+
echo
97+
git -C openemr-devops pull upstream master
98+
echo
99+
)
100100
}
101101

102102
# Check the code clone or not
@@ -143,7 +143,7 @@ rhel_register_check_and_enable_repo() {
143143
register_note
144144
fi
145145
elif [[ -f ${register_lock} ]]; then
146-
if [[ "$(cat /tmp/openemr-register-lock)" = "1" ]]; then
146+
if [[ "$(</tmp/openemr-register-lock)" = "1" ]]; then
147147
register_note
148148
fi
149149
fi
@@ -157,7 +157,8 @@ rhel_register_check_and_enable_repo() {
157157
subscription-manager repos --enable rhel-7-server-extras-rpms &>/dev/null
158158
[[ $? -eq 0 ]] && echo 2 >> ${repo_lock}
159159
elif [[ -f ${repo_lock} ]]; then
160-
if [[ "$(cat /tmp/openemr-repo-lock|wc -l)" = "2" ]]; then
160+
line_count=$(wc -l </tmp/openemr-repo-lock)
161+
if [[ "${line_count}" = "2" ]]; then
161162
echo -e "\033[30m===>\033[0m \033[32mBoth of base and extras repo are already enabled. \033[0m"
162163
echo
163164
fi
@@ -187,7 +188,8 @@ install_docker() {
187188
sudo curl -fsSL https://download.docker.com/linux/${os_distribution}/gpg | sudo apt-key add -
188189
echo
189190
echo -e "\033[30m===>\033[0m \033[32mSetting up the stable repository... \033[0m"
190-
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/${os_distribution} $(lsb_release -cs) stable"
191+
codename=$(lsb_release -cs)
192+
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/${os_distribution} ${codename} stable"
191193
echo
192194
echo -e "\033[30m===>\033[0m \033[32mInstalling docker engine... \033[0m"
193195
echo
@@ -246,7 +248,9 @@ install_docker_compose() {
246248
echo -e "\033[30m===>\033[0m \033[32mInstalling docker-compose... \033[0m"
247249
echo
248250
# Run sudo under root mode that is also fine e.g. rhel/fedora/centos
249-
sudo curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
251+
os_name=$(uname -s)
252+
arch=$(uname -m)
253+
sudo curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-${os_name}-${arch}" -o /usr/local/bin/docker-compose
250254
sudo chmod +x /usr/local/bin/docker-compose
251255
echo
252256
}
@@ -482,7 +486,10 @@ elif [[ "${os_type}" = "Darwin" ]]; then
482486
echo
483487
else
484488
echo -e "\033[30m===>\033[0m \033[32mInstalling Homebrew... \033[0m"
485-
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
489+
brew_installer=$(mktemp -d)
490+
curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh > "${brew_installer}"/install.sh
491+
chmod +x "${brew_installer}"/install.sh
492+
"${brew_installer}/install.sh"
486493
echo
487494
fi
488495

utilities/openemr-env-migrator/openemr-env-migrator

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ target_dir_remote_check() {
2525
# Stop the container at first
2626
stop_all_containers() {
2727
echo -e "\033[30m===>\033[0m \033[32mStopping the running containers... \033[0m"
28-
container_name=$(docker ps -a | awk '{print $NF}'|grep -v NAMES)
29-
for cn in "${container_name}"
30-
do
31-
docker stop ${cn}
32-
done
28+
{ docker ps -aq || true; } | xargs docker stop
3329
echo
3430
}
3531

@@ -90,13 +86,9 @@ else
9086
# Start the container after the migration
9187
start_all_containers() {
9288
sudo systemctl restart docker
93-
container_name=$(docker ps -a | awk '{print $NF}'|grep -v NAMES)
9489
echo -e "\033[30m===>\033[0m \033[32mStarting the container... \033[0m"
9590
echo
96-
for cn in "${container_name}"
97-
do
98-
docker start ${cn}
99-
done
91+
{ docker ps -aq || true; } | xargs docker start
10092
echo
10193
}
10294

utilities/openemr-monitor/monitor-installer

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,15 @@ senderEmail=$4
77
emailPassword=$5
88
receiverEmail=$6
99

10-
# Check docker and dock-compose exist
10+
# Check docker
1111
DOCKER_CODE=10
1212
DOCKER_START=11
13-
DOCKER_COMPOSE_CODE=12
1413
if ! command -v docker &>/dev/null; then
15-
echo 'Please check docker and docker-compose install or not.'
16-
exit ${DOCKER_CODE}
17-
elif ! command -v docker-compose &>/dev/null; then
18-
echo 'Please check docker-compose install or not.'
19-
exit ${DOCKER_COMPOSE_CODE}
20-
elif [[ $(ps aux|grep dockerd|grep -v grep|wc -l) -ne 1 ]]; then
21-
echo "Please check doceker start or not."
22-
exit ${DOCKER_START}
14+
echo 'Please ensure docker is installed.'
15+
exit "${DOCKER_CODE}"
16+
elif ! docker info &> /dev/null; then
17+
echo 'Please ensure docker is started and properly configured.'
18+
exit "${DOCKER_START}"
2319
fi
2420

2521
# Modify the ip and mail setting for the yml files

0 commit comments

Comments
 (0)