Files
PropertyDeployment/sh/grant.sh
2025-12-09 20:22:03 +08:00

41 lines
1.5 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
set -e # 遇错即退出
##############################################################################
# 1. 获取当前脚本所在目录
##############################################################################
SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd)
DIR_PERM="755"
FILE_PERM="644"
echo -e "\n📂 [INFO] 当前目录:${SCRIPT_DIR}"
##############################################################################
# 2. 授权当前目录下所有文件和子目录
##############################################################################
echo -e "\n📌 开始授权 ${SCRIPT_DIR} 下的所有文件..."
# 修改目录权限
find "${SCRIPT_DIR}" -type d -exec chmod ${DIR_PERM} {} \;
# 修改文件权限
find "${SCRIPT_DIR}" -type f -exec chmod ${FILE_PERM} {} \;
# 修改所有者为当前用户
sudo chown -R "$(whoami):$(whoami)" "${SCRIPT_DIR}"
##############################################################################
# 3. 显示授权结果示例
##############################################################################
TEST_DIR=$(find "${SCRIPT_DIR}" -type d | head -n 1)
TEST_FILE=$(find "${SCRIPT_DIR}" -type f | head -n 1)
if [ -n "${TEST_DIR}" ]; then
echo -e "✅ 目录示例权限(${TEST_DIR}$(ls -ld "${TEST_DIR}" | awk '{print $1, $3, $4}')"
fi
if [ -n "${TEST_FILE}" ]; then
echo -e "✅ 文件示例权限(${TEST_FILE}$(ls -l "${TEST_FILE}" | awk '{print $1, $3, $4}')"
fi
echo -e "\n🎯 所有文件授权完成!\n"