aboutsummaryrefslogtreecommitdiff
path: root/nixpkgs/pkgs/desktops/deepin/setup-hook.sh
blob: ce1d7330a22213a8e125642b0a3291c4b1a32ba3 (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
# Helper functions for deepin packaging

searchHardCodedPaths() {
    # Usage:
    #
    #   searchHardCodedPaths [-a] [<path>]
    #
    # Looks for ocurrences of FHS hard coded paths and command
    # invocations in the given path (default: current directory) for
    # the purpose of debugging a derivation. The option -a enables
    # processing binary files as if they were text.

    local binary
    if [ "$1" = "-a" ]; then
        binary="-a"
        shift
    fi

    local path=$1

    echo ----------- looking for command invocations in $path
    grep --color=always -r -E '\<(ExecStart|Exec|startDetached|execute|exec\.(Command|LookPath))\>' $path || true

    echo ----------- looking for hard coded paths in $path
    grep --color=always $binary -r -E '/(usr|bin|sbin|etc|var|opt)\>' $path || true

    echo ----------- done
}

fixPath() {
    # Usage:
    #
    #   fixPath <parent dir> <path> <files>
    #
    # replaces occurences of <path> by <parent_dir><path> in <files>
    # removing /usr from the start of <path> if present

    local parentdir=$1
    local path=$2
    local newpath=$parentdir$(echo $path | sed "s,^/usr,,")
    local files=("${@:3}")
    echo ======= grep --color=always "${path}" "${files[@]}"
    grep --color=always "${path}" "${files[@]}"
    echo +++++++ sed -i -e "s,$path,$newpath,g" "${files[@]}"
    sed -i -e "s,$path,$newpath,g" "${files[@]}"
}

searchForUnresolvedDLL() {
    # Usage:
    #
    #   searchForUnresolvedDLL <dir>
    #
    # looks in <dir> for executables with unresolved dynamic library paths

    local dir="$1"
    echo ======= Looking for executables with unresolved dynamic library dependencies
    echo $dir
    for f in $(find -L "$dir" -type f -executable); do
      if (ldd $f | grep -q "not found"); then
        echo $f
        ldd $f | grep --color=always "not found"
      fi
    done
}