Skip to content

Commit cee7037

Browse files
committed
shellcheck
1 parent cfb3bbb commit cee7037

19 files changed

+88
-73
lines changed

Kubernetes/finalize-k8s-obj.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
kubectl patch KIND -n NAMESPACE NAME -p '{"metadata":{"finalizers":[]}}' --type='merge'
22

33
# Many:
4-
kubectl get flinkdeployment,flinksessionjob -n ${k8s_namespace} | \
4+
k8s_namespace="xxx"
5+
kubectl get flinkdeployment,flinksessionjob -n "${k8s_namespace}" | \
56
grep flink | awk '{print $1}' | xargs -I {} kubectl patch \
6-
-n ${k8s_namespace} {} -p '{"metadata":{"finalizers":[]}}' --type='merge' || true
7+
-n "${k8s_namespace}" {} -p '{"metadata":{"finalizers":[]}}' --type='merge' || true

Kubernetes/sealed-secret-gen.sh

+20-22
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
PASS_LEN=${PASS_LEN:-xxx}
2-
SCRIPT_NAME=$(basename "$0")
3-
ARGS="$*"
1+
PASS_LEN="${PASS_LEN:-xxx}"
42
SEAL_CMD="/usr/bin/env kubeseal --controller-namespace sealed-secrets -o yaml --allow-empty-data --scope xxx"
53
TMP_FILE=/tmp/sealedsecret.yaml
64

75
while getopts "h?pi:" opt; do
8-
case "$opt" in
6+
case "${opt}" in
97
h|\?)
108
echo '+------------------------------------HELP------------------------------------+'
119
echo '| This script can generate a SealedSecret from a given Secret. |'
@@ -18,52 +16,52 @@ while getopts "h?pi:" opt; do
1816
;;
1917
p)
2018
# shellcheck disable=SC2181
21-
password=$(export LC_CTYPE=C; false; while [ $? -ne 0 ]; do tr -dc A-Za-z0-9 < /dev/urandom | \
22-
head -c "$PASS_LEN"; done)
19+
password=$(export LC_CTYPE=C; false; while [ "${?}" -ne 0 ]; do \
20+
tr -dc A-Za-z0-9 < /dev/urandom | head -c "${PASS_LEN}"; done)
2321
;;
24-
i) input_file=$OPTARG
22+
i) input_file="${OPTARG}"
2523
;;
2624
esac
2725
done
2826
2927
shift $((OPTIND-1))
3028
[ "${1:-}" = "--" ] && shift
3129
32-
if [ -n "$1" ]; then
33-
echo "Unknown argument: $1" >&2
30+
if [ -n "${1}" ]; then
31+
echo "Unknown argument: ${1}" >&2
3432
exit 2
3533
fi
3634
37-
if [ -z "$input_file" ]; then
35+
if [ -z "${input_file}" ]; then
3836
echo "Required argument is missing: -i <file containing a Kubernetes Secret>." >&2
3937
exit 2
4038
fi
4139
42-
if [ ! -f "$input_file" ]; then
43-
echo "File not found: $input_file." >&2
40+
if [ ! -f "${input_file}" ]; then
41+
echo "File not found: ${input_file}." >&2
4442
exit 1
4543
fi
4644
47-
input=$(yq 'del(.metadata.namespace)' "$input_file" | sed '/ null$/d')
48-
echo "$input" | $SEAL_CMD > $TMP_FILE
49-
name=$(yq '.metadata.name' "$input_file")
45+
input=$(yq 'del(.metadata.namespace)' "${input_file}" | sed '/ null$/d')
46+
echo "${input}" | ${SEAL_CMD} > "${TMP_FILE}"
47+
name=$(yq '.metadata.name' "${input_file}")
5048
51-
if [ -n "$password" ]; then
52-
echo -n "$password" | kubectl create secret generic "$name" \
49+
if [ -n "${password}" ]; then
50+
echo -n "${password}" | kubectl create secret generic "${name}" \
5351
--dry-run=client --from-file=password=/dev/stdin -o yaml | \
54-
$SEAL_CMD --merge-into $TMP_FILE
52+
${SEAL_CMD} --merge-into "${TMP_FILE}"
5553
fi
5654
57-
result=$(sed '/ null$/d' $TMP_FILE)
58-
rm -f $TMP_FILE
55+
result=$(sed '/ null$/d' "${TMP_FILE}")
56+
rm -f "${TMP_FILE}"
5957
6058
echo "# Input:"
6159
echo "# ---"
6260
# shellcheck disable=SC2001
63-
echo "$input" | sed 's/^/# /g'
61+
echo "${input}" | sed 's/^/# /g'
6462
echo
6563
6664
echo "# Result:"
6765
echo ---
68-
echo "$result" | yq 'del(.spec.template)'
66+
echo "${result}" | yq 'del(.spec.template)'
6967
echo

