Skip to content

Commit 25c8878

Browse files
committed
Script: add install_appimage.sh
1 parent 772e77b commit 25c8878

File tree

3 files changed

+41
-35
lines changed

3 files changed

+41
-35
lines changed

.github/workflows/appimage.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@ jobs:
108108
pushd SetupSerialPortAssistantAppImage
109109
cp ${{github.workspace}}/SerialPortAssistant_${{env.SerialPortAssistant_VERSION}}_Linux_`uname -m`.AppImage .
110110
chmod a+rx SerialPortAssistant_${{env.SerialPortAssistant_VERSION}}_Linux_`uname -m`.AppImage
111-
cp ${{github.workspace}}/Script/install.sh .
111+
cp ${{github.workspace}}/Script/install_appimage.sh install.sh
112112
chmod a+rx install.sh
113+
ls ${{env.BUILD_DIR}}
114+
ls ${{env.BUILD_DIR}}/AppDir/usr/share/
113115
cp ${{env.BUILD_DIR}}/AppDir/usr/share/applications/io.github.KangLin.SerialPortAssistant.desktop .
114116
cp ${{env.BUILD_DIR}}/AppDir/usr/share/icons/hicolor/scalable/apps/io.github.KangLin.SerialPortAssistant.svg .
115117
popd

App/CMakeLists.txt

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,24 +105,21 @@ elseif(UNIX AND NOT ANDROID)
105105
INSTALL(FILES ${CMAKE_BINARY_DIR}/${APP_ID}.desktop
106106
DESTINATION "${CMAKE_INSTALL_DATADIR}/applications"
107107
COMPONENT Application)
108-
INSTALL(PROGRAMS ${CMAKE_SOURCE_DIR}/share/SerialPortAssistant.sh
109-
DESTINATION "${CMAKE_INSTALL_BINDIR}"
110-
COMPONENT Application)
111-
# Icon path
108+
# INSTALL(PROGRAMS ${CMAKE_SOURCE_DIR}/share/SerialPortAssistant.sh
109+
# DESTINATION "${CMAKE_INSTALL_BINDIR}"
110+
# COMPONENT Application)
111+
# Icon path: http://freedesktop.org/wiki/Standards/icon-theme-spec
112112
# The freedesktop.org standard specifies in which order and directories programs should look for icons:
113113
#
114114
# $HOME/.icons (for backwards compatibility)
115115
# $XDG_DATA_DIRS/icons
116116
# /usr/share/pixmaps
117-
INSTALL(FILES ${CMAKE_SOURCE_DIR}/App/Resource/png/SerialPortAssistant.png
118-
DESTINATION share/pixmaps
119-
COMPONENT Application
120-
RENAME ${APP_ID}.png)
121117
# Flatpak: https://docs.flatpak.org/en/latest/conventions.html#application-icons
122118
INSTALL(FILES ${CMAKE_SOURCE_DIR}/App/Resource/png/SerialPortAssistant.png
123-
DESTINATION "${CMAKE_INSTALL_DATADIR}/icons/hicolor/128x128/apps"
119+
DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps
124120
COMPONENT Application
125121
RENAME ${APP_ID}.png)
122+
126123
string(TIMESTAMP BUILD_DATE "%Y-%m-%d")
127124
configure_file(${CMAKE_SOURCE_DIR}/share/metainfo/${APP_ID}.metainfo.xml.in
128125
${CMAKE_BINARY_DIR}/${APP_ID}.metainfo.xml @ONLY)
Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
#!/bin/bash
22

3-
# Setup appimage shell script
3+
# Setup AppImage shell script
44
# Author: Kang Lin <kl222@126.com>
55

66
#set -v
77
set -e
88
#set -x
99

10-
INSTALL_DIR=~/AppImage/io.github.KangLin.SerialPortAssistant
10+
APP_ID=io.github.KangLin.SerialPortAssistant
11+
INSTALL_DIR=$HOME/AppImage/$APP_ID
12+
DESKTOP_FILE_DIR=$HOME/.local/share/applications
13+
DESKTOP_FILE=$DESKTOP_FILE_DIR/$APP_ID.AppImage.desktop
14+
1115
usage_long() {
1216
echo "$0 [-h|--help] [--install=<install directory>]"
1317
echo " -h|--help: show help"
1418
echo "Directory:"
1519
echo " --install: Set install directory"
1620
exit
1721
}
22+
1823
# [如何使用getopt和getopts命令解析命令行选项和参数](https://zhuanlan.zhihu.com/p/673908518)
1924
# [【Linux】Shell命令 getopts/getopt用法详解](https://blog.csdn.net/arpospf/article/details/103381621)
2025
if command -V getopt >/dev/null; then
@@ -61,58 +66,60 @@ if command -V getopt >/dev/null; then
6166
done
6267
fi
6368

64-
if [ -f ~/.local/share/applications/io.github.KangLin.SerialPortAssistant.AppImage.desktop ]; then
65-
OLD_UNINSTALL=$(dirname $(readlink -f ~/.local/share/applications/io.github.KangLin.SerialPortAssistant.AppImage.desktop))
69+
if [ -f $DESKTOP_FILE ]; then
70+
OLD_UNINSTALL=$(dirname $(readlink -f $DESKTOP_FILE))
6671
if [ -f $OLD_UNINSTALL/uninstall.sh ]; then
67-
echo ""
72+
#echo "Run $OLD_UNINSTALL/uninstall.sh"
6873
$OLD_UNINSTALL/uninstall.sh
6974
fi
7075
fi
7176

