#!/bin/bash
# 获取系统中的所有用户列表
users=$(cut -d: -f1 /etc/passwd)
# 遍历每个用户并执行命令
for user in $users; do
# 获取用户的 home 目录
home_dir=$(getent passwd "$user" | cut -d: -f6)
# 检查 home 目录是否存在
if [ -d "$home_dir" ]; then
# 使用 su -c 来以用户身份执行命令
su - "$user" -c "git config --global core.hooksPath /opt/githook/"
echo "Command executed for user: $user"
else
echo "Home directory for user $user does not exist, skipping."
fi
done