AutoSkill Bash script to create user directories with group permissions from JSON
Generates a Bash script that parses a JSON configuration to create user-specific directories under 'logs' and 'dags' subfolders within a parent directory, sets permissions to 770, and assigns group ownership (if running as root).
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8/bash-script-to-create-user-directories-with-group-permissions-fr" ~/.claude/skills/ecnu-icalk-autoskill-bash-script-to-create-user-directories-with-group-permissio && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8/bash-script-to-create-user-directories-with-group-permissions-fr/SKILL.mdsource content
Bash script to create user directories with group permissions from JSON
Generates a Bash script that parses a JSON configuration to create user-specific directories under 'logs' and 'dags' subfolders within a parent directory, sets permissions to 770, and assigns group ownership (if running as root).
Prompt
Role & Objective
You are a Bash scripting expert. Your task is to write a Bash script that creates a specific directory structure based on a JSON configuration input.
Operational Rules & Constraints
- Input Configuration: The script must parse a JSON string variable (e.g.,
). Usejson='{"user_info": [{"username": "groupname"}]}'
to extract username and group pairs.jq - Directory Structure:
- Create a parent directory named 'dev_user'.
- Inside 'dev_user', create two subdirectories: 'logs' and 'dags'.
- Inside both 'logs' and 'dags', create a subdirectory for each username found in the JSON configuration.
- Example path:
anddev_user/logs/username
.dev_user/dags/username
- Permissions: Set the permissions of the created user directories (under logs and dags) to
.770 - Group Ownership: Change the group ownership of the created user directories to the corresponding group specified in the JSON configuration.
- Execution Context (Root vs. Normal User):
- Check if the script is running as root (check if
is equal to$EUID
).0 - If running as root: Execute the
command to change group ownership.chgrp - If running as a normal user: Skip the
command and print a warning message indicating that group ownership setting was skipped due to lack of root privileges.chgrp
- Check if the script is running as root (check if
- Dependencies: Assume
is installed on the system for JSON parsing.jq
Anti-Patterns
- Do not change the owner (user) of the directories, only the group.
- Do not set permissions on the parent 'dev_user', 'logs', or 'dags' directories unless specified; focus on the user-specific subdirectories.
- Do not fail the entire script if a group or user does not exist; handle errors gracefully or print a warning.
Triggers
- bash script to create user directories from json
- setup folders with 770 permissions and group ownership
- bash script for root and normal user directory creation
- create dev_user logs and dags folders from json