Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # https://discourse.joplin.cozic.net/
- # "I didn't get rid of the Hydra by smiling at them."
- # -- Kara Danvers
- # OS:
- # Tested ver. 1.0.120 on Ubuntu 16
- # Might also work on other Linux distributions
- # Feature:
- # 1. Install Joplin desktop by one command,
- # basically wrapping the official install script
- # 2. Kill the running Joplin desktop before installation.
- # 3. Backup the Joplin desktop db to the default directory.
- # 4. Create links to the Joplin desktop with version info
- # (unavailable for versions perhaps before 1.0.110)
- # Usage:
- # 1. Manually run the command as non-root
- # ./joplink_desk_ins.bash
- # A temporary file of "joplin_install_and_update.bash"
- # will be created in the /tmp dir.
- # To change this path, modify the value of DPATH_TMP.
- # 2. By default, the backup of note data will be copied
- # to the predefined path of ~/joplin_db_bak
- # To change this path,
- # modify the value of DPATH_BAK.
- # To disable the note backup,
- # comment out the line of DPATH_BAK=
- # 3. To diable making links,
- # comment out the line of DPATH_JOPLIN_DESK_APP=
- # 4. Write your own functions and put them in the main function
- # when you need to extend the script
- # Or you can modify the script at your own will
- # 5. To run the script by cron job as non-root user (required),
- # try something like this:
- # 2 12 * * * sudo -u username "/path/to/joplin_desk_ins.bash"
- # then to update the joplin automatically
- # Caution:
- # The script might be buggy
- # so backup your data first
- # and use the script at your own risks
- SET_DEFAULT_VALUES(){
- ## Paths for original data file
- JOPLIN_DESK_CONF_DIRNAME="joplin-desktop"
- DPATH_CONF=~/.config/"$JOPLIN_DESK_CONF_DIRNAME"
- FPATH_DATA="$DPATH_CONF"/database.sqlite
- ## Paths for backup files
- # Set the path for the backup dir you prefer
- # with proper permissions
- # Comment out DPATH_BAK= to disable backup of data
- DPATH_BAK=~/joplin_db_bak
- ## Path for temporary files
- DPATH_TMP=/tmp
- ## Paths for link files
- # Comment out DPATH_JOPLIN_DESK_APP= to disable making links
- DPATH_JOPLIN_DESK_APP=~/.joplin
- JOPLIN_APPNAME="Joplin.AppImage"
- # BINPATH_HOME is used to hold bin files or joplin link
- # with proper permissions of the $HOME user
- # and should be in the PATH of ~/profile
- # Leave it commented out if it's not needed
- # BINPATH_HOME="~/bin"
- }
- get_datetime(){
- datef=`date '+%Y%m%dT%H%M%S'`
- echo "$datef"
- }
- is_unused_path(){
- fpath="$1"
- [ "y" == "y$fpath" ] && return 1
- [ -e "$fpath" ] && return 64
- [ -h "$fpath" ] && return 65
- return 0
- }
- mkdir_chk(){
- dpath="$1"
- is_unused_path "$dpath"
- retval=$?
- [ 1 -le $retval ] && return 1
- mkdir "$dpath"
- }
- init(){
- SET_DEFAULT_VALUES
- mkdir_chk "$DPATH_BAK"
- mkdir_chk "$BINPATH_HOME"
- }
- backup_sqlite(){
- [ ! -d "$DPATH_BAK" ] && return 1
- fpath_data_bak="$DPATH_BAK"/database.sqlite.$(get_datetime)
- cp "$FPATH_DATA" "$fpath_data_bak"
- }
- kill_app(){
- # Don't kill the ppid of Joplin.AppImage
- # It would crash the Gnome Desktop
- pid_img=$(pidof Joplin.AppImage)
- pid_jopl=$(pidof joplin)
- if [ -n "$pid_img" -o -n "$pid_jopl" ]
- then
- echo "Joplin is running. Killing it now.."
- [ -n "$pid_img" ] && kill $pid_img
- [ -n "$pid_jopl" ] && kill $pid_jopl
- fi
- }
- install(){
- if [ ! -d "$DPATH_TMP" ]
- then
- echo "ERR:: DPATH_TMP: Invalid Path: $DPATH_TMP"
- echo "ERR:: Installation is aborted"
- return 1
- fi
- fpath="$DPATH_TMP"/joplin_install_and_update.bash
- # On Linux, if it works with your distribution
- # (it has been tested on Ubuntu, Fedora, Gnome and Mint),
- # the recommended way is to use this script
- # as it will handle the desktop icon too:
- url="https://raw.githubusercontent.com/laurent22/joplin/master/Joplin_install_and_update.sh"
- wget -O "$fpath" "$url"
- chmod u+x "$fpath"
- bash "$fpath"
- }
- rm_chk(){
- fpath="$1"
- is_unused_path "$fpath"
- retval=$?
- [ 1 -ge $retval ] && return 1
- rm "$fpath"
- }
- mklink_binhome(){
- fpath_joplin_app_link="$1"
- [ ! -d "$BINPATH_HOME" ] && return 1
- fpath_binhome_link="$BINPATH_HOME"/joplin-desk
- rm_chk "$fpath_binhome_link"
- ln -s "$fpath_joplin_app_link" "$fpath_binhome_link"
- }
- mklink(){
- [ ! -d "$DPATH_JOPLIN_DESK_APP" ] && return 1
- fpath_ver="$DPATH_JOPLIN_DESK_APP"/VERSION
- if [ ! -f "$fpath_ver" ]
- then
- echo "INFO:: fpath_ver: Invalid Path: $fpath_ver"
- echo "INFO:: The making of links is disabled."
- return 1
- fi
- # Make a link with version number under the joplin home path
- ver=`cat "$fpath_ver"`
- fpath_joplin_app="$DPATH_JOPLIN_DESK_APP"/"$JOPLIN_APPNAME"
- fpath_joplin_app_link="$DPATH_JOPLIN_DESK_APP"/"$JOPLIN_APPNAME"-desk-$ver
- rm_chk "$fpath_joplin_app_link"
- ln -s "$fpath_joplin_app" "$fpath_joplin_app_link"
- mklink_binhome "$fpath_joplin_app_link"
- }
- main(){
- init
- backup_sqlite
- kill_app
- install
- mklink
- }
- main "$@"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement