File: cmake_uninstall.cmake.in

package info (click to toggle)
ckb-next 0.4.3%2Bdfsg.1-0.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 4,428 kB
  • sloc: cpp: 16,823; ansic: 10,448; sh: 205; xml: 121; python: 21; makefile: 9
file content (196 lines) | stat: -rw-r--r-- 7,821 bytes parent folder | download
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#   Copyright 2017-2018 ckb-next Development Team <ckb-next@googlegroups.com>
#   All rights reserved.
#
#   Redistribution and use in source and binary forms, with or without
#   modification, are permitted provided that the following conditions are met:
#
#   1. Redistributions of source code must retain the above copyright notice,
#   this list of conditions and the following disclaimer.
#   2. Redistributions in binary form must reproduce the above copyright
#   notice, this list of conditions and the following disclaimer in the
#   documentation and/or other materials provided with the distribution.
#   3. Neither the name of the copyright holder nor the names of its
#   contributors may be used to endorse or promote products derived from this
#   software without specific prior written permission. 
#   
#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
#   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
#   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
#   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
#   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
#   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
#   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
#   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
#   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
#   POSSIBILITY OF SUCH DAMAGE.

# Also see https://cmake.org/Wiki/CMake_FAQ#Can_I_do_.22make_uninstall.22_with_CMake.3F

if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
  message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")

# Stop the GUI
message(STATUS "Searching for running ckb and/or ckb-next GUI")

execute_process(
    COMMAND ps axco command
    COMMAND egrep "^ckb$|^ckb-next$"
    OUTPUT_VARIABLE gui_processes
    OUTPUT_STRIP_TRAILING_WHITESPACE)

if (gui_processes)
    string(REPLACE "\n" ";" gui_processes_list "${gui_processes}")
    foreach (gui_process IN LISTS gui_processes_list)
        message(STATUS "Running ${gui_process} GUI detected")
        message(STATUS "Terminating ${gui_process}")
        execute_process(COMMAND killall -9 "${gui_process}")
    endforeach ()
endif ()

set(init_system "@CKB_NEXT_INIT_SYSTEM@")
message(STATUS "Init system: ${init_system}")

# Stop the daemon
if ("${init_system}" STREQUAL "launchd")

    execute_process(
        COMMAND sudo launchctl list
        OUTPUT_VARIABLE launchctl_jobs)

    foreach (plist_name IN ITEMS "com.ckb.daemon" "org.next.ckb.daemon")
        string(FIND "${launchctl_jobs}" "${plist_name}" daemon_found)
        if (NOT (daemon_found EQUAL -1))
            message(STATUS "Running job with ${plist_name} plist detected")
            message(STATUS "${init_system}: permanently unloading ${plist_name}")
            execute_process(COMMAND sudo launchctl unload -w /Library/LaunchDaemons/${plist_name}.plist)
        endif ()
    endforeach ()

elseif ("${init_system}" STREQUAL "upstart")

    foreach(daemon IN ITEMS "ckb-daemon" "ckb-next-daemon")

        execute_process(
            COMMAND sudo service ${daemon} status
            COMMAND egrep "^${daemon} start"
            RESULT_VARIABLE daemon_active)

        if(daemon_active EQUAL 0)
            message(STATUS "Running ${daemon} detected")
            message(STATUS "${init_system}: stopping ${daemon}")
            execute_process(COMMAND sudo service ${daemon} stop)
        endif()

        execute_process(
            COMMAND sudo initctl show-config ${daemon}
            COMMAND egrep "^  start on"
            RESULT_VARIABLE daemon_enabled)

        if(daemon_enabled EQUAL 0)
            message(STATUS "Enabled ${daemon} detected")
            message(STATUS "${init_system}: permanently disabling ${daemon}")
            execute_process(COMMAND echo manual COMMAND sudo tee /etc/init/${daemon}.override)
        endif()

    endforeach()

elseif ("${init_system}" STREQUAL "systemd")

    foreach(daemon IN ITEMS "ckb-daemon" "ckb-next-daemon")

        execute_process(
            COMMAND sudo systemctl is-active ${daemon}.service
            RESULT_VARIABLE daemon_active)

        if(daemon_active EQUAL 0)
            message(STATUS "Running ${daemon} detected")
            message(STATUS "${init_system}: stoppping ${daemon}")
            execute_process(COMMAND sudo systemctl stop ${daemon}.service)
        endif()

        execute_process(
            COMMAND sudo systemctl is-enabled ${daemon}.service
            RESULT_VARIABLE daemon_enabled)

        if(daemon_enabled EQUAL 0)
            message(STATUS "Enabled ${daemon} detected")
            message(STATUS "${init_system}: permanently disabling ${daemon}")
            execute_process(COMMAND sudo systemctl disable ${daemon}.service)
        endif()

    endforeach()

elseif ("${init_system}" STREQUAL "OpenRC")

    execute_process(
        COMMAND rc-status -a
        COMMAND egrep "started"
        COMMAND egrep -o "ckb-daemon|ckb-next-daemon"
        OUTPUT_VARIABLE daemons
        OUTPUT_STRIP_TRAILING_WHITESPACE)

    if (daemons)
        string(REPLACE "\n" ";" daemons_list "${daemons}")
        foreach(daemon IN LISTS daemons_list)
            message(STATUS "Running ${daemon} detected")
            message(STATUS "${init_system}: stoppping ${daemon}")
            execute_process(COMMAND sudo rc-service ${daemon} stop)
        endforeach()
    endif()

    execute_process(
        COMMAND rc-status -a
        COMMAND egrep -o "ckb-daemon|ckb-next-daemon"
        OUTPUT_VARIABLE daemons
        OUTPUT_STRIP_TRAILING_WHITESPACE)

    if (daemons)
        string(REPLACE "\n" ";" daemons_list "${daemons}")
        foreach(daemon IN LISTS daemons_list)
            message(STATUS "Enabled ${daemon} detected")
            message(STATUS "${init_system}: permanently disabling ${daemon}")
            execute_process(COMMAND sudo rc-update del ${daemon} default)
        endforeach()
    endif()

elseif ("${init_system}" STREQUAL "SysVinit")

    message(STATUS "${init_system}: stopping and disabling ${daemon}")
    execute_process(COMMAND sudo service ckb-next-daemon.sh stop)
    find_program(UPDATE_RC_EXISTS "update-rc.d")
    if (UPDATE_RC_EXISTS)
        execute_process(COMMAND sudo update-rc.d ckb-next-daemon.sh remove)
    endif ()

else ()
    message(WARNING "Init system was not detected.
    Either there's a bug, or your init system is not supported.")
endif ()

file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
string(REGEX REPLACE "\n" ";" files "${files}")

foreach (file IN LISTS files)
    message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
    if (IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
        exec_program(
            "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
            OUTPUT_VARIABLE rm_out
            RETURN_VALUE rm_retval)
        if (NOT "${rm_retval}" STREQUAL 0)
            message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
        endif (NOT "${rm_retval}" STREQUAL 0)
    else ()
        message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
    endif ()
endforeach (file)

if ("${init_system}" STREQUAL "systemd")
    message(STATUS "${init_system}: refreshing services")
    execute_process(COMMAND sudo systemctl daemon-reload)
elseif ("${init_system}" STREQUAL "upstart")
    message(STATUS "${init_system}: refreshing services")
    execute_process(COMMAND sudo initctl reload-configuration)
endif ()