#!/bin/cat 
# $Id: INSTALL.Debian.txt,v 1.40 2023/07/29 16:21:14 gilles Exp gilles $

This documentation is also located online at 
https://imapsync.lamiral.info/INSTALL.d/
https://imapsync.lamiral.info/INSTALL.d/INSTALL.Debian.txt


There is four install sections in this document,
1) one for Debian 9 Stretch, Debian 10 Buster, Debian 11 Bullseye, Debian 12 Bookworm
2) one for all the Debian, called "After installing the dependencies".
3) one for Debian 8 Jessie (obsolete)
4) one for Debian 7 Wheezy (even more obsolete)

After reading and following 1) or 3) or 4), you'll be invited to read and follow 
the section "2) After installing the dependencies"

What is your Debian release?
Type on a terminal:

    cat /etc/debian_version

12.x => Bookworm
11.x => Bullseye
10.x => Buster
 9.x => Stretch
 8.x => Jessie
 7.x => Wheezy

where x is any number between 0 and 9, x is minor and to be forgotten.


First, a call to Debian packagers
Why imapsync is not in Debian as a package?
Imapsync used to be in Debian from 2005-04-25 (release 1.125) to 2011-01-25 (release 1.315).
It could be in Debian nowadays, as always, my last words on this discussion were 
"Do what you want, I promise I won't complain anymore about the fact imapsync is in Debian or not."
https://lists.debian.org/debian-legal/2011/01/msg00058.html
The Imapsync license is "No limits to do anything with this work and this license".
So feel free!
See also a more detailed story at
https://lists.debian.org/debian-user/2016/11/msg00849.html


=========================================================================================
  1) Installing imapsync on Debian 9 Stretch, 10 Buster, 11 Bullseye, Debian 12 Bookworm
=========================================================================================

How to install imapsync dependencies on a Debian system?

The repositories are the classical ones, ie, a
/etc/apt/sources.list file with:

# Debian 12 Bookworm
deb http://deb.debian.org/debian bookworm main contrib

or

# Debian 11 Bullseye
deb http://deb.debian.org/debian bullseye main contrib

or

# Debian 10 Buster
deb http://deb.debian.org/debian buster main contrib

or

# Debian 9 Stretch
deb http://deb.debian.org/debian stretch main contrib


You need root privilege to run it, be root or use sudo.

apt install -y            \
  libauthen-ntlm-perl     \
  libcgi-pm-perl          \
  libcrypt-openssl-rsa-perl   \
  libdata-uniqid-perl         \
  libencode-imaputf7-perl     \
  libfile-copy-recursive-perl \
  libfile-tail-perl        \
  libio-socket-inet6-perl  \
  libio-socket-ssl-perl    \
  libio-tee-perl           \
  libhtml-parser-perl      \
  libjson-webtoken-perl    \
  libmail-imapclient-perl  \
  libparse-recdescent-perl \
  libproc-processtable-perl \
  libmodule-scandeps-perl  \
  libreadonly-perl         \
  libregexp-common-perl    \
  libsys-meminfo-perl      \
  libterm-readkey-perl     \
  libtest-mockobject-perl  \
  libtest-pod-perl         \
  libunicode-string-perl   \
  liburi-perl              \
  libwww-perl              \
  libtest-nowarnings-perl  \
  libtest-deep-perl        \
  libtest-warn-perl        \
  make                     \
  time                     \
  cpanminus


After installing the dependencies, imapsync should be working,
go to the section "2) After installing the dependencies" below.

=======================================================================
  2) After installing the dependencies
=======================================================================

You don't have to be root to test and use imapsync.

Take imapsync either on github:

  wget -N https://raw.githubusercontent.com/imapsync/imapsync/master/imapsync

or be on the cutting edge with the upstream site:

  wget -N https://imapsync.lamiral.info/imapsync

Add execution permission to the downloaded script:

  chmod +x imapsync
  
Check the dependencies and print also the basic example:

  ./imapsync

Perform a live test showing imapsync job:

  ./imapsync --testslive

To get rid of the fake messages
DEBUG: .../IO/Socket/SSL.pm:1177: global error: Undefined SSL object
(See https://imapsync.lamiral.info/FAQ.d/FAQ.SSL_errors.txt)
then update the Perl module IO::Socket::SSL release >= 2.073
with the commands:

  cpanm --test-only IO::Socket::SSL
  cpanm             IO::Socket::SSL

Now install imapsync on the system (need root priviledges again):

  cp imapsync /usr/bin/

That's finished for the installation part.
You can now use imapsync without knowing where it is located
on the system:

  imapsync 

Now go read the menu http://imapsync.lamiral.info/#doc
and start with the tutorial 
https://imapsync.lamiral.info/doc/TUTORIAL_Unix.html

Feedback is welcome!



=======================================================================
 3) Installing imapsync on Debian 8 Jessie 
