COMPASSi/trunk/code/projects/Cpack/postinst

36 lines
1.1 KiB
Bash
Raw 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/sh
# 获取当前用户
USER=$SUDO_USER
# 获取桌面路径
DESKTOP_PATH=$(su - $USER -c 'echo $HOME')/桌面
# 桌面文件路径
DESKTOP_FILE="$DESKTOP_PATH/COMPASS-Rules2023.desktop"
# 检查桌面文件是否存在
if [ -f "$DESKTOP_FILE" ]; then
chown $USER:$USER "$DESKTOP_FILE"
else
echo "Desktop file not found!"
fi
# 更改目录文件所有者
sudo chown -R $USER:$USER /usr/local/COMPASS-Rules2023
echo "Post-installation script is running..."
# 修改目标用户的 .bashrc 文件
echo "export LD_LIBRARY_PATH=/usr/local/COMPASS-Rules2023/lib:$LD_LIBRARY_PATH" >> /home/$USER/.bashrc
# 为 root 用户添加环境变量
echo "export LD_LIBRARY_PATH=/usr/local/COMPASS-Rules2023/lib:$LD_LIBRARY_PATH" >> /root/.bashrc
# 为所有用户包括root添加环境变量如果想让所有用户都能加载此环境变量
echo "export LD_LIBRARY_PATH=/usr/local/COMPASS-Rules2023/lib:$LD_LIBRARY_PATH" >> /etc/profile
# 让目标用户的 .bashrc 生效
sudo -u $USER bash -l -c "source /home/$USER/.bashrc"
# 让 root 用户的 .bashrc 生效
bash -l -c "source /root/.bashrc"
echo "Environment variables updated for root and $USER."