This howto is tested on:

  • Debian 10.0 Buster

This howto is tested with these versions of the software:

  • 7.0.4

Requirements

This howto recommends:

Settings

Choose the user running the software on the system:

seafcliUser="www-data"

Installation

Detect if sudo is available (“command” is used if not):

cmdProxy='command'
command type -f 'sudo' &>'/dev/null' && cmdProxy='sudo'

Detect the distribution version name:

debianVersion="$(command lsb_release -cs)"

Compute the software data cache path for the chosen user:

seafcliDataPath="/var/lib/seaf-cli/${seafcliUser}"

Create the data path and set its owner:

${cmdProxy} mkdir --parent "${seafcliDataPath}"
${cmdProxy} chown "${seafcliUser}:${seafcliUser}" "${seafcliDataPath}"

Environment setup

Install the software’s requisites:

${cmdProxy} apt-get install 'sudo' 'ca-certificates' \
    'lsb-release' 'gnupg'

Configure the software’s repository:

${cmdProxy} tee "/etc/apt/sources.list.d/seafile.list" \
<<< "# Seafile for ${debianVersion}
deb http://deb.seadrive.org ${debianVersion} main"

Add the repository’s signing key:

${cmdProxy} apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' \
    --recv-keys '8756C4F765C9AC3CB6B85D62379CE192D401AB61'

Update the list of available packages:

${cmdProxy} apt update

Software installation

Install the software:

${cmdProxy} apt-get install 'seafile-cli'

Install a script restarting seaf-cli services when the “seafile-cli” package has been upgraded less than 120 minutes ago:

${cmdProxy} tee '/var/lib/seaf-cli/seaf-cli-restart' \
<<< "#\!/bin/bash

# Check if seafile-cli package has been upgraded in the last 120 minutes.
# end this script if the package has not been upgraded recently.
find '/var/lib/dpkg/info' -name 'seafile-cli.list' -mmin '-120' >'/dev/null' \\
    || exit 0

# Restart each active seaf-cli services
find '/etc/systemd/system' -type f -name 'seaf-cli-*.service' \\
    | while read serviceFile; do
  serviceName=\"\$(basename \"\${serviceFile}\")\"

  systemctl is-active \"\${serviceName}\" >'/dev/null' 2>&1 \\
      && systemctl restart \"\${serviceName}\"
done

exit 0"
${cmdProxy} chmod +x '/var/lib/seaf-cli/seaf-cli-restart'

Trigger seaf-cli services restart after upgrade:

${cmdProxy} tee '/etc/apt/apt.conf.d/90seafile-cli' \
<<< '// Restart seafile-cli services after upgrade.
DPkg::Post-Invoke {
  "[ -x '/var/lib/seaf-cli/seaf-cli-restart' ] && /var/lib/seaf-cli/seaf-cli-restart";
};'

Initialization

Install the software as a service for the chosen user:

${cmdProxy} tee "/etc/systemd/system/seaf-cli-${seafcliUser}.service" \
    <<< "[Unit]
Description=Seafile client for user ${seafcliUser}
# add seafile.service and seahub.service here if the client is on the same host as the Seafile server.
After=network.target

[Service]
Type=forking
ExecStart=/usr/bin/seaf-cli start
ExecStop=/usr/bin/seaf-cli stop
User=${seafcliUser}
Group=${seafcliUser}

[Install]
WantedBy=multi-user.target"

Reload systemctl configuration:

${cmdProxy} systemctl daemon-reload

Set the seafile data cache path for the chosen user:

sudo -u "${seafcliUser}" seaf-cli init -d "${seafcliDataPath}"

Start the service at boot:

${cmdProxy} systemctl enable "seaf-cli-${seafcliUser}"

Start the service:

${cmdProxy} systemctl start "seaf-cli-${seafcliUser}"

Configuration

Synchronization of a Seafile library

Settings

Provide the URL of the Seafile library to synchronize locally (copy/pasted from the browser):

libraryUrl='https://seafile.domain.com/library/fa9df3e8c-2de3-5f82-9ca3-ad53678033b8/ASeafileLibrary/'

Choose the local path for the library:

libraryPath="${HOME}/seafile/"

Configuration

Compute the library ID and the Seafile server URL:

seafileServer="$(command echo "${libraryUrl}" \
    | command sed -e 's|\(http[s]*://[^/]*/\).*$|\1|')"
libraryId="$(command echo "${libraryUrl}" \
    | command sed -e 's|^.*/library/||' -e 's|\([^/]\)/.*$|\1|g')"

Make sure the local library path exists:

${cmdProxy} mkdir -p "${libraryPath}"
${cmdProxy} chown "${seafcliUser}" "${libraryPath}"

Register the library with the Seafile client service:

sudo -u "${seafcliUser}" seaf-cli download \
    -l "${libraryId}" \
    -s "${seafileServer}" \
    -d "${libraryPath}"

The library can be synchronized with an existing folder contents:

sudo -u "${seafcliUser}" seaf-cli sync \
    -l "${libraryId}" \
    -s "${seafileServer}" \
    -d "${libraryPath}"

Removal

Detect if sudo is available (“command” is used if not):

cmdProxy='command'
command type -f 'sudo' &>'/dev/null' && cmdProxy='sudo'

Stop and remove the seaf-cli services:

command find '/etc/systemd/system' -type f -name 'seaf-cli-*.service' \
    | while read serviceFile; do
  serviceName="$(command basename "${serviceFile}")"
  ${cmdProxy} systemctl 'stop' "${serviceName}"
  ${cmdProxy} systemctl 'disable' "${serviceName}"
  ${cmdProxy} rm "${serviceFile}"
done

Reload systemctl configuration:

${cmdProxy} systemctl daemon-reload

Remove the software:

${cmdProxy} apt-get autoremove 'seafile-cli'

The folders synchronized by Seafile can now be removed.

Thanks

Categories: Software

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.