如何创建 debian 包以将文件安装到 /home/user

如何创建 debian 包以将文件安装到 /home/user

我创建了一个 Debian 软件包,我想将文件安装到该目录/home/user/myapp而不是/usr/bin

但是安装deb后,所有者/home/user/myapp是root

我希望安装 deb 后,所有者应该是用户,所以我添加 postinst 来完成后期工作:

#postinst
chown -R user /home/user/myapp

但我总是收到错误“chown:...不允许操作”

任何想法?

答案1

整体观点Debian 软件包的作用是安装系统范围的软件。想一想:如果多个用户将此软件包安装到各自的/home/user/myapp区域,那么您的软件包管理器中应该显示什么?

如果您想安装到主目录,请使用原始源(例如 tarball)发行版。

答案2

您需要在软件包的安装后创建一个例程,复制您需要放在用户家中的内容

像这样的东西:

# For every user in /home/ ...
for HOME_U in /home/*?; do

# Obtain the username
USER=$( basename ${HOME_U} )

# In case the user is active (exists in /etc/shadow) ...
if [ $( grep -c "${USER}:.*:.*:.*:.*:.*:::" /etc/shadow ) == 1 ] \
&& [ $( grep -c "${USER}:.*:.*:.*:.*:.*:/bin/.*sh" /etc/passwd ) == 1 ] \
&& [ -d ${HOME_U}/.config ] \
&& [ -d ${HOME_U} ]; then

# Making sure .config/your-package/ exists
mkdir -p /home/${USER}/.config/your-package/

# with appropiate permissions
chown ${USER}:${USER} /home/${USER}/.config/your-package/

# copy what we need
cp /etc/skel/.config/your-package/x.conf /home/${USER}/.config/your-package/
cp /etc/skel/.config/your-package/y.conf /home/${USER}/.config/your-package/
cp ... /home/${USER}/.config/your-package/

# with appropiate permissions
chown ${USER}:${USER} /home/${USER}/.config/your-package/x.conf
chown ${USER}:${USER} /home/${USER}/.config/your-package/y.conf
...

fi
done

希望你能使用它。

相关内容