mirror of
https://gitee.com/bianbu-linux/ai-support
synced 2025-04-24 06:07:24 -04:00
144 lines
3.7 KiB
Bash
Executable file
144 lines
3.7 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
set -e
|
|
#set -x
|
|
|
|
aiDesktop=(
|
|
"object-detection.desktop"
|
|
#"hand-tracker.desktop"
|
|
"pose-tracker.desktop"
|
|
)
|
|
|
|
function update_desktop_name() {
|
|
if [ $# -ne 1 ]; then
|
|
return;
|
|
fi
|
|
local curFileName=$1
|
|
|
|
if [ -f "${curFileName}/.config/user-dirs.dirs" ]; then
|
|
if [ ! $HOME ]; then HOME=${curFileName}; fi
|
|
# Import user dir config
|
|
source "${curFileName}/.config/user-dirs.dirs"
|
|
if [ ! -d "${XDG_DESKTOP_DIR}" ]; then
|
|
mkdir -p "${XDG_DESKTOP_DIR}" >/dev/null 2>&1 || true
|
|
fi
|
|
# Replace(Remove) "${HOME}/" by "" in ${XDG_DESKTOP_DIR} with greedy mode
|
|
gDesktopName="${XDG_DESKTOP_DIR//${HOME}\//}"
|
|
else
|
|
if [ -d "${curFileName}/桌面" ]; then
|
|
gDesktopName="桌面"
|
|
elif [ -d "${curFileName}/Desktop" ]; then
|
|
gDesktopName="Desktop"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
function copy_install_to_desktop() {
|
|
if [ $# -ne 5 ]; then
|
|
return;
|
|
fi
|
|
local curFileName=$1
|
|
local aiDesktopName=$2
|
|
local curUserName=$3
|
|
local initSetup=$4
|
|
local action=$5
|
|
if [ -e "${APP_DATA}/${aiDesktopName}" ]; then
|
|
cp -f ${APP_DATA}/${aiDesktopName} "${curFileName}/${gDesktopName}/"
|
|
if test $? -eq 0; then
|
|
chmod +x "${curFileName}/${gDesktopName}/${aiDesktopName}"
|
|
chown ${curUserName} "${curFileName}/${gDesktopName}/${aiDesktopName}"
|
|
# update init setup info
|
|
echo ${curFileName}/${gDesktopName}/${aiDesktopName} "postinst ${action}" $(date) >> ${initSetup}
|
|
chown ${curUserName} ${initSetup}
|
|
fi
|
|
fi
|
|
}
|
|
|
|
function config_desktop_shortcut() {
|
|
if [ $# -ne 2 ]; then
|
|
return;
|
|
fi
|
|
local curFileName=$1
|
|
local curUserName=$2
|
|
local action="copy" # "update"
|
|
# prepare config dir for application
|
|
local cfgAppDir=${curFileName}/.config/${APP_NAME}/applications
|
|
mkdir -p ${cfgAppDir}
|
|
chown -R ${curUserName} $(dirname ${cfgAppDir})
|
|
# config desktop shortcut
|
|
for desktop in "${aiDesktop[@]}"; do
|
|
local initSetup="${curFileName}/.config/${APP_NAME}/applications/${desktop%.desktop}-initial-setup-done"
|
|
if [ -f ${initSetup} ] && [ "$(cat ${initSetup} | grep ${gDesktopName})" ]; then
|
|
# i.e. desktop is already configured(initial-setup-done)
|
|
#continue
|
|
if [ -e ${curFileName}/${gDesktopName}/${desktop} ]; then
|
|
if cmp -s "${APP_DATA}/${desktop}" "${curFileName}/${gDesktopName}/${desktop}"; then
|
|
# desktop exist and exactly same
|
|
continue
|
|
fi
|
|
# i.e. desktop exist but need to be updated
|
|
action="update"
|
|
else
|
|
# TODO: distinguish shortcut removed by user or `postrm remove`
|
|
: #continue
|
|
fi
|
|
fi
|
|
copy_install_to_desktop ${curFileName} ${desktop} ${curUserName} ${initSetup} ${action}
|
|
done
|
|
}
|
|
|
|
function config_desktop() {
|
|
gDesktopName="桌面"
|
|
if [ -d "/root/桌面" ]; then
|
|
gDesktopName="桌面"
|
|
elif [ -d "/root/Desktop" ]; then
|
|
gDesktopName="Desktop"
|
|
fi
|
|
if [ -d "/root/${gDesktopName}" ]; then
|
|
config_desktop_shortcut "/root" "root"
|
|
fi
|
|
|
|
for FILENAME in /home/*; do
|
|
update_desktop_name ${FILENAME}
|
|
if [ -d "${FILENAME}/${gDesktopName}" ]; then
|
|
config_desktop_shortcut ${FILENAME} "$(echo ${FILENAME} | awk '{print substr($FILENAME, 7, 32)}')"
|
|
fi
|
|
done
|
|
}
|
|
|
|
## ------------------------- ##
|
|
|
|
function postinst_init() {
|
|
export APP_NAME=bianbu-ai-support
|
|
export APP_DATA=/usr/share/applications
|
|
}
|
|
|
|
function postinst_configure() {
|
|
config_desktop
|
|
}
|
|
|
|
function postinst_triggered() {
|
|
for triggername in $1; do
|
|
case "$triggername" in
|
|
*)
|
|
echo "unhandled/unknown trigger!" $triggername
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
}
|
|
|
|
function postinst_main() {
|
|
if [ $# -eq 0 ]; then
|
|
return;
|
|
fi
|
|
|
|
postinst_init
|
|
case $1 in
|
|
configure ) shift; postinst_configure $@;;
|
|
triggered ) shift; postinst_triggered $@;;
|
|
esac
|
|
}
|
|
|
|
args="$@"
|
|
postinst_main $@
|