Other/LinuxAdventures/FedoraGnome/bootstrap.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ configure_user() {
77
https://github.com/romkatv/powerlevel10k.git ~/powerlevel10k --depth 1
88

99
# Dotfiles
10-
if [ ${OS_USERNAME} = "vagrant" ]; then
10+
if [ "${OS_USERNAME}" = "vagrant" ]; then
1111
cp -r /vagrant/Home/.* ~/
1212
else
1313
cp -Lr ./Home/.* ~/
@@ -32,7 +32,7 @@ get_docker() {
3232
/etc/docker/daemon.json
3333
systemctl restart docker
3434
systemctl enable docker
35-
usermod -aG docker ${OS_USERNAME}
35+
usermod -aG docker "${OS_USERNAME}"
3636
}
3737

3838
# Base repo packages
@@ -58,10 +58,10 @@ wget -qO /usr/local/bin/pfetch \
5858
https://github.com/raw/dylanaraps/pfetch/master/pfetch
5959
chmod +x /usr/local/bin/pfetch
6060

61-
if [ ${OS_USERNAME} = "vagrant" ]; then
61+
if [ "${OS_USERNAME}" = "vagrant" ]; then
6262
# De-bloat
6363
hostnamectl hostname fedora
64-
> /etc/motd
64+
true > /etc/motd
6565
grep "#PrintLastLog yes" /etc/ssh/sshd_config \
6666
&& sed -i "s/#PrintLastLog yes/PrintLastLog no/" /etc/ssh/sshd_config \
6767
&& systemctl restart sshd
@@ -78,5 +78,5 @@ fi
7878

7979
# Regular user configuration
8080
export -f configure_user
81-
su ${OS_USERNAME} -c "bash -xec configure_user"
82-
chsh -s $(which zsh) ${OS_USERNAME}
81+
su "${OS_USERNAME}" -c "bash -xec configure_user"
82+
chsh -s "$(which zsh)" "${OS_USERNAME}"

Other/LinuxAdventures/TumbleweedPlasma/bootstrap.sh

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ get_executable() {
66
}
77

88
get_repo() {
9+
# shellcheck disable=SC2015
910
cd "$1" && git pull || git clone "$2" "$1"
1011
}
1112

Other/LinuxAdventures/UnusedDistros/Virtual/bootstrap-ubuntu.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pretty() {
1818
# p10k
1919
[[ -d ~/.oh-my-zsh/custom/themes/powerlevel10k ]] || git clone \
2020
--depth=1 https://github.com/romkatv/powerlevel10k.git \
21-
${ZSH_CUSTOM:-${HOME}/.oh-my-zsh/custom}/themes/powerlevel10k
21+
"${ZSH_CUSTOM:-${HOME}/.oh-my-zsh/custom}/themes/powerlevel10k"
2222

2323
# Main venv
2424
python3 -m venv ~/.venv
@@ -54,6 +54,7 @@ install -m 0755 -d /etc/apt/keyrings
5454
gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \
5555
chmod a+r /etc/apt/keyrings/docker.gpg; }
5656

57+
# shellcheck disable=SC2027,SC2046
5758
echo \
5859
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] \
5960
https://download.docker.com/linux/ubuntu \
@@ -66,7 +67,7 @@ apt-get install -yq docker-ce docker-ce-cli containerd.io \
6667
echo '{"default-address-pools":[{"base":"10.2.0.0/16","size":24}]}' > /etc/docker/daemon.json
6768

