|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -# Setup rabbit remote control appimage shell script |
| 3 | +# Setup AppImage shell script |
4 | 4 | # Author: Kang Lin <kl222@126.com> |
5 | 5 |
|
6 | 6 | #set -v |
7 | 7 | set -e |
8 | 8 | #set -x |
9 | 9 |
|
10 | | -INSTALL_DIR=~/AppImage/io.github.KangLin.RabbitRemoteControl |
| 10 | +APP_ID=io.github.KangLin.RabbitRemoteControl |
| 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 | + |
11 | 15 | usage_long() { |
12 | 16 | echo "$0 [-h|--help] [--install=<install directory>]" |
13 | 17 | echo " -h|--help: show help" |
14 | 18 | echo "Directory:" |
15 | 19 | echo " --install: Set install directory" |
16 | 20 | exit |
17 | 21 | } |
| 22 | + |
18 | 23 | # [如何使用getopt和getopts命令解析命令行选项和参数](https://zhuanlan.zhihu.com/p/673908518) |
19 | 24 | # [【Linux】Shell命令 getopts/getopt用法详解](https://blog.csdn.net/arpospf/article/details/103381621) |
20 | 25 | if command -V getopt >/dev/null; then |
@@ -61,58 +66,60 @@ if command -V getopt >/dev/null; then |
61 | 66 | done |
62 | 67 | fi |
63 | 68 |
|
64 | | -if [ -f ~/.local/share/applications/io.github.KangLin.RabbitRemoteControl.AppImage.desktop ]; then |
65 | | - OLD_UNINSTALL=$(dirname $(readlink -f ~/.local/share/applications/io.github.KangLin.RabbitRemoteControl.AppImage.desktop)) |
| 69 | +if [ -f $DESKTOP_FILE ]; then |
| 70 | + OLD_UNINSTALL=$(dirname $(readlink -f $DESKTOP_FILE)) |
66 | 71 | if [ -f $OLD_UNINSTALL/uninstall.sh ]; then |
67 | | - echo "" |
| 72 | + #echo "Run $OLD_UNINSTALL/uninstall.sh" |
68 | 73 | $OLD_UNINSTALL/uninstall.sh |
69 | 74 | fi |
70 | 75 | fi |
71 | 76 |
|
72 | 77 | INSTALL_DIR=$(readlink -f $INSTALL_DIR) |
73 | 78 | if [ ! -d $INSTALL_DIR ]; then |
74 | 79 | mkdir -p $INSTALL_DIR |
| 80 | + CREATE_INSTALL_DIR=1 |
75 | 81 | fi |
76 | 82 |
|
77 | 83 | 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 |
80 | 86 | fi |
81 | 87 |
|
82 | 88 | pushd $ROOT_DIR > /dev/null |
83 | 89 |
|
84 | 90 | APPIMAGE_FILE=`ls RabbitRemoteControl_*.AppImage` |
85 | 91 | if [ $INSTALL_DIR != $ROOT_DIR ]; then |
86 | 92 | cp $APPIMAGE_FILE $INSTALL_DIR/$APPIMAGE_FILE |
87 | | - cp io.github.KangLin.RabbitRemoteControl.svg $INSTALL_DIR/io.github.KangLin.RabbitRemoteControl.svg |
88 | | - cp io.github.KangLin.RabbitRemoteControl.desktop $INSTALL_DIR/io.github.KangLin.RabbitRemoteControl.desktop |
| 93 | + cp $APP_ID.svg $INSTALL_DIR/$APP_ID.svg |
| 94 | + cp $APP_ID.desktop $INSTALL_DIR/$APP_ID.desktop |
89 | 95 | fi |
90 | 96 |
|
91 | | -sed -i "s#Exec=.*#Exec=${INSTALL_DIR}/${APPIMAGE_FILE}#g" $INSTALL_DIR/io.github.KangLin.RabbitRemoteControl.desktop |
92 | | -if [ ! -f ~/.local/share/applications/io.github.KangLin.RabbitRemoteControl.AppImage.desktop ]; then |
93 | | - ln -s $INSTALL_DIR/io.github.KangLin.RabbitRemoteControl.desktop ~/.local/share/applications/io.github.KangLin.RabbitRemoteControl.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 |
94 | 106 | fi |
95 | | -if [ ! -d ~/.icons/hicolor/scalable/apps ]; then |
96 | | - mkdir -p ~/.icons/hicolor/scalable/apps |
| 107 | + |
| 108 | +echo "echo \"Uninstall \\\"Rabbit Remote Control\\\" 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 |
97 | 111 | fi |
98 | | -if [ ! -f ~/.icons/hicolor/scalable/apps/io.github.KangLin.RabbitRemoteControl.svg ]; then |
99 | | - ln -s $INSTALL_DIR/io.github.KangLin.RabbitRemoteControl.svg ~/.icons/hicolor/scalable/apps/io.github.KangLin.RabbitRemoteControl.svg |
| 112 | +if [ -n $CREATE_INSTALL_DIR ]; then |
| 113 | + echo "rm -fr $INSTALL_DIR" >> $INSTALL_DIR/uninstall.sh |
100 | 114 | 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.RabbitRemoteControl.AppImage.desktop))\"" > $INSTALL_DIR/uninstall.sh |
105 | | -echo "rm ~/.local/share/applications/io.github.KangLin.RabbitRemoteControl.AppImage.desktop" >> $INSTALL_DIR/uninstall.sh |
106 | | -echo "rm ~/.icons/hicolor/scalable/apps/io.github.KangLin.RabbitRemoteControl.svg" >> $INSTALL_DIR/uninstall.sh |
107 | | -echo "rm -fr $INSTALL_DIR" >> $INSTALL_DIR/uninstall.sh |
108 | 115 | chmod u+x $INSTALL_DIR/uninstall.sh |
109 | 116 | chmod u+x $INSTALL_DIR/$APPIMAGE_FILE |
110 | 117 |
|
111 | 118 | echo "" |
112 | | -echo "Install rabbit remote control AppImage to \"$INSTALL_DIR\"." |
| 119 | +echo "Install \"Rabbit Remote Control\" AppImage to \"$INSTALL_DIR\"." |
113 | 120 | echo "" |
114 | 121 | echo "If you want to uninstall it. Please execute:" |
115 | | -echo " $INSTALL_DIR/unistasll.sh" |
| 122 | +echo " $INSTALL_DIR/uninstall.sh" |
116 | 123 | echo "" |
117 | 124 |
|
118 | 125 | popd > /dev/null |
0 commit comments