From 36bc0c7fb5df2b9dfebb9be153ccdea46c0b3d80 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Sat, 17 Sep 2022 17:58:27 +0700 Subject: all: add script chmod-x.sh chmod-x.sh is a script to remove executable bit from file that may not an executable. --- Makefile | 1 + README | 4 ++++ bin/chmod-x.sh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100755 bin/chmod-x.sh diff --git a/Makefile b/Makefile index 9be6e01..2956183 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ install: install -d $(DESTDIR)/usr/bin + install bin/chmod-x.sh $(DESTDIR)/usr/bin/ install bin/tmux-session.sh $(DESTDIR)/usr/bin/ install bin/wg-activate.sh $(DESTDIR)/usr/bin/ diff --git a/README b/README index c5d348e..855d1cb 100644 --- a/README +++ b/README @@ -4,6 +4,10 @@ A collection of shell scripts. == Scripts +*chmod-x.sh*:: +Script to recursively scan directory and remove executable-bit from file that +may not an executable. + *tmux-session.sh*:: Script to open new tmux session with start directory based on configuration in `~/.tmux.session`. 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 +## 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 " + 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 -- cgit v1.3