首先描述下我的环境, 喜欢折腾着玩,所以我的电脑上装了3个系统,分别是ubuntu22.04, opensuse 15.5, manjora 三个操作系统,平时基本上换着用。这3个系统分别使用独立的根分区/ 和 /root分区, 但挂载同一个数据分区 /u01(存放数据文件和软件等)
这3个操作系统上都装上了我平时经常使用的软件,像libreoffice,typora等。
之前, 需要分别在ubuntu上安装软件的deb版本, 在opensuse上安装软件的rpm版本, 在manjaro上安装软件的二进制版本。
后来发现很多linux软件有appimage版本,不需安装就能运行。 例如 navicat , 也有的软件只要解压就可以运行,例如 idea。
所以, 我就开始摒弃rpm/deb 版本 ,转而下载appimage和二进制压缩包了, 这样只要在 /usr/share/applications 中按照格式创建 .desktop文件,开始菜单中就有对应的图标了,打开就是执行,非常方便。
这样就不用分别为3个系统安装deb/rpm/binary包了。 只需要写好脚本,安装完操作系统,运行下脚本,分别为软件创建.desktop就行了。
大部分.desktop文件是大同小异,主要的就2项,一个是程序的路径, 一个是程序的图标。为了和rpm/deb安装效果一样, 我参考了rpm/deb安装生成的 .desktop文件内容, 并从appimage中提取了原版的图标。写下了下面的创建脚本, 供大家参考。
分三部分,分别是libreoffice, appimage软件, 二进制压缩包软件。
libreoffice软件包含了writer,calc,math,impress ,base,draw等等, 分别对应office中的word,excel,powerpoint ,access,viso 等软件。还有math(公式编辑器) 没有对应的office产品,libreoffice相当于入口。所以一共要创建7个快捷方式。
写法稍微复杂,单独列出来。ubuntu22.04/opensuse 15.5 /manjaro均测试通过
#libreoffice
cat > /usr/share/applications/libreoffice-startcenter.desktop <<EOF
[Desktop Entry]
Version=7.5.2.2
Terminal=false
NoDisplay=false
Icon=libreoffice-startcenter
Type=Application
Categories=Office;X-Red-Hat-Base;X-SuSE-Core-Office;X-MandrivaLinux-Office-Other;
Exec=/u01/3.software/3.crossplatfrom/office/LibreOffice-7.5.2.2.standard-x86_64.AppImage %U
MimeType=application/vnd.openofficeorg.extension;x-scheme-handler/vnd.libreoffice.cmis;x-scheme-handler/vnd.sun.star.webdav;x-scheme-handler/vnd.sun.star.webdavs;x-scheme-handler/vnd.libreoffice.command;x-scheme-handler/ms-word;x-scheme-handler/ms-powerpoint;x-scheme-handler/ms-excel;x-scheme-handler/ms-visio;x-scheme-handler/ms-access;
Name=LibreOffice
GenericName=Office
Comment=The office productivity suite compatible to the open and standardized ODF document format. Supported by The Document Foundation.
StartupNotify=true
X-GIO-NoFuse=true
StartupWMClass=libreoffice-startcenter
X-KDE-Protocols=file,http,ftp,webdav,webdavs
X-AppStream-Ignore=True
Actions=Writer;Calc;Impress;Draw;Base;Math;
[Desktop Action Writer]
Name=Writer
Exec=libreoffice --writer
[Desktop Action Calc]
Name=Calc
Exec=libreoffice --calc
[Desktop Action Impress]
Name=Impress
Exec=libreoffice --impress
[Desktop Action Draw]
Name=Draw
Exec=libreoffice --draw
[Desktop Action Base]
Name=Base
Exec=libreoffice --base
[Desktop Action Math]
Name=Math
Exec=libreoffice --math
EOF
cat > /usr/share/applications/libreoffice-writer.desktop <<EOF
[Desktop Entry]
Version=7.5.2.2
Terminal=false
Icon=libreoffice-writer
Type=Application
Categories=Office;WordProcessor;
Exec=/u01/3.software/3.crossplatfrom/office/LibreOffice-7.5.2.2.standard-x86_64.AppImage --writer %U
MimeType=application/vnd.oasis.opendocument.text;application/vnd.oasis.opendocument.text-template;application/vnd.oasis.opendocument.text-web;application/vnd.oasis.opendocument.text-master;application/vnd.oasis.opendocument.text-master-template;application/vnd.sun.xml.writer;application/vnd.sun.xml.writer.template;application/vnd.sun.xml.writer.global;application/msword;application/vnd.ms-word;application/x-doc;application/x-hwp;application/rtf;text/rtf;application/vnd.wordperfect;application/wordperfect;application/vnd.lotus-wordpro;application/vnd.openxmlformats-officedocument.wordprocessingml.document;application/vnd.ms-word.document.macroEnabled.12;application/vnd.openxmlformats-officedocument.wordprocessingml.template;application/vnd.ms-word.template.macroEnabled.12;application/vnd.ms-works;application/vnd.stardivision.writer-global;application/x-extension-txt;application/x-t602;text/plain;application/vnd.oasis.opendocument.text-flat-xml;application/x-fictionbook+xml;application/macwriteii;application/x-aportisdoc;application/prs.plucker;application/vnd.palm;application/clarisworks;application/x-sony-bbeb;application/x-abiword;application/x-iwork-pages-sffpages;application/x-mswrite;application/x-starwriter;
Name=LibreOffice Writer
GenericName=Word Processor
Comment=Create and edit text and graphics in letters, reports, documents and Web pages by using Writer.
StartupNotify=true
X-GIO-NoFuse=true
Keywords=Text;Letter;Fax;Document;OpenDocument Text;Microsoft Word;Microsoft Works;Lotus WordPro;OpenOffice Writer;CV;odt;doc;docx;rtf;
InitialPreference=5
StartupWMClass=libreoffice-writer
X-KDE-Protocols=file,http,ftp,webdav,webdavs
Actions=NewDocument;
[Desktop Action NewDocument]
Name=New Document
Icon=document-new
Exec=libreoffice --writer
EOF
cat > /usr/share/applications/libreoffice-calc.desktop <<EOF
[Desktop Entry]
Version=7.5.2.2
Terminal=false
Icon=libreoffice-calc
Type=Application
Categories=Office;Spreadsheet;
Exec=/u01/3.software/3.crossplatfrom/office/LibreOffice-7.5.2.2.standard-x86_64.AppImage --calc %U
MimeType=application/vnd.oasis.opendocument.spreadsheet;application/vnd.oasis.opendocument.spreadsheet-template;application/vnd.sun.xml.calc;application/vnd.sun.xml.calc.template;application/msexcel;application/vnd.ms-excel;application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;application/vnd.ms-excel.sheet.macroEnabled.12;application/vnd.openxmlformats-officedocument.spreadsheetml.template;application/vnd.ms-excel.template.macroEnabled.12;application/vnd.ms-excel.sheet.binary.macroEnabled.12;text/csv;application/x-dbf;text/spreadsheet;application/csv;application/excel;application/tab-separated-values;application/vnd.lotus-1-2-3;application/vnd.oasis.opendocument.chart;application/vnd.oasis.opendocument.chart-template;application/x-dbase;application/x-dos_ms_excel;application/x-excel;application/x-msexcel;application/x-ms-excel;application/x-quattropro;application/x-123;text/comma-separated-values;text/tab-separated-values;text/x-comma-separated-values;text/x-csv;application/vnd.oasis.opendocument.spreadsheet-flat-xml;application/vnd.ms-works;application/clarisworks;application/x-iwork-numbers-sffnumbers;application/x-starcalc;
Name=LibreOffice Calc
GenericName=Spreadsheet
Comment=Perform calculations, analyze information and manage lists in spreadsheets by using Calc.
StartupNotify=true
X-GIO-NoFuse=true
Keywords=Accounting;Stats;OpenDocument Spreadsheet;Chart;Microsoft Excel;Microsoft Works;OpenOffice Calc;ods;xls;xlsx;
InitialPreference=5
StartupWMClass=libreoffice-calc
X-KDE-Protocols=file,http,ftp,webdav,webdavs
Actions=NewDocument;
[Desktop Action NewDocument]
Name=New Spreadsheet
Icon=document-new
Exec=libreoffice --calc
EOF
cat > /usr/share/applications/libreoffice-impress.desktop <<EOF
[Desktop Entry]
Version=7.5.2.2
Terminal=false
Icon=libreoffice-impress
Type=Application
Categories=Office;Presentation;
Exec=/u01/3.software/3.crossplatfrom/office/LibreOffice-7.5.2.2.standard-x86_64.AppImage --impress %U
MimeType=application/vnd.oasis.opendocument.presentation;application/vnd.oasis.opendocument.presentation-template;application/vnd.sun.xml.impress;application/vnd.sun.xml.impress.template;application/mspowerpoint;application/vnd.ms-powerpoint;application/vnd.openxmlformats-officedocument.presentationml.presentation;application/vnd.ms-powerpoint.presentation.macroEnabled.12;application/vnd.openxmlformats-officedocument.presentationml.template;application/vnd.ms-powerpoint.template.macroEnabled.12;application/vnd.openxmlformats-officedocument.presentationml.slide;application/vnd.openxmlformats-officedocument.presentationml.slideshow;application/vnd.ms-powerpoint.slideshow.macroEnabled.12;application/vnd.oasis.opendocument.presentation-flat-xml;application/x-iwork-keynote-sffkey;
Name=LibreOffice Impress
GenericName=Presentation
Comment=Create and edit presentations for slideshows, meeting and Web pages by using Impress.
StartupNotify=true
X-GIO-NoFuse=true
Keywords=Slideshow;Slides;OpenDocument Presentation;Microsoft PowerPoint;Microsoft Works;OpenOffice Impress;odp;ppt;pptx;
InitialPreference=5
StartupWMClass=libreoffice-impress
X-KDE-Protocols=file,http,ftp,webdav,webdavs
Actions=NewDocument;
[Desktop Action NewDocument]
Name=New Presentation
Icon=document-new
Exec=libreoffice --impress
EOF
cat > /usr/share/applications/libreoffice-draw.desktop <<EOF
[Desktop Entry]
Version=7.5.2.2
Terminal=false
Icon=libreoffice-draw
Type=Application
Categories=Office;FlowChart;Graphics;2DGraphics;VectorGraphics;
Exec=/u01/3.software/3.crossplatfrom/office/LibreOffice-7.5.2.2.standard-x86_64.AppImage --draw %U
MimeType=application/vnd.oasis.opendocument.graphics;application/vnd.oasis.opendocument.graphics-flat-xml;application/vnd.oasis.opendocument.graphics-template;application/vnd.sun.xml.draw;application/vnd.sun.xml.draw.template;application/vnd.visio;application/x-wpg;application/vnd.corel-draw;application/vnd.ms-publisher;image/x-freehand;application/clarisworks;application/x-pagemaker;application/pdf;application/x-stardraw;image/x-emf;image/x-wmf;
Name=LibreOffice Draw
GenericName=Drawing Program
Comment=Create and edit drawings, flow charts and logos by using Draw.
StartupNotify=true
X-GIO-NoFuse=true
Keywords=Vector;Schema;Diagram;Layout;OpenDocument Graphics;Microsoft Publisher;Microsoft Visio;Corel Draw;cdr;odg;svg;pdf;vsd;
InitialPreference=5
StartupWMClass=libreoffice-draw
X-KDE-Protocols=file,http,ftp,webdav,webdavs
Actions=NewDocument;
[Desktop Action NewDocument]
Name=New Drawing
Icon=document-new
Exec=libreoffice --draw
EOF
cat > /usr/share/applications/libreoffice-base.desktop <<EOF
[Desktop Entry]
Version=7.5.2.2
Terminal=false
Icon=libreoffice-base
Type=Application
Categories=Office;Database;
Exec=/u01/3.software/3.crossplatfrom/office/LibreOffice-7.5.2.2.standard-x86_64.AppImage --base %U
MimeType=application/vnd.oasis.opendocument.database;application/vnd.sun.xml.base;
Name=LibreOffice Base
GenericName=Database Development
Comment=Manage databases, create queries and reports to track and manage your information by using Base.
StartupNotify=true
X-GIO-NoFuse=true
Keywords=Data;SQL;
InitialPreference=5
StartupWMClass=libreoffice-base
X-KDE-Protocols=file,http,ftp,webdav,webdavs
Actions=NewDocument;
[Desktop Action NewDocument]
Name=New Database
Icon=document-new
Exec=libreoffice --base
EOF
cat > /usr/share/applications/libreoffice-math.desktop <<EOF
[Desktop Entry]
Version=7.5.2.2
Terminal=false
NoDisplay=false
Icon=libreoffice-math
Type=Application
Categories=Office;Math;
Exec=/u01/3.software/3.crossplatfrom/office/LibreOffice-7.5.2.2.standard-x86_64.AppImage --math %U
MimeType=application/vnd.oasis.opendocument.formula;application/vnd.sun.xml.math;application/vnd.oasis.opendocument.formula-template;text/mathml;application/mathml+xml;
Name=LibreOffice Math
GenericName=Formula Editor
Comment=Create and edit scientific formulas and equations by using Math.
StartupNotify=true
X-GIO-NoFuse=true
Keywords=Equation;OpenDocument Formula;Formula;odf;MathML;
InitialPreference=5
StartupWMClass=libreoffice-math
X-KDE-Protocols=file,http,ftp,webdav,webdavs
Actions=NewDocument;
[Desktop Action NewDocument]
Name=New Formula
Icon=document-new
Exec=libreoffice --math
EOF