aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-09-17 17:58:27 +0700
committerShulhan <ms@kilabit.info>2022-09-17 22:28:30 +0700
commit36bc0c7fb5df2b9dfebb9be153ccdea46c0b3d80 (patch)
treea5b80c2d495c14804aba434ce81c4f14eea225ce /bin
parent397789cea60237f357476c86df96cd234e7b37eb (diff)
downloadbin.sh-36bc0c7fb5df2b9dfebb9be153ccdea46c0b3d80.tar.xz
all: add script chmod-x.sh
chmod-x.sh is a script to remove executable bit from file that may not an executable.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/chmod-x.sh30
1 files changed, 30 insertions, 0 deletions
diff --git a/bin/chmod-x.sh b/bin/chmod-x.sh
new file mode 100755
index 0000000..fe8ae9a
--- /dev/null
+++ b/bin/chmod-x.sh
@@ -0,0 +1,30 @@
+#!/bin/sh
+## SPDX-FileCopyrightText: 2022 M. Shulhan <ms@kilabit.info>
+## SPDX-License-Identifier: GPL-3.0-or-later
+
+## Script to recursively scan directory and remove executable-bit from file
+## that may not an executable.
+##
+## Usage
+##
+## $ chmod-x.sh dir
+
+DIR=$1
+
+if [[ -z "$DIR" ]]; then
+ echo "$0 <directory>"
+ exit 1
+fi
+
+IFS=:
+MAYBE_BIN="ELF 32-bit | shell script | executable";
+
+echo "Checking in directory: $DIR"
+
+for file in $(find $DIR -type f -perm /111 -printf "%p$IFS")
+do
+ if ! file $file | grep -q -E "$MAYBE_BIN"; then
+ echo "$file"
+ chmod -x $file
+ fi
+done