Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start-ceph: do rm -rf only when path exists #88

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nizamial09
Copy link
Member

start-ceph.sh has a line to remove rm -rf "$CEPH_CONF_PATH"/* If someone run this script locally when he has root previllages, he could accidentally remove his / directory because CEPH_CONF_PATH will come empty and the command will become rm -rf /* which is like shooting yourself infinitely..

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

shellcheck

🚫 [shellcheck] reported by reviewdog 🐶
Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @). SC2199

if [[ -n "$@" ]]; then


⚠️ [shellcheck] reported by reviewdog 🐶
Assigning an array to a string! Assign as array, or use * instead of @ to concatenate. SC2124


[shellcheck] reported by reviewdog 🐶
Consider using 'grep -c' instead of 'grep|wc -l'. SC2126

if [[ "$(tox -l | grep cov | wc -l)" > 0 ]]; then # Nautilus branch.


🚫 [shellcheck] reported by reviewdog 🐶
> is for string comparisons. Use -gt instead. SC2071

if [[ "$(tox -l | grep cov | wc -l)" > 0 ]]; then # Nautilus branch.


📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

tox ${TOX_OPTIONS} $TOX_ARGS


⚠️ [shellcheck] reported by reviewdog 🐶
Declare and assign separately to avoid masking return values. SC2155

local grafonnet_version=$(grep 'set(ver' CMakeLists.txt | grep -Eo "([0-9.])+")


⚠️ [shellcheck] reported by reviewdog 🐶
Assigning an array to a string! Assign as array, or use * instead of @ to concatenate. SC2124


📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

mypy --config-file="$MYPY_CONFIG_FILE" --cache-dir=src/.mypy_cache --follow-imports=skip ${MYPY_ARGS}


📝 [shellcheck] reported by reviewdog 🐶
Not following: ./run-backend-api-tests.sh: openBinaryFile: does not exist (No such file or directory) SC1091

source ./run-backend-api-tests.sh


⚠️ [shellcheck] reported by reviewdog 🐶
Assigning an array to a string! Assign as array, or use * instead of @ to concatenate. SC2124

E2E_CMD="npx cypress run $@ --browser chrome --headless"


[shellcheck] reported by reviewdog 🐶
Consider using 'grep -c' instead of 'grep|wc -l'. SC2126

elif [[ "$(npm run | grep e2e:ci | wc -l)" == 1 ]]; then


📝 [shellcheck] reported by reviewdog 🐶
Consider using pgrep instead of grepping ps output. SC2009

if [[ $(ps -ef | grep -v grep | grep "ceph-mgr -i" | wc -l) == 0 ]]; then


[shellcheck] reported by reviewdog 🐶
Consider using 'grep -c' instead of 'grep|wc -l'. SC2126

if [[ $(ps -ef | grep -v grep | grep "ceph-mgr -i" | wc -l) == 0 ]]; then


⚠️ [shellcheck] reported by reviewdog 🐶
Declare and assign separately to avoid masking return values. SC2155

export DASHBOARD_URL=$("$CEPH_BIN"/ceph mgr services | jq -r .dashboard)


📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

${E2E_CMD} -- ${ARGS}


📝 [shellcheck] reported by reviewdog 🐶
Command appears to be unreachable. Check usage (or ignore if invoked indirectly). SC2317

return 2> /dev/null || true


📝 [shellcheck] reported by reviewdog 🐶
Command appears to be unreachable. Check usage (or ignore if invoked indirectly). SC2317

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Not following: /docker/set-start-env.sh: openBinaryFile: does not exist (No such file or directory) SC1091

source /docker/set-start-env.sh

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [shellcheck] reported by reviewdog 🐶
The surrounding quotes actually unquote this. Remove or escape them. SC2027

jq "(.[] | .target)=\""${TARGET_URL}"\"" proxy.conf.json.sample > proxy.conf.json

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

jq "(.[] | .target)=\""${TARGET_URL}"\"" proxy.conf.json.sample > proxy.conf.json

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [shellcheck] reported by reviewdog 🐶
Assigning an array to a string! Assign as array, or use * instead of @ to concatenate. SC2124

local TARGET="$@"

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [shellcheck] reported by reviewdog 🐶
Declare and assign separately to avoid masking return values. SC2155

local CONSOLE_CALLS=$((echo "${TARGET}" | xargs grep -Eirn "console\..*\(") || echo '')

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [shellcheck] reported by reviewdog 🐶
Shells disambiguate $(( differently or not at all. For $(command substitution), add space after $( . For $((arithmetics)), fix parsing errors. SC1102

local CONSOLE_CALLS=$((echo "${TARGET}" | xargs grep -Eirn "console\..*\(") || echo '')

@nizamial09
Copy link
Member Author

an example inside a container..

[root@8c015bb5eb48 ceph]# cd ceph-dev/docker/ceph
bash: cd: ceph-dev/docker/ceph: No such file or directory
[root@8c015bb5eb48 ceph]# ./start-ceph.sh
set-start-env.sh: line 10: hostname: command not found
rm: cannot remove '/ceph-dev': Device or resource busy
rm: cannot remove '/dev/pts/0': Operation not permitted
rm: cannot remove '/dev/pts/ptmx': Operation not permitted
rm: cannot remove '/dev/mqueue': Device or resource busy
rm: cannot remove '/dev/shm': Device or resource busy
rm: cannot remove '/dev/console': Device or resource busy
rm: cannot remove '/etc/hostname': Device or resource busy
rm: cannot remove '/etc/hosts': Device or resource busy
rm: cannot remove '/etc/resolv.conf': Device or resource busy
rm: cannot remove '/proc/fs/ext4/nvme0n1p2/fc_info': Read-only file system
rm: cannot remove '/proc/fs/ext4/nvme0n1p2/options': Read-only file system
rm: cannot remove '/proc/fs/ext4/nvme0n1p2/mb_stats': Read-only file system
rm: cannot remove '/proc/fs/ext4/nvme0n1p2/mb_groups': Read-only file system
rm: cannot remove '/proc/fs/ext4/nvme0n1p2/es_shrinker_info': Read-only file system
rm: cannot remove '/proc/fs/ext4/nvme0n1p2/mb_structs_summary': Read-only file system
rm: cannot remove '/proc/fs/jbd2/nvme0n1p2-8/info': Read-only file system
rm: cannot remove '/proc/fs/nfsd': Read-only file system

start-ceph has a line to remove `rm -rf "$CEPH_CONF_PATH"/*`
If someone run this script locally when he has root previllages, he
could accidentally remove his `/` directory because `CEPH_CONF_PATH`
will come empty and the command will become `rm -rf /*` which is like
shooting yourself infinitely..

Signed-off-by: Nizamudeen A <[email protected]>
@nizamial09
Copy link
Member Author

bot educated me about https://github.com/koalaman/shellcheck/wiki/SC2115, so going with it.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

shellcheck

⚠️ [shellcheck] reported by reviewdog 🐶
Assigning an array to a string! Assign as array, or use * instead of @ to concatenate. SC2124


📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

mypy --config-file="$MYPY_CONFIG_FILE" --cache-dir=src/.mypy_cache --follow-imports=skip ${MYPY_ARGS}


📝 [shellcheck] reported by reviewdog 🐶
Not following: ./run-backend-api-tests.sh: openBinaryFile: does not exist (No such file or directory) SC1091

source ./run-backend-api-tests.sh


⚠️ [shellcheck] reported by reviewdog 🐶
Assigning an array to a string! Assign as array, or use * instead of @ to concatenate. SC2124

E2E_CMD="npx cypress run $@ --browser chrome --headless"


[shellcheck] reported by reviewdog 🐶
Consider using 'grep -c' instead of 'grep|wc -l'. SC2126

elif [[ "$(npm run | grep e2e:ci | wc -l)" == 1 ]]; then


📝 [shellcheck] reported by reviewdog 🐶
Consider using pgrep instead of grepping ps output. SC2009

if [[ $(ps -ef | grep -v grep | grep "ceph-mgr -i" | wc -l) == 0 ]]; then


[shellcheck] reported by reviewdog 🐶
Consider using 'grep -c' instead of 'grep|wc -l'. SC2126

if [[ $(ps -ef | grep -v grep | grep "ceph-mgr -i" | wc -l) == 0 ]]; then


⚠️ [shellcheck] reported by reviewdog 🐶
Declare and assign separately to avoid masking return values. SC2155

export DASHBOARD_URL=$("$CEPH_BIN"/ceph mgr services | jq -r .dashboard)


📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

${E2E_CMD} -- ${ARGS}


📝 [shellcheck] reported by reviewdog 🐶
Command appears to be unreachable. Check usage (or ignore if invoked indirectly). SC2317

return 2> /dev/null || true


📝 [shellcheck] reported by reviewdog 🐶
Command appears to be unreachable. Check usage (or ignore if invoked indirectly). SC2317

@@ -45,7 +45,7 @@ if [[ -n "${DASHBOARD_URL}" ]]; then
exit 0
fi

rm -rf "$CEPH_CONF_PATH"/*
rm -rf "${CEPH_CONF_PATH:?}"/*

cd /ceph/build
../src/vstart.sh ${VSTART_OPTIONS}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [shellcheck] reported by reviewdog 🐶
Declare and assign separately to avoid masking return values. SC2155

readonly VSTART_HAS_SSL_FLAG=$(cat /ceph/src/vstart.sh | grep DASHBOARD_SSL | wc -l)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shellcheck] reported by reviewdog 🐶
Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. SC2002

readonly VSTART_HAS_SSL_FLAG=$(cat /ceph/src/vstart.sh | grep DASHBOARD_SSL | wc -l)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shellcheck] reported by reviewdog 🐶
Consider using 'grep -c' instead of 'grep|wc -l'. SC2126

readonly VSTART_HAS_SSL_FLAG=$(cat /ceph/src/vstart.sh | grep DASHBOARD_SSL | wc -l)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Possible misspelling: DASHBOARD_SSL may not be assigned. Did you mean DASHBOARD_URL? SC2153

if [[ "$DASHBOARD_SSL" == 0 && "$VSTART_HAS_SSL_FLAG" == 0 ]]; then

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [shellcheck] reported by reviewdog 🐶
Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @). SC2199

if [[ -n "$@" ]]; then

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [shellcheck] reported by reviewdog 🐶
Assigning an array to a string! Assign as array, or use * instead of @ to concatenate. SC2124

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shellcheck] reported by reviewdog 🐶
Consider using 'grep -c' instead of 'grep|wc -l'. SC2126

if [[ "$(tox -l | grep cov | wc -l)" > 0 ]]; then # Nautilus branch.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [shellcheck] reported by reviewdog 🐶
> is for string comparisons. Use -gt instead. SC2071

if [[ "$(tox -l | grep cov | wc -l)" > 0 ]]; then # Nautilus branch.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

tox ${TOX_OPTIONS} $TOX_ARGS

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [shellcheck] reported by reviewdog 🐶
Declare and assign separately to avoid masking return values. SC2155

local grafonnet_version=$(grep 'set(ver' CMakeLists.txt | grep -Eo "([0-9.])+")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant