Logseq-Installer/logseq-install.sh

179 lines
4.7 KiB
Bash
Raw Permalink Normal View History

2022-08-18 20:07:21 +02:00
#!/bin/bash -e
2022-08-14 22:12:09 +02:00
2022-08-18 20:07:21 +02:00
COLOR_RED=$( tput setaf 1 )
COLOR_GREEN=$( tput setaf 2 )
COLOR_YELLOW=$( tput setaf 3 )
COLOR_RESET=$( tput sgr0 )
ALLOW_ROOT=false
2022-08-18 20:07:21 +02:00
trap 'handleError' ERR
handleError() {
cat <<-EOT
Leider ist ein Fehler aufgetreten.
Bitte hilf mit dieses Skript zu verbessern und sende einen
Fehlerbericht per EMail an installer@logseq.eu
EOT
}
2022-08-14 22:12:09 +02:00
err() {
echo "${COLOR_RED}$*${COLOR_RESET}"
exit 1
}
2022-08-14 22:12:09 +02:00
showLogo() {
echo -n "${COLOR_GREEN}"
cat <<-'EOT'
.____
| | ____ ____ ______ ____ ______
| | / _ \ / ___\/ ___// __ \/ ____/
| |__( <_> ) /_/ >___ \\ ___< <_| |
|_______ \____/\___ /____ >\___ >__ |
\/ /_____/ \/ \/ |__|
EOT
echo -n "${COLOR_YELLOW}"
cat <<-'EOT'
.___ __ .__ .__
| | ____ _______/ |______ | | | | ___________
| |/ \ / ___/\ __\__ \ | | | | _/ __ \_ __ \
| | | \\___ \ | | / __ \| |_| |_\ ___/| | \/
|___|___| /____ > |__| (____ /____/____/\___ >__|
\/ \/ \/ \/
EOT
echo -n "${COLOR_RESET}"
}
showHelp() {
[ $# -gt 0 ] && echo "$*" && echo ""
cat <<-EOT
Logseq Installer
================
Erlaubte Optionen:
-h | --hilfe --- Zeigt diese Hilfe an
-e | --entfernen --- Deinstalliert Logseq
-r | --root --- Erlaubt die Installation als root
Geschrieben von Tim Peters
---> https://git.tim-peters.org/Tim/Logseq-Installer
EOT
exit 1
}
2022-08-14 22:12:09 +02:00
getVersionLatest() {
VERSION_LATEST="$( wget -qO - https://github.com/logseq/logseq/releases/latest | grep -Poi "releases/tag/\K\d+\.\d+\.\d+" | head -n 1 )"
[ -n "$VERSION_LATEST" ] || err "Konnte nicht ermittelt werden"
2022-08-14 22:12:09 +02:00
}
getVersionCurrent() {
2022-08-18 20:07:21 +02:00
local FILENAME
FILENAME="$( ls -1rt ~/.local/bin/Logseq-*AppImage 2>/dev/null | head -n1 )"
2022-08-14 22:12:09 +02:00
if [ -n "$FILENAME" ]; then
VERSION_CURRENT="$( echo "$FILENAME" | grep -Poi "Logseq-linux-x64-\K\d+\.\d+\.\d+" | head -n 1 )"
2022-08-14 22:12:09 +02:00
else
VERSION_CURRENT=
fi
[ -n "$VERSION_CURRENT" ] || err "Konnte nicht ermittelt werden"
2022-08-14 22:12:09 +02:00
}
getLatest() {
2022-08-18 20:07:21 +02:00
local URL
URL="https://github.com/logseq/logseq/releases/download/$VERSION_LATEST/Logseq-linux-x64-$VERSION_LATEST.AppImage"
2022-08-18 20:07:21 +02:00
local DIR_DEST
DIR_DEST=~/.local/bin
local FILE_LINK
FILE_LINK=~/.local/bin/Logseq
local FILE_TMP
FILE_TMP="$( mktemp )"
local FILE_DELETE
2022-08-14 22:12:09 +02:00
FILENAME_LOGSEQ="$( basename "$URL" )"
mkdir -p $DIR_DEST
2022-08-18 20:07:21 +02:00
wget "$URL" --show-progress -qO "$FILE_TMP"
mv "$FILE_TMP" "$DIR_DEST/$FILENAME_LOGSEQ"
chmod u+x "$DIR_DEST/$FILENAME_LOGSEQ"
2022-08-14 23:39:45 +02:00
# Veraltete Versionen löschen
2022-08-18 20:07:21 +02:00
FILE_DELETE="$( find ~/.local/bin -iname Logseq-\*AppImage | grep -v "$FILENAME_LOGSEQ" )" || true
[ -n "$FILE_DELETE" ] && rm -f "$FILE_DELETE"
[ -L "$FILE_LINK" ] && rm -f "$FILE_LINK"
ln -s "$DIR_DEST/$FILENAME_LOGSEQ" "$FILE_LINK"
2022-08-14 22:12:09 +02:00
}
doUninstall() {
rm -f ~/.local/bin/Logseq* "${HOME}"/.local/share/applications/logseq.*
update-desktop-database ~/.local/share/applications
echo "Logseq wurde deinstalliert"
exit
}
2022-08-14 22:12:09 +02:00
createDesktop() {
2022-08-14 22:46:38 +02:00
local FILE_PNG=${HOME}/.local/share/applications/logseq.png
2022-08-18 20:07:21 +02:00
[ -f "$FILE_PNG" ] || wget https://raw.githubusercontent.com/logseq/logseq/master/resources/icons/logseq.png -qO "$FILE_PNG"
2022-08-14 22:12:09 +02:00
2022-08-14 22:46:38 +02:00
cat > ~/.local/share/applications/logseq.desktop <<-EOF
2022-08-14 22:12:09 +02:00
[Desktop Entry]
Encoding=UTF-8
Name=Logseq
Comment=Wissensmanagement mit Logseq
Exec=${HOME}/.local/bin/$FILENAME_LOGSEQ
Icon=${HOME}/.local/share/applications/logseq.png
Type=Application
Categories=Office;
X-GNOME-SingleWindow=true
SingleMainWindow=true
EOF
2022-08-15 19:49:33 +02:00
update-desktop-database ~/.local/share/applications
2022-08-14 22:12:09 +02:00
}
optspec=":her-:"
while getopts "${optspec}" OPT; do
[ "${OPT}" = " " ] && continue
if [ "${OPT}" = "-" ]; then
OPT="${OPTARG%%=*}"
OPTARG="${OPTARG#$OPT}"
OPTARG="${OPTARG#=}"
fi
case "${OPT}" in
h | hilfe ) showHelp ;;
e | entfernen ) doUninstall ;;
r | root ) ALLOW_ROOT=true ;;
[^\?]* ) showHelp "Unbekannte Option: --${OPT}"; exit 2 ;;
\? ) showHelp "Unbekannte Option: -${OPTARG}"; exit 2 ;;
esac
done
shift $((OPTIND-1))
if [ "$( whoami )" = root -a "$ALLOW_ROOT" = false ]; then
showHelp "Die Installation sollte nicht als root erfolgen"
exit 1
fi
2022-08-14 22:12:09 +02:00
showLogo
2022-08-18 20:07:21 +02:00
echo "Ermitteln der verfügbaren Versionen"
2022-08-14 22:12:09 +02:00
getVersionLatest
getVersionCurrent
echo "Neuste verfügbare Version...... $COLOR_GREEN$VERSION_LATEST$COLOR_RESET"
2022-08-18 20:07:21 +02:00
echo "Derzeit installierte Version... $COLOR_GREEN${VERSION_CURRENT:-${COLOR_RED}Logseq ist nicht installiert}$COLOR_RESET"
2022-08-14 22:12:09 +02:00
[ "$VERSION_CURRENT" != "$VERSION_LATEST" ] || exit
if [ "$( pgrep -ifcx ~/.local/bin/Logseq )" -ne 0 ]; then
err "Logseq sollte erst geschlossen werden, bevor das Update eingespielt wird"
fi
2022-08-14 22:12:09 +02:00
echo "Logseq Download gestartet"
getLatest
createDesktop
echo "Logseq wurde installiert"