-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33a7396
commit 0849346
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "$@" |