feat: 新增安装deb时添加桌面图标,卸载时删除桌面图标功能.

This commit is contained in:
chriswang521 2024-07-23 11:10:21 +08:00 committed by wangpenglong
parent 44fa1559c1
commit 51d39f111d
2 changed files with 132 additions and 1 deletions

View File

@ -22,3 +22,84 @@ fi
if hash update-mime-database 2>/dev/null; then
update-mime-database /usr/share/mime
fi
# Install the desktop icon
function copy_install_to_desktop()
{
if [ $# -ne 3 ] ; then
return;
fi
local curFileName=$1
local ideDesktopName=$2
local curUserName=$3
if [ -e "/usr/share/applications/${ideDesktopName}" ]; then
cp -f /usr/share/applications/${ideDesktopName} "${curFileName}/${gDesktopName}/${ideDesktopName}"
if test $? -eq 0; then
chmod +x "${curFileName}/${gDesktopName}/${ideDesktopName}"
chown ${curUserName} "${curFileName}/${gDesktopName}/${ideDesktopName}"
fi
fi
}
function deploy_ide_desktop_icon()
{
if [ $# -ne 2 ] ; then
return;
fi
local curFileName=$1
local curUserName=$2
copy_install_to_desktop ${curFileName} @@NAME@@.desktop ${curUserName}
}
function ky_deploy_ide_desktop()
{
gDesktopName=""
if [ -d "/root/桌面" ]; then
gDesktopName="桌面"
elif [ -d "/root/Desktop" ]; then
gDesktopName="Desktop"
fi
if [ ! -z "$gDesktopName" ]; then
rm -f /root/${gDesktopName}/@@NAME@@.desktop
if [ -d "/root/${gDesktopName}" ]; then
deploy_ide_desktop_icon "/root" "root"
fi
fi
for FILENAME in /home/*; do
USERNAME="${FILENAME##*/}"
[ ! -d "${FILENAME}" ] && continue
getent passwd "${USERNAME}" >/dev/null 2>&1 || continue
if id -u `echo ${FILENAME} | awk '{print substr($FILENAME, 7, 32)}'` >/dev/null 2>&1; then
:
else
continue
fi
if [ -f "${FILENAME}/.config/user-dirs.dirs" ]; then
if [ ! $HOME ]; then
HOME=${FILENAME}
fi
source "${FILENAME}/.config/user-dirs.dirs"
if [ ! -d "${XDG_DESKTOP_DIR}" ]; then
mkdir -p "${XDG_DESKTOP_DIR}" >/dev/null 2>&1 || true
fi
gDesktopName="${XDG_DESKTOP_DIR//${HOME}\//}"
else
if [ -d "${FILENAME}/桌面" ]; then
gDesktopName="桌面"
elif [ -d "${FILENAME}/Desktop" ]; then
gDesktopName="Desktop"
fi
fi
curUserName=`echo ${FILENAME} | awk '{print substr($FILENAME, 7, 32)}'`
rm -f /home/${curUserName}/${gDesktopName}/@@NAME@@.desktop
deploy_ide_desktop_icon ${FILENAME} ${curUserName}
done
}
ky_deploy_ide_desktop

View File

@ -4,4 +4,54 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# Deregister code from the alternatives system
update-alternatives --remove editor /usr/bin/@@NAME@@
update-alternatives --remove editor /usr/bin/@@NAME@@
# Uninstall desktop icon
function ky_prerm_uninstall_ide_desktop_icon(){
gDesktopName=""
if [ -d "/root/桌面" ]; then
gDesktopName="桌面"
elif [ -d "/root/Desktop" ]; then
gDesktopName="Desktop"
fi
if [ ! -z "$gDesktopName" ]; then
if [ -d "/root/${gDesktopName}" ]; then
rm -f /root/${gDesktopName}/@@NAME@@.desktop
fi
fi
for FILENAME in /home/*; do
USERNAME="${FILENAME##*/}"
[ ! -d "${FILENAME}" ] && continue
getent passwd "${USERNAME}" >/dev/null 2>&1 || continue
if id -u `echo ${FILENAME} | awk '{print substr($FILENAME, 7, 32)}'` >/dev/null 2>&1; then
:
else
continue
fi
if [ -f "${FILENAME}/.config/user-dirs.dirs" ]; then
if [ ! $HOME ]; then
HOME=${FILENAME}
fi
source "${FILENAME}/.config/user-dirs.dirs"
if [ ! -d "${XDG_DESKTOP_DIR}" ]; then
mkdir -p "${XDG_DESKTOP_DIR}" >/dev/null 2>&1 || true
fi
gDesktopName="${XDG_DESKTOP_DIR//${HOME}\//}"
else
if [ -d "${FILENAME}/桌面" ]; then
gDesktopName="桌面"
elif [ -d "${FILENAME}/Desktop" ]; then
gDesktopName="Desktop"
fi
fi
if [ -f "${FILENAME}/${gDesktopName}/@@NAME@@.desktop" ]; then
rm -f "${FILENAME}/${gDesktopName}/@@NAME@@.desktop"
fi
done
}
ky_prerm_uninstall_ide_desktop_icon