=======================================================================

How to install imapsync dependencies on a Debian system?

You need root priviledge.

The first command installs standard Debian packages:
apt install           \
  libauthen-ntlm-perl \
  libcgi-pm-perl      \
  libcrypt-openssl-rsa-perl   \
  libdata-uniqid-perl         \
  libencode-imaputf7-perl     \
  libfile-copy-recursive-perl \
  libfile-tail-perl        \
  libio-socket-inet6-perl  \
  libio-socket-ssl-perl    \
  libio-tee-perl           \
  libhtml-parser-perl      \
  libmail-imapclient-perl  \
  libparse-recdescent-perl \
  libmodule-scandeps-perl  \
  libreadonly-perl         \
  libterm-readkey-perl     \
  libtest-mockobject-perl  \
  libtest-pod-perl         \
  libunicode-string-perl   \
  liburi-perl              \
  libwww-perl              \
  libregexp-common-perl    \
  libtest-nowarnings-perl  \
  libtest-deep-perl        \
  libtest-warn-perl        \
  gcc                      \
  make                     \
  cpanminus

The package libdata-uniqid-perl is in the jessie-backports repository
https://packages.debian.org/fr/jessie-backports/libdata-uniqid-perl

Here is how to add jessie-backports repository in /etc/apt/sources.list

https://backports.debian.org/Instructions/

If you can't add the jessie-backports repository in /etc/apt/sources.list you
have to install Perl module Data::Uniqid with cpanm:

  cpanm  Data::Uniqid

The following second command installs "manually" the Perl module Sys::MemInfo
because Debian 8 Jessie doesn't have this Perl module available via a package 
(but Debian 9 Stretch does):

  cpanm Sys::MemInfo 

The following optional cpanm command updates Perl module Mail::IMAPClient
because it is good to be up to date with that imapsync dependency,
but it is not mandatory since Mail::IMAPClient is installed by
the Debian package libmail-imapclient-perl:

  cpanm Mail::IMAPClient

Last, in case you need to use XOAUTH2 authentication you have to install   
the module JSON::WebToken with the command:

  cpanm JSON::WebToken

After installing the dependencies, imapsync should be working,
go to the section "2) After installing the dependencies" above.


=======================================================================
  4) Installing imapsync on Debian 7 Wheezy 
=======================================================================

How to install imapsync dependencies on a Debian system?

You need root priviledge to run the commands.

The first command installs standard Debian packages:

apt-get install    \
  libauthen-ntlm-perl  \
  libclass-load-perl   \
  libcrypt-openssl-rsa-perl \
  libdigest-hmac-perl  \
  libencode-imaputf7-perl     \
  libfile-copy-recursive-perl \
  libfile-tail-perl        \
  libio-compress-perl     \
  libio-socket-inet6-perl \
  libio-socket-ssl-perl   \
  libio-tee-perl          \
  libmail-imapclient-perl \
  libmodule-implementation-perl \
  libmodule-runtime-perl  \
  libmodule-scandeps-perl \
  libpackage-stash-perl   \
  libpackage-stash-xs-perl \
  libpar-packer-perl      \
  libreadonly-perl        \
  libterm-readkey-perl    \
  libtest-fatal-perl      \
  libtest-pod-perl        \
  libtest-requires-perl   \
  libtest-simple-perl     \
  libunicode-string-perl  \
  liburi-perl             \
  gcc                     \
  make                    \
  cpanminus


The following second command installs "manually" the Perl modules 
Data::Uniqid
Sys::MemInfo
because Debian hasn't made them available via a package yet.
This cpanm command  also installs manually Perl module Mail::IMAPClient
because it is good to be up to date with that imapsync dependency,
but it is not mandatory since Mail::IMAPClient is installed by
the Debian package libmail-imapclient-perl:

  cpanm Data::Uniqid  Sys::MemInfo
  
In case you want to update the Perl module Mail::IMAPClient,
a major module for imapsync, but an old March 2012 release 3.31 in Wheezy, 
the following command updates it "manually":

  cpanm Mail::IMAPClient

Last, in case you need to use XOAUTH2 authentication you have to install   
the module JSON::WebToken with the command:

  cpanm JSON::WebToken


After installing the dependencies, imapsync should be working,
then go to the section "2) After installing the dependencies" above.

=======================================================================
