From 47e8f8003ee1c59e03b960f1d05f09d2c65104f1 Mon Sep 17 00:00:00 2001 From: dutor <440396+dutor@users.noreply.github.com> Date: Mon, 16 Dec 2019 12:52:45 +0800 Subject: [PATCH] Added uninstall --- CMakeLists.txt | 18 +++++++++++++++--- aux/self-extractable.sh.in | 3 ++- scripts/CMakeLists.txt | 2 ++ scripts/nebula-gears-show-files | 18 ++++++++++++++++++ scripts/nebula-gears-uninstall | 21 +++++++++++++++++++++ 5 files changed, 58 insertions(+), 4 deletions(-) create mode 100755 scripts/nebula-gears-show-files create mode 100755 scripts/nebula-gears-uninstall diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b10a98..53d525b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,6 @@ cmake_minimum_required(VERSION 3.0) project("nebula-gears" CXX ASM) - set(CMAKE_CXX_STANDARD 14) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY lib) @@ -37,14 +36,27 @@ configure_file( @ONLY ) +set(stage_dir "${CMAKE_BINARY_DIR}/stage") +set(stage_install_prefix "${stage_dir}/${CMAKE_INSTALL_PREFIX}") +set(share_dir "share/nebula-gears") +set(installed_files_file "installed_files") + add_custom_target( package COMMAND - make -s install DESTDIR=${CMAKE_BINARY_DIR}/stage + make -s install DESTDIR=${stage_dir} + COMMAND + mkdir -p ${stage_install_prefix}/${share_dir} + COMMAND + find ${stage_install_prefix} -type f -fprint ${stage_install_prefix}/${share_dir}/${installed_files_file} + COMMAND + find ${stage_install_prefix} -type f -fprint ${stage_install_prefix}/${share_dir}/${installed_files_file} + COMMAND + sed -i "s#${stage_install_prefix}/##" ${stage_install_prefix}/${share_dir}/${installed_files_file} COMMAND cp -f ${CMAKE_BINARY_DIR}/${package_name}-meta.sh ${package_name}.sh COMMAND - tar -cJf - -C ${CMAKE_BINARY_DIR}/stage/${CMAKE_INSTALL_PREFIX} . >> ${CMAKE_BINARY_DIR}/${package_name}.sh + tar -cJf - -C ${stage_install_prefix} . >> ${CMAKE_BINARY_DIR}/${package_name}.sh COMMAND chmod +x ${CMAKE_BINARY_DIR}/${package_name}.sh ) diff --git a/aux/self-extractable.sh.in b/aux/self-extractable.sh.in index 4ae4568..34a97cf 100644 --- a/aux/self-extractable.sh.in +++ b/aux/self-extractable.sh.in @@ -16,10 +16,11 @@ hash xz &>/dev/null || { echo "xz: command not found"; exit 1; } hash lsb_release &>/dev/null || { echo "lsb_release: command not found"; exit 1; } mkdir -p $prefix + [[ -w $prefix ]] || { echo "$prefix: No permission to write"; exit 1; } archive_offset=$(awk '/^__start_of_archive__$/{print NR+1; exit 0;}' $0) -tail -n+$archive_offset $0 | tar --numeric-owner -xJf - -C $prefix +tail -n+$archive_offset $0 | tar --no-same-owner --numeric-owner -xJf - -C $prefix echo "@package_name@ has been installed to $prefix" diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index ef1fe2a..d00a877 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -20,6 +20,8 @@ install( distro-name distro-fullname distro-version + nebula-gears-uninstall + nebula-gears-show-files PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE diff --git a/scripts/nebula-gears-show-files b/scripts/nebula-gears-show-files new file mode 100755 index 0000000..01ee3d4 --- /dev/null +++ b/scripts/nebula-gears-show-files @@ -0,0 +1,18 @@ +#! /usr/bin/env bash + +set -e +set -o pipefail + +this_dir=$(dirname $(readlink -f $0)) + +bin_dir_name=$(basename $this_dir) +[[ $bin_dir_name = bin ]] || exit 1 + +install_prefix=$(dirname $this_dir) +share_dir=$install_prefix/share/nebula-gears +installed_files_file=$share_dir/installed_files + +for file in $(cat $installed_files_file) +do + echo $install_prefix/$file +done diff --git a/scripts/nebula-gears-uninstall b/scripts/nebula-gears-uninstall new file mode 100755 index 0000000..adef732 --- /dev/null +++ b/scripts/nebula-gears-uninstall @@ -0,0 +1,21 @@ +#! /usr/bin/env bash + +set -e +set -o pipefail + +this_dir=$(dirname $(readlink -f $0)) + +bin_dir_name=$(basename $this_dir) +[[ $bin_dir_name = bin ]] || exit 1 + +install_prefix=$(dirname $this_dir) +share_dir=$install_prefix/share/nebula-gears +installed_files_file=$share_dir/installed_files + +for file in $(cat $installed_files_file) +do + echo "Removing $install_prefix/$file" + rm -f $install_prefix/$file +done + +echo "Done"