6869
systemctl restart docker
69-
usermod -aG docker ${OS_USER}
70+
usermod -aG docker "${OS_USER}"
7071
# Docker end
7172

7273
# MongoDB repo
@@ -109,7 +110,7 @@ chmod +x /usr/local/bin/websocat
109110

110111
export -f pretty
111112
su ${OS_USER} -c "bash -xec pretty"
112-
chsh -s $(which zsh) ${OS_USER}
113+
chsh -s "$(which zsh)" "${OS_USER}"
113114

114115
apt_up
115116
echo REMEMBER TO BRING YOUR DOTFILES NOW
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sudo chown -Rv $USER: /var/cache/zypp/raw
1+
sudo chown -Rv "${USER}:" /var/cache/zypp/raw

Other/VagrantSetup/Vagrant/bootstrap.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ configure_user() {
77
https://github.com/romkatv/powerlevel10k.git ~/powerlevel10k --depth 1
88

99
# Dotfiles
10-
if [ ${OS_USERNAME} = "vagrant" ]; then
10+
if [ "${OS_USERNAME}" = "vagrant" ]; then
1111
cp -r /vagrant/Home/.* ~/
1212
else
1313
cp -Lr ./Home/.* ~/
@@ -32,7 +32,7 @@ get_docker() {
3232
/etc/docker/daemon.json
3333
systemctl restart docker
3434
systemctl enable docker
35-
usermod -aG docker ${OS_USERNAME}
35+
usermod -aG docker "${OS_USERNAME}"
3636
}
3737

3838
# Base repo packages
@@ -58,10 +58,10 @@ wget -qO /usr/local/bin/pfetch \
5858
https://github.com/raw/dylanaraps/pfetch/master/pfetch
5959
chmod +x /usr/local/bin/pfetch
6060

61-
if [ ${OS_USERNAME} = "vagrant" ]; then
61+
if [ "${OS_USERNAME}" = "vagrant" ]; then
6262
# De-bloat
6363
hostnamectl hostname fedora
64-
> /etc/motd
64+
true > /etc/motd
6565
grep "#PrintLastLog yes" /etc/ssh/sshd_config \
6666
&& sed -i "s/#PrintLastLog yes/PrintLastLog no/" /etc/ssh/sshd_config \
6767
&& systemctl restart sshd
@@ -78,5 +78,5 @@ fi
7878

7979
# Regular user configuration
8080
export -f configure_user
81-
su ${OS_USERNAME} -c "bash -xec configure_user"
82-
chsh -s $(which zsh) ${OS_USERNAME}
81+
su "${OS_USERNAME}" -c "bash -xec configure_user"
82+
chsh -s "$(which zsh)" "${OS_USERNAME}"

Other/VagrantSetup/macos-vagrant-vars.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# shellcheck disable=SC2003,SC2046
2+
13
export VAGRANT_EXPERIMENTAL="disks"
24

35
CALC_MEM=$(expr $(system_profiler SPHardwareDataType | \
@@ -13,5 +15,5 @@ export GIT_EMAIL="[email protected]"
1315
export DISK_GB=200
1416
export PORT_TCP=8080
1517

16-
export MEMORY=$(( ${CALC_MEM} > 1024 ? ${CALC_MEM} : 1024 ))
17-
export CPUS=$(( ${CALC_CPU} > 1 ? ${CALC_CPU} : 1 ))
18+
export MEMORY=$(( CALC_MEM > 1024 ? CALC_MEM : 1024 ))
19+
export CPUS=$(( CALC_CPU > 1 ? CALC_CPU : 1 ))

Other/VagrantSetup/vagrant-debian-bootstrap.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pretty() {
2424
# p10k
2525
[[ -d ~/.oh-my-zsh/custom/themes/powerlevel10k ]] || git clone \
2626
--depth=1 https://github.com/romkatv/powerlevel10k.git \
27-
${ZSH_CUSTOM:-${HOME}/.oh-my-zsh/custom}/themes/powerlevel10k
27+
"${ZSH_CUSTOM:-${HOME}/.oh-my-zsh/custom}/themes/powerlevel10k"
2828

2929
# Main venv
3030
python3 -m venv ~/.venv
@@ -61,6 +61,7 @@ install -m 0755 -d /etc/apt/keyrings
6161
gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \
6262
chmod a+r /etc/apt/keyrings/docker.gpg; }
6363

64+
# shellcheck disable=SC2027,SC2046
6465
echo \
6566
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] \
6667
https://download.docker.com/linux/debian \
@@ -121,11 +122,11 @@ chmod +x /usr/local/bin/websocat
121122
# User configuration for vagrant
122123
export -f pretty
123124
su vagrant -c "bash -xec pretty"
124-
chsh -s $(which zsh) vagrant
125+
chsh -s "$(which zsh)" vagrant
125126

126127
# Ensure the filesystem takes the whole virtual disk
127128
growpart /dev/sda 1 || true
128129
resize2fs /dev/sda1 || true
129130

130-
> /etc/motd
131+
true > /etc/motd
131132
apt_up

Shell/AWS/ec2-csv.sh

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# shellcheck disable=SC2016
12
aws ec2 describe-instances \
23
--filters "Name=instance-state-name,Values=running,stopped,stopping,shutting-down" \
34
--query 'Reservations[].Instances[].{Name: Tags[?Key==`Name`].Value | [0], xxx: Tags[?Key==`xxx`].Value | [0], InstanceId: InstanceId, State: State.Name, Type: InstanceType}' \

Shell/AWS/get-all-cidrs.sh

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ profiles=$(grep -Eo "^\[profile (.+)\]$" ~/.aws/config | cut -d" " -f2 | tr -d "
66
regions="XXX XXX XXX"
77
output=""
88

9-
for profile in $profiles; do
10-
for region in $regions; do
11-
echo "Checking $region in $profile..." >&2
9+
for profile in ${profiles}; do
10+
for region in ${regions}; do
11+
echo "Checking ${region} in ${profile}..." >&2
1212
output+=$(aws ec2 describe-vpcs --output text --query "Vpcs[*].[CidrBlock]" \
13-
--region "$region" --profile "$profile" 2> /dev/null)
13+
--region "${region}" --profile "${profile}" 2> /dev/null)
1414
output+="\n"
1515
done
1616
done
1717

1818
echo >&2
1919
echo "Results:" >&2
20-
echo -e "$output" | sort | grep --color=never .
20+
echo -e "${output}" | sort | grep --color=never .

Shell/AWS/gp2-gp3.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
regions=$($AWS ec2 describe-regions --output text | cut -f4)
1+
regions=$(${AWS} ec2 describe-regions --output text | cut -f4)
22

33
for region in ${regions}; do
44
echo "------------------------------------"
5-
echo "Iterating over region $region ..."
5+
echo "Iterating over region ${region}..."
66

77
# shellcheck disable=SC2016
8-
volume_ids=$($AWS ec2 describe-volumes --region "$region" \
8+
volume_ids=$($AWS ec2 describe-volumes --region "${region}" \
99
--filters Name=volume-type,Values=gp2 --output text \
1010
--query 'Volumes[?Size <= `1000`].VolumeId')
1111

Shell/AWS/impersonate-role-aws.sh

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
# shellcheck disable=SC2046
12
eval $(aws sts assume-role --role-arn arn:aws:iam::123456789123:role/myAwesomeRole --role-session-name test | \
23
jq -r '.Credentials | "export AWS_ACCESS_KEY_ID=\(.AccessKeyId)\nexport AWS_SECRET_ACCESS_KEY=\(.SecretAccessKey)\nexport AWS_SESSION_TOKEN=\(.SessionToken)\n"')

Shell/AWS/run-ecs-task.sh

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# shellcheck disable=SC2086
12
set -o allexport
23
source .env
34
set +o allexport

Shell/AWS/update-eks-addons.sh

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
eks_version=$(xxxxx)
2+
region="yyyyy"
3+
cluster_name="zzzzz"
24

35
for addon in vpc-cni coredns kube-proxy aws-ebs-csi-driver; do
4-
addon_version=$(aws eks describe-addon-versions --region ${region} --addon-name ${addon} \
5-
--kubernetes-version ${eks_version} --query 'addons[].addonVersions[0].addonVersion' --output text)
6+
addon_version=$(aws eks describe-addon-versions --region "${region}" --addon-name "${addon}" \
7+
--kubernetes-version "${eks_version}" --query 'addons[].addonVersions[0].addonVersion' --output text)
68

7-
aws eks update-addon --region ${region} --cluster-name ${cluster_name} \
8-
--addon-name ${addon} --addon-version ${addon_version} --resolve-conflicts XXX
9+
aws eks update-addon --region "${region}" --cluster-name "${cluster_name}" \
10+
--addon-name "${addon}" --addon-version "${addon_version}" --resolve-conflicts XXX
911

10-
aws eks wait addon-active --region ${region} --cluster-name ${cluster_name} --addon-name ${addon}
12+
aws eks wait addon-active --region "${region}" --cluster-name "${cluster_name}" --addon-name "${addon}"
1113
done

Shell/AWS/update-eks-node-group.sh

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
node_group_name=$(xxxxx)
2+
region="yyyyy"
3+
cluster_name="zzzzz"
24

3-
aws eks update-nodegroup-version --cluster-name ${cluster_name} --region ${region} \
4-
--nodegroup-name ${node_group_name}
5+
aws eks update-nodegroup-version --cluster-name "${cluster_name}" \
6+
--region "${region}" --nodegroup-name "${node_group_name}"
57

6-
aws eks wait nodegroup-active --cluster-name ${cluster_name} --region ${region} \
7-
--nodegroup-name ${node_group_name}
8+
aws eks wait nodegroup-active --cluster-name "${cluster_name}" \
9+
--region "${region}" --nodegroup-name "${node_group_name}"

Shell/Git/promote-monochart.sh

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
# shellcheck disable=SC2154,SC2016
2+
13
# If full merge
2-
cd ${manifest_dir}
3-
git checkout ${dest_branch}
4-
git merge ${src_branch} --no-commit --strategy-option theirs
4+
cd "${manifest_dir}"
5+
git checkout "${dest_branch}"
6+
git merge "${src_branch}" --no-commit --strategy-option theirs
57
rm -f .git/MERGE_HEAD
68

79
# If single service
8-
cd ${manifest_dir}
10+
cd "${manifest_dir}"
911
export new_tag=$(yq '.${specific_app}.bbbbb' xxxx/yyyy.yaml)
10-
git checkout ${dest_branch}
12+
git checkout "${dest_branch}"
1113
yq '. | .${specific_app}.bbbbb = env(new_tag)' xxxx/yyyy.yaml > yyyy.yaml.tmp \
1214
&& mv yyyy.yaml.tmp xxxx/yyyy.yaml
13-
git checkout ${src_branch} -- zxxxx/${specific_app}.yaml
15+
git checkout "${src_branch}" -- "zxxxx/${specific_app}.yaml"
1416

1517
### PUSH LOGIC GOES HERE ###

Shell/Packages/get-distro.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
if [ $(grep "^ID=" /etc/os-release | cut -d"=" -f2 | tr -d '"') = "almalinux" ]; then echo yes; fi
1+
release=$(grep "^ID=" /etc/os-release | cut -d"=" -f2 | tr -d '"')
2+
if [ "${release}" = "almalinux" ]; then echo yes; fi

Shell/gunicorn-django-run.sh

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
# ./manage.py collectstatic --noinput
44
./manage.py migrate
55

6+
# shellcheck disable=SC2046
67
gunicorn xx.wsgi \
7-
--workers ${WORKERS} \
8-
--threads ${THREADS} \
9-
--bind 0.0.0.0:${PORT} \
8+
--workers "${WORKERS}" \
9+
--threads "${THREADS}" \
10+
--bind "0.0.0.0:${PORT}" \
1011
--access-logfile - \
11-
--log-level $([ ${DEBUG:-0} = 1 ] && echo debug || echo info)
12+
--log-level $([ "${DEBUG:-0}" = 1 ] && echo debug || echo info)

0 commit comments

Comments
 (0)