#!/bin/sh # # Copyright (c) 2012, Ting-Wei Lan. 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 author 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 HOLDERS 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. PREFIX=/usr/local PKGDB=/var/pkgdb PKGDB_COPY=${PKGDB}/copy PKGDB_DIR=${PKGDB}/dir PKGDB_SYMLINK=${PKGDB}/symlink [ "$1" ] && package_name="$1" if [ -z "${package_name}" ]; then read -p "Package to remove: " package_name [ -z "${package_name}" ] && echo "No input!" && exit 1 fi if [ -e "${PKGDB_COPY}/${package_name}" ] || [ -e "${PKGDB_DIR}/${package_name}" ] || [ -e "${PKGDB_SYMLINK}/${package_name}" ]; then echo "Found entry ${package_name} in ${PKGDB}" else echo "Package entry ${package_name} does not exist in ${PKGDB}" exit 1 fi read -p "You are going to remove ${package_name}! Is this correct [y/N]? " \ remove_yes if [ "${remove_yes}" != "y" ] && [ "${remove_yes}" != "Y" ]; then echo "Quit" exit 1 fi echo "List of copied files: " cat "${PKGDB_COPY}/${package_name}" read -p "Do you want to remove copied files? This may include your configuration file and other important data! [y/N] " remove_copied cat "${PKGDB_SYMLINK}/${package_name}" | { while read oneline do printf "[\e[1;36mREMOVE SYMLINK\e[m][-] ${package_prefix}/${oneline}\n" rm "${package_prefix}/${oneline}" done } rm "${PKGDB_SYMLINK}/${package_name}" if [ "${remove_copied}" = "y" ] || [ "${remove_copied}" = "Y" ]; then cat "${PKGDB_COPY}/${package_name}" | { while read oneline do printf "[\e[1;31mREMOVE COPIED\e[m][-] ${package_prefix}/${oneline}\n" rm "${package_prefix}/${oneline}" done } rm "${PKGDB_COPY}/${package_name}" fi cat "${PKGDB_DIR}/${package_name}" | { while read oneline do printf "[\e[1;35mRMDIR\e[m][-] ${package_prefix}/${oneline}\n" rmdir -p "${package_prefix}/${oneline}" done } rm "${PKGDB_DIR}/${package_name}" if [ '!' "${remove_copied}" = "y" ] && [ '!' "${remove_copied}" = "Y" ]; then echo "Note: ${PKGDB_COPY}/${package_name} still exists!" fi