aboutsummarylogtreecommitdiffstats
path: root/kesl.install
blob: 3110994c83c80e3f8cb1308d4ee488f56fddc19e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
export TMPDIR=/tmp
# avoid re-creating tmp dir when already exists
[ -d "$KTMP" ] || KTMP=$(mktemp -d -t kesl.XXXXX)

# man pages are special here:
# 1) usr/local/share is protected (owned by filesystem package)
# 2) when modding /opt/kaspersky/kesl/libexec/symlinks/man directly the hash will break and kesl won't work properly
# 3) to be flexible for future changes we backup the symlink defs to tmp, replace, run installer, revert original
# this ensures that the kesl install dir isn't tampered and future changes will be added automagically or by
# extending the following func:
man_pre(){
    # man pages
    cp /var/opt/kaspersky/kesl/install/opt/kaspersky/kesl/libexec/symlinks/man $KTMP/
    sed -i 's#usr/local/#usr/#g' /var/opt/kaspersky/kesl/install/opt/kaspersky/kesl/libexec/symlinks/man
}

man_post(){
    # revert man pages symlinks
    cp $KTMP/man /var/opt/kaspersky/kesl/install/opt/kaspersky/kesl/libexec/symlinks/man
    [ -d "/opt/kaspersky/kesl/libexec/symlinks" ] && cp $KTMP/man /opt/kaspersky/kesl/libexec/symlinks/man
}

# create all directories referenced by the kesl installer
# no idea why this is not covered by it but this ensures nothing breaks during the install
kesl_symlinks(){
    man_pre
    # create any directory expected to be there for symlinking
    for sl in $(cat /var/opt/kaspersky/kesl/install/opt/kaspersky/kesl/libexec/symlinks/*);do
        sld=$(dirname $sl)
        [ ! -d $sld ] && mkdir -p $sld
    done
}

kesl_updatedb(){
    # upgrading the database can take a LONG time while any other pacman
    # jobs would wait until this has been finished. It is recommended to do
    # this manually:
    echo -e "\n\n\e[93m\e[1mPlease update the AV database MANUALLY with the following command (or use the GUI):\e[0m\nsudo /opt/kaspersky/kesl/bin/kesl-control --start-task Update --progress\n\n"
}

pre_install(){
    echo $FUNCNAME
    # this always breaks post_install:
    #/var/opt/kaspersky/kesl/pkgscripts/preinst install
}

post_install(){
    echo $FUNCNAME

    # load preconfiguration variables and export them
    source /var/opt/kaspersky/kesl/pkgscripts/kesl.ini
    for k in $(egrep -v "^#" /var/opt/kaspersky/kesl/pkgscripts/kesl.ini);do
        key=${k/=*}; kkey="KESL_${key}"; v="${k/*=}"
        export ${key}=$v ${kkey}=$v
    done

    kesl_symlinks

    # manually add the link to /opt (really wondering why this is not covered
    # anywhere but likely I am blind:
    ln -s /var/opt/kaspersky/kesl/install/opt/kaspersky/kesl /opt/kaspersky/

    # exec the debian package postinst
    /var/opt/kaspersky/kesl/pkgscripts/postinst configure

    man_post

    # execute the kesl installer with preconfigured settings
    echo -e "\e[32m\e[1m ... starting '/opt/kaspersky/kesl/bin/kesl-setup.pl' now\e[0m\n(no need to execute it again after installation has finished)."
    cp /var/opt/kaspersky/kesl/pkgscripts/kesl.ini $KTMP/
    sed -i "s/@YOU@/$SUDO_USER/g" $KTMP/kesl.ini 
    /opt/kaspersky/kesl/bin/kesl-setup.pl --autoinstall=$KTMP/kesl.ini

    kesl-control -L --query

    kesl_updatedb
}

pre_upgrade(){
    echo $FUNCNAME
    for k in $(egrep -v "^#" /var/opt/kaspersky/kesl/pkgscripts/kesl.ini);do
        key=${k/=*}; kkey="KESL_${key}"; v="${k/*=}"
        export ${key}=$v ${kkey}=$v
    done

    # exec the debian package preinst
    man_pre
    /var/opt/kaspersky/kesl/pkgscripts/preinst upgrade
    man_post
}

post_upgrade(){
    echo $FUNCNAME

    # load preconfiguration variables and export them
    source /var/opt/kaspersky/kesl/pkgscripts/kesl.ini
    for k in $(egrep -v "^#" /var/opt/kaspersky/kesl/pkgscripts/kesl.ini);do
        key=${k/=*}; kkey="KESL_${key}"; v="${k/*=}"
        export ${key}=$v ${kkey}=$v
    done
    kesl_symlinks

    # exec the debian package postinst
    /var/opt/kaspersky/kesl/pkgscripts/preinst configure
    man_post

    kesl_updatedb
}

pre_remove(){
    echo $FUNCNAME
    # exec the debian package rm scripts (post_remove is too late)
    /var/opt/kaspersky/kesl/pkgscripts/prerm remove
    /var/opt/kaspersky/kesl/pkgscripts/postrm remove
}

post_remove(){
    echo $FUNCNAME
    rm -rf /etc/opt/kaspersky/ /opt/kaspersky/ /usr/share/licenses/kesl /var/opt/kaspersky
}

#rm -rf $KTMP/