You are not logged in.

#1 2020-11-16 02:00:02

MountainX
Member
Registered: 2016-02-08
Posts: 262

PKGBUILD request: Zoho WorkDrive Sync for Desktop

We have this in the AUR: AUR (en) - zoho-docs-bin

Zoho WorkDrive Sync for Desktop is for teams. Zoho Docs syncs only the files for a single account.

Is anyone already using Zoho WorkDrive Sync for Desktop and has a PKGBUILD to share? Otherwise, I will start taking a look at making one...

The tar.gz from the download link contains a setup executable that is a combination of a bash script and an embedded archive. Are those difficult to make a package out of?

EDIT: here's the workdrive setup script. How would I start making this into a PKGBUILD?

#!/bin/bash
# workdrive setup script
#--------------------------------------------------------------------------------------------------------
function display_error(){
    zenity --error --title="Zoho WorkDrive Setup" --text="$*" || xmessage -center -title "Zoho WorkDrive Setup" -geometry 400x100 "$1" || return 1  
    return 0
}
#--------------------------------------------------------------------------------------------------------
function init_vars(){
    ZSYNC_VER='2.5.20'
    BIN_ARCH='x86_64'
    UNINSTALL=false
    REINSTALL=false
    if [[ ${1} = "-UNINSTALL" ]]; then
        UNINSTALL=true
    fi
    SRCPATH=$(dirname $(readlink -f $0))
    CONFPATH="$HOME/.zohoworkdrive"
    OLDCONFPATH="$HOME/.zohoteamdrive"
    BINPATH="$CONFPATH/bin"
    VERSION="$BINPATH/.version"
    LOCAL_PATH="$HOME/.local/"
    mkdir -p $LOCAL_PATH || _abort "error while creating local folder"
}
#--------------------------------------------------------------------------------------------------------
function check_arch(){

    sys_arch=`uname -m` || return 1
    if [[ ${sys_arch: -2} -eq "64" && ${BIN_ARCH: -2} -eq "64" ]]; then
        return 0
    elif [[ ${sys_arch: -2} -eq '86' && ${BIN_ARCH: -2} -eq '86' ]]; then
        return 0
    else
        display_error "OS Architecture not supported. Please download" "$sys_arch" "bit setup of Zoho WorkDrive to install"
        return 1
    fi    
}
#--------------------------------------------------------------------------------------------------------
function check_ver(){

    if [ -e $VERSION  ]; then
        OLD_VER=$(cat $VERSION)
        REINSTALL=true
    else
        OLD_VER=0.0
    fi
    old_ver_arr=(${OLD_VER//./ })
    old_ver_arr_len=${#old_ver_arr[@]}
    ver_arr=(${ZSYNC_VER//./ })
    ver_arr_len=${#ver_arr[@]}
    for((i=0;i<$old_ver_arr_len;i++))
    do
        if [[ ${old_ver_arr[$i]} -eq "" ]]; then
            return 0
        fi
        
        if [[ ${ver_arr[$i]} -eq "" ]]; then
            return 1
        fi

        if [[ ${ver_arr[$i]} -gt ${old_ver_arr[$i]} ]]; then
            return 0
        elif [[ ${ver_arr[$i]} -lt ${old_ver_arr[$i]} ]]; then
            return 1
        fi

    done
    return 0 # return true if same version exist to over write the existing agent

}
#--------------------------------------------------------------------------------------------------------
function extract_workdrive(){

    IFS=$'\n'
    SKIP=`awk '/^__TARFILE_FOLLOWS__/ { print NR + 1; exit 0; }' $0`
    THIS=$0
    if [ ! -e $BINPATH ]; then
        mkdir -p $BINPATH || return 1
    fi
    tail -n +$SKIP $THIS | tar -xz -C  $BINPATH || return 1
    return 0
}
#--------------------------------------------------------------------------------------------------------
function create_desktop_file(){

    STARTUP=false
    if [[ ${1} = "STARTUP" ]]; then
        STARTUP=true
    fi
    DESKTOP_ENTRY="[Desktop Entry]
    Name=Zoho WorkDrive
    Comment=Sync documents to Zoho WorkDrive
    Exec=$HOME/.zohoworkdrive/bin/zohoworkdrive*
    Terminal=false
    Type=Application
    Icon=emblem-ztdrive-folder.png
    Categories=Network;FileTransfer;
    MimeType=application/x-ztwriter-link;application/x-ztsheet-link;application/x-ztshow-link;
    StartupNotify=false"
    if $STARTUP; then
        REPLACE=" -sstart"
        DESKTOP_ENTRY_PATH="$HOME/.config/autostart/ZohoWorkDrive.desktop"
        DESKTOP_ENTRY_PATH_OLD="$HOME/.config/autostart/ZohoTeamDrive.desktop"
    else
        mkdir -p "$LOCAL_PATH/share/applications/" || return 1
        REPLACE=" %F"
        DESKTOP_ENTRY_PATH="$LOCAL_PATH/share/applications/ZohoWorkDrive.desktop"
        DESKTOP_ENTRY_PATH_OLD="$LOCAL_PATH/share/applications/ZohoTeamDrive.desktop"
    fi
    DESKTOP_ENTRY="${DESKTOP_ENTRY/\*/$REPLACE}"
    echo "$DESKTOP_ENTRY" > "$DESKTOP_ENTRY_PATH" || return 1
    chmod +x "$DESKTOP_ENTRY_PATH" || return 1
    rm -f ${DESKTOP_ENTRY_PATH_OLD}
    return 0

}
#--------------------------------------------------------------------------------------------------------
function add_workdrive_to_startup(){

    mkdir -p ~/.config || return 1
    mkdir -p ~/.config/autostart || return 1
    create_desktop_file "STARTUP" || return 1
    return 0
}
#--------------------------------------------------------------------------------------------------------
function open_help_page(){

    if $REINSTALL; then
        HELPPAGE="https://help.zoho.com/portal/kb/articles/workdrive-desktop-sync#Install_and_set_up_Zoho_WorkDrive_for_your_desktop"
    else
        HELPPAGE="https://help.zoho.com/portal/kb/articles/workdrive-desktop-sync#Install_and_set_up_Zoho_WorkDrive_for_your_desktop"
    fi
    if which xdg-open > /dev/null; then
        xdg-open $HELPPAGE &
    elif which gnome-open > /dev/null; then
        gnome-open $HELPPAGE &
    fi
    return 0
}
#--------------------------------------------------------------------------------------------------------
function update_mimetype(){

    update-mime-database "$LOCAL_PATH/share/mime"
    gtk-update-icon-cache -t -f --include-image-data "$LOCAL_PATH/share/icons/hicolor"
    update-desktop-database "$LOCAL_PATH/share/applications"
    return 0
}
#--------------------------------------------------------------------------------------------------------
function add_file_to_local(){

    cp -R "$BINPATH/.local" $HOME || return 1
    return 0

}
#--------------------------------------------------------------------------------------------------------
function _abort(){

    echo "$1"
    exit 0
}
#--------------------------------------------------------------------------------------------------------
function start_workdrive(){

    exec $BINPATH/zohoworkdrive >/dev/null &
    disown
    return 0
}
#--------------------------------------------------------------------------------------------------------
function uninstall(){

    if [ ! -d "$BINPATH" ]; then
        _abort "Zoho WorkDrive not installed"
    fi
    open_uninstall_feeback
    unlink_app
    sleep 5
    rm -rf ~/.zohoworkdrive
    file_list=("$LOCAL_PATH/share/applications/ZohoWorkDrive.desktop"
                 "$HOME/.config/autostart/ZohoWorkDrive.desktop"
                 "$LOCAL_PATH/share/mime/packages/x-ztsheet-link.xml"
                 "$LOCAL_PATH/share/mime/packages/x-ztshow-link.xml"
                 "$LOCAL_PATH/share/mime/packages/x-ztwriter-link.xml"
                 "$LOCAL_PATH/share/icons/hicolor/16x16/emblems/emblem-ztdrive-folder.png"
                 "$LOCAL_PATH/share/icons/hicolor/16x16/mimetypes/zoho-tsheet-link.png"
                 "$LOCAL_PATH/share/icons/hicolor/16x16/mimetypes/zoho-tshow-link.png"
                 "$LOCAL_PATH/share/icons/hicolor/16x16/mimetypes/zoho-twriter-link.png"

                 "$LOCAL_PATH/share/icons/hicolor/24x24/emblems/emblem-ztdrive-folder.png"
                 "$LOCAL_PATH/share/icons/hicolor/24x24/mimetypes/zoho-tsheet-link.png"
                 "$LOCAL_PATH/share/icons/hicolor/24x24/mimetypes/zoho-tshow-link.png"
                 "$LOCAL_PATH/share/icons/hicolor/24x24/mimetypes/zoho-twriter-link.png"

                 "$LOCAL_PATH/share/icons/hicolor/32x32/emblems/emblem-ztdrive-folder.png"
                 "$LOCAL_PATH/share/icons/hicolor/32x32/mimetypes/zoho-tsheet-link.png"
                 "$LOCAL_PATH/share/icons/hicolor/32x32/mimetypes/zoho-tshow-link.png"
                 "$LOCAL_PATH/share/icons/hicolor/32x32/mimetypes/zoho-twriter-link.png"

                 "$LOCAL_PATH/share/icons/hicolor/48x48/emblems/emblem-ztdrive-folder.png"
                 "$LOCAL_PATH/share/icons/hicolor/48x48/mimetypes/zoho-tsheet-link.png"
                 "$LOCAL_PATH/share/icons/hicolor/48x48/mimetypes/zoho-tshow-link.png"
                 "$LOCAL_PATH/share/icons/hicolor/48x48/mimetypes/zoho-twriter-link.png"

                 "$LOCAL_PATH/share/icons/hicolor/64x64/emblems/emblem-ztdrive-folder.png"
                 "$LOCAL_PATH/share/icons/hicolor/64x64/mimetypes/zoho-tsheet-link.png"
                 "$LOCAL_PATH/share/icons/hicolor/64x64/mimetypes/zoho-tshow-link.png"
                 "$LOCAL_PATH/share/icons/hicolor/64x64/mimetypes/zoho-twriter-link.png"

                 "$LOCAL_PATH/share/icons/hicolor/128x128/emblems/emblem-ztdrive-folder.png"
                 "$LOCAL_PATH/share/icons/hicolor/128x128/mimetypes/zoho-tsheet-link.png"
                 "$LOCAL_PATH/share/icons/hicolor/128x128/mimetypes/zoho-tshow-link.png"
                 "$LOCAL_PATH/share/icons/hicolor/128x128/mimetypes/zoho-twriter-link.png"

                 "$LOCAL_PATH/share/icons/hicolor/256x256/emblems/emblem-ztdrive-folder.png"
                 "$LOCAL_PATH/share/icons/hicolor/256x256/mimetypes/zoho-tsheet-link.png"
                 "$LOCAL_PATH/share/icons/hicolor/256x256/mimetypes/zoho-tshow-link.png"
                 "$LOCAL_PATH/share/icons/hicolor/256x256/mimetypes/zoho-twriter-link.png" )

    for file in ${file_list[@]}
    do
        echo "removing... " $file
        rm -f $file || return 1
    done

    update-mime-database "$LOCAL_PATH/share/mime"
    gtk-update-icon-cache -t -f --include-image-data "$LOCAL_PATH/share/icons/hicolor"
    update-desktop-database "$LOCAL_PATH/share/applications"
    return 0
}
#--------------------------------------------------------------------------------------------------------
function open_uninstall_feeback(){

    if which xdg-open > /dev/null; then
        xdg-open "https://www.zoho.com/workdrive/uninstall-feedback.html" &
    elif which gnome-open > /dev/null; then
        gnome-open "https://www.zoho.com/workdrive/uninstall-feedback.html" &
    fi
    return 0
}
#--------------------------------------------------------------------------------------------------------
function unlink_app(){

    $BINPATH/zohoworkdrive "-uninstall" &
    return 0
}
#--------------------------------------------------------------------------------------------------------
function check_running_workdrive(){

    if pgrep "zohoworkdrive" || pgrep "zohoteamdrive"; then
        display_error "Zoho WorkDrive is running. Please quit Zoho WorkDrive to proceed"
        _abort "Zoho Workdrive aldready running"
    fi
    return 0
}
#--------------------------------------------------------------------------------------------------------
function migrate_teamdrive(){

    if [ ! -e $CONFPATH ]; then  #if .zohoworkspace not available
        if [ -e $OLDCONFPATH ]; then
            mv $OLDCONFPATH $CONFPATH
        fi
    fi
    return 0
}
#--------------------------------------------------------------------------------------------------------
function check_uninstallation(){
    
    check_running_workdrive
    if $UNINSTALL; then
        echo "uninstalling..."
        uninstall || _abort "uninstallation failed"
        exit 0
    fi
    return 0
}
#--------------------------------------------------------------------------------------------------------
function check_version(){
    if ! check_ver; then
        display_error "The setup has detected that higher version" "$(cat $VERSION)" "of Zoho WorkDrive is already installed"
        _abort "higher version aldready exists"
    fi
    return 0
}
#--------------------------------------------------------------------------------------------------------
function main(){

    init_vars $*
    check_uninstallation
    check_arch || _abort "failed in architecture check"
    check_version
    check_running_workdrive
    migrate_teamdrive
    extract_workdrive
    create_desktop_file || _abort "failed desktop file creation"
    add_workdrive_to_startup || _abort "failed to add at startup"
    add_file_to_local || _abort "failed to add mime and icons "
    update_mimetype || _abort "failed to update mime type"
    open_help_page || _abort "failed to open help page"
    start_workdrive || _abort "failed to start workdrive"    
    _abort "exiting..."
}
#--------------------------------------------------------------------------------------------------------
main $*
# Dont add anything below this line
#--------------------------------------------------------------------------------------------------------
__TARFILE_FOLLOWS__

followed by 81 MB archive data

Last edited by MountainX (2020-11-16 02:27:11)

Offline

#2 2020-11-16 06:33:09

loqs
Member
Registered: 2014-03-06
Posts: 12,093

Re: PKGBUILD request: Zoho WorkDrive Sync for Desktop

As a start:

pkgname=zohoworkdrive
_pkgname=ZohoWorkDrive
pkgver=1
pkgrel=1
pkgdesc=""
arch=('x86_64')
url=""
license=('unknown')
source=("ZohoWorkDrive-x64.tar.gz::https://files-accl.zohopublic.com/public/wdbin/download/2014030a29db316e9cedd501f32270e8")
sha256sums=('c15fa586861f72c3728c067aff2f22fb001f3ab3a12b898846c77f4741c894f2')

prepare() {
  mkdir $pkgname
  cd $_pkgname
  SKIP=`awk '/^__TARFILE_FOLLOWS__/ { print NR + 1; exit 0; }' .setup`
  tail -n +$SKIP .setup | tar -xz -C ../$pkgname
}

package() {
  cd "$pkgname"
}

Last edited by loqs (2020-11-16 06:35:56)

Offline

#3 2020-11-16 21:12:26

eschwartz
Trusted User/Bug Wrangler
Registered: 2014-08-08
Posts: 3,768

Re: PKGBUILD request: Zoho WorkDrive Sync for Desktop

Right, the main thing you need is to get the tarfile contents by reimplementing function extract_workdrive(){ ...; } as loqs demoed.

For installing, you will want to copy all the tarball contents to ${pkgdir}/opt/${_pkgname}, then move ${pkgdir}/opt/${_pkgname}/.local/share/ to ${pkgdir}/usr/share

Finally, you want to

ln -s /opt/${_pkgname}/zohoworkdrived "${pkgdir}"/usr/bin/zohoworkdrived

And create a ${_pkgname}.desktop file out of the contents of the DESKTOP_ENTRY="..." variable in the script, but with the Exec line just running "zohoworkdrived %F"; add the ${_pkgname}.desktop to source=() and install it the way desktop files normally get installed.

(Note there is a binary zohoworkdrived, and a script zohoworkdrive without the "d" at the endwhich just sets a redundant LD_LIBRARY_PATH that I don't believe you need, because the binary contains an rpath entry, then runs zohoworkdrived after a 5-second sleep, or a 30-second sleep if you invoke it via the optional autostart file.)

Note pkgver= should be aligned with this part of the script: ZSYNC_VER='2.5.20'

source=("ZohoWorkDrive-x64.tar.gz::https://files-accl.zohopublic.com/public/wdbin/download/2014030a29db316e9cedd501f32270e8")

should be source_x86_64=() since the source only works on x86_64, and the part before the :: is the renamed file -- add the pkgver to it.

source_x86_64=("ZohoWorkDrive-${pkgver}-x64.tar.gz::https://files-accl.zohopublic.com/public/wdbin/download/2014030a29db316e9cedd501f32270e8")
source=("ZohoWorkDrive.desktop")
sha256sums_x86_64=('c15fa586861f72c3728c067aff2f22fb001f3ab3a12b898846c77f4741c894f2')
sha256sums=('Desktop file checksum FILL THIS IN')

Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

Board footer

Powered by FluxBB