Skip to content

Commit

Permalink
Allow dirty
Browse files Browse the repository at this point in the history
  • Loading branch information
francescobianco committed Nov 26, 2024
1 parent 33a7396 commit 0849346
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions bin/myown
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env bash
## BP010: Release metadata
## @build_type: bin
## @build_date: 2024-11-26T23:25:25Z
set -e
use() { return 0; }
extern() { return 0; }
legacy() { return 0; }
module() { return 0; }
public() { return 0; }
embed() { return 0; }
## BP004: Compile the entrypoint

usage() {
echo "Usage: myown [-r] file1 [file2 ...]"
echo " -r Apply changes recursively"
exit 1
}

main() {

# Leggi utente e gruppo di $HOME
USER_GROUP=$(ls -ld "$HOME" | awk '{print $3 ":" $4}')

# Variabile per la modalità ricorsiva
RECURSIVE=""
TARGETS=""

# Analizza gli argomenti
for ARG in "$@"; do
if [ "$ARG" = "-r" ]; then
RECURSIVE="-R"
else
TARGETS="$TARGETS $ARG"
fi
done

# Controlla che ci siano file o directory
if [ -z "$TARGETS" ]; then
usage
fi

# Applica utente e gruppo agli argomenti
for TARGET in $TARGETS; do
if [ -e "$TARGET" ]; then
chown $RECURSIVE "$USER_GROUP" "$TARGET" >/dev/null 2>/dev/null && true
if [ $? -eq 0 ]; then
echo "Changed ownership of $TARGET to $USER_GROUP"
else
echo "High privileded are required"
sudo chown $RECURSIVE "$USER_GROUP" "$TARGET" && true
if [ $? -eq 0 ]; then
echo "Changed ownership of $TARGET to $USER_GROUP"
else
echo "Failed to change ownership of $TARGET" >&2
fi

fi
else
echo "File or directory $TARGET does not exist" >&2
fi
done

}
## BP005: Execute the entrypoint
main "$@"

0 comments on commit 0849346

Please sign in to comment.