7277
INSTALL_DIR=$(readlink -f $INSTALL_DIR)
7378
if [ ! -d $INSTALL_DIR ]; then
7479
mkdir -p $INSTALL_DIR
80+
CREATE_INSTALL_DIR=1
7581
fi
7682

7783
ROOT_DIR=$(dirname $(readlink -f $0))
78-
if [ ! -d /usr/share/icons/hicolor/scalable/apps ]; then
79-
mkdir -p /usr/share/icons/hicolor/scalable/apps
84+
if [ ! -d $DESKTOP_FILE_DIR ]; then
85+
mkdir -p $DESKTOP_FILE_DIR
8086
fi
8187

8288
pushd $ROOT_DIR > /dev/null
8389

8490
APPIMAGE_FILE=`ls SerialPortAssistant_*.AppImage`
8591
if [ $INSTALL_DIR != $ROOT_DIR ]; then
8692
cp $APPIMAGE_FILE $INSTALL_DIR/$APPIMAGE_FILE
87-
cp io.github.KangLin.SerialPortAssistant.svg $INSTALL_DIR/io.github.KangLin.SerialPortAssistant.svg
88-
cp io.github.KangLin.SerialPortAssistant.desktop $INSTALL_DIR/io.github.KangLin.SerialPortAssistant.desktop
93+
cp $APP_ID.svg $INSTALL_DIR/$APP_ID.svg
94+
cp $APP_ID.desktop $INSTALL_DIR/$APP_ID.desktop
8995
fi
9096

91-
sed -i "s#Exec=.*#Exec=${INSTALL_DIR}/${APPIMAGE_FILE}#g" $INSTALL_DIR/io.github.KangLin.SerialPortAssistant.desktop
92-
if [ ! -f ~/.local/share/applications/io.github.KangLin.SerialPortAssistant.AppImage.desktop ]; then
93-
ln -s $INSTALL_DIR/io.github.KangLin.SerialPortAssistant.desktop ~/.local/share/applications/io.github.KangLin.SerialPortAssistant.AppImage.desktop
97+
# 修改执行文件
98+
sed -i "s#Exec=.*#Exec=${APPIMAGE_FILE}#g" $INSTALL_DIR/$APP_ID.desktop
99+
# 修改路径
100+
sed -i "s#Path=.*#Path=${INSTALL_DIR}#g" $INSTALL_DIR/$APP_ID.desktop
101+
if [ ! -f $DESKTOP_FILE ]; then
102+
CREATE_DESKTOP_FILE=1
103+
ln -s ${INSTALL_DIR}/$APP_ID.desktop $DESKTOP_FILE
104+
# ICON 使用绝对路径。因为已修改了 Path,所以此处可以不用修改
105+
#sed -i "s#^Icon=.*#Icon=$INSTALL_DIR/$APP_ID.svg#" $INSTALL_DIR/$APP_ID.desktop
94106
fi
95-
if [ ! -d ~/.icons/hicolor/scalable/apps ]; then
96-
mkdir -p ~/.icons/hicolor/scalable/apps
107+
108+
echo "echo \"Uninstall \\\"Serial Port Assistant\\\" AppImage from \\\"$(dirname $(readlink -f $DESKTOP_FILE))\\\"\"" > $INSTALL_DIR/uninstall.sh
109+
if [ -n $CREATE_DESKTOP_FILE ]; then
110+
echo "rm $DESKTOP_FILE" >> $INSTALL_DIR/uninstall.sh
97111
fi
98-
if [ ! -f ~/.icons/hicolor/scalable/apps/io.github.KangLin.SerialPortAssistant.svg ]; then
99-
ln -s $INSTALL_DIR/io.github.KangLin.SerialPortAssistant.svg ~/.icons/hicolor/scalable/apps/io.github.KangLin.SerialPortAssistant.svg
112+
if [ -n $CREATE_INSTALL_DIR ]; then
113+
echo "rm -fr $INSTALL_DIR" >> $INSTALL_DIR/uninstall.sh
100114
fi
101-
102-
update-desktop-database ~/.local/share/applications
103-
104-
echo "echo \"Uninstall rabbit remote control in $(dirname $(readlink -f ~/.local/share/applications/io.github.KangLin.SerialPortAssistant.AppImage.desktop))\"" > $INSTALL_DIR/uninstall.sh
105-
echo "rm ~/.local/share/applications/io.github.KangLin.SerialPortAssistant.AppImage.desktop" >> $INSTALL_DIR/uninstall.sh
106-
echo "rm ~/.icons/hicolor/scalable/apps/io.github.KangLin.SerialPortAssistant.svg" >> $INSTALL_DIR/uninstall.sh
107-
echo "rm -fr $INSTALL_DIR" >> $INSTALL_DIR/uninstall.sh
108115
chmod u+x $INSTALL_DIR/uninstall.sh
109116
chmod u+x $INSTALL_DIR/$APPIMAGE_FILE
110117

111118
echo ""
112-
echo "Install rabbit remote control AppImage to \"$INSTALL_DIR\"."
119+
echo "Install \"Serial Port Assistant\" AppImage to \"$INSTALL_DIR\"."
113120
echo ""
114121
echo "If you want to uninstall it. Please execute:"
115-
echo " $INSTALL_DIR/unistasll.sh"
122+
echo " $INSTALL_DIR/uninstall.sh"
116123
echo ""
117124

118125
popd > /dev/null

0 commit comments

Comments
 (0)