lib32/rmpkg.sh

222 lines
5.5 KiB
Bash
Raw Normal View History

2011-02-03 18:54:20 +08:00
#!/bin/bash
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
#
# (c) 2010 - Manuel Tortosa <manutortosa[at]chakra-project[dot]org>
#
# global vars
#
_script_name="Remove Package(s)"
2011-02-24 23:22:21 +08:00
_cur_repo=$(pwd | awk -F '/' '{print $NF}')
2011-02-03 18:54:20 +08:00
_needed_functions="config_handling helpers messages"
_build_arch="$_arch"
2011-02-24 23:22:21 +08:00
_sarch="x32"
_args=`echo $1`
[[ ${_arch} = *x*64* ]] && _sarch="x64"
2011-02-03 18:54:20 +08:00
# helper functions
for subroutine in ${_needed_functions} ; do
2011-02-24 23:22:21 +08:00
source _buildscripts/functions/${subroutine}
2011-02-03 18:54:20 +08:00
done
# Determine the sync folder
if [[ ${_cur_repo} = *-testing ]] && [[ ${_cur_repo} != lib32-testing ]] ; then
2011-02-24 23:22:21 +08:00
_sync_folder="_testing-${_sarch}/"
elif [[ ${_cur_repo} = *-unstable ]] ; then
_sync_folder="_unstable-${_sarch}/"
2011-02-03 18:54:20 +08:00
else
2011-02-24 23:22:21 +08:00
_sync_folder="_repo/remote/"
2011-02-03 18:54:20 +08:00
fi
2011-02-24 23:22:21 +08:00
2011-02-03 18:54:20 +08:00
#
# main
#
sync_down()
{
2011-02-24 23:22:21 +08:00
msg "syncing down"
export RSYNC_PASSWORD=$(echo ${_rsync_pass})
if [ "${_sync_folder}" = "_testing-${_sarch}/" ] ; then
rsync -avh --progress ${_rsync_user}@${_rsync_server}::dev/testing/$_build_arch/* ${_sync_folder}
elif [ "${_sync_folder}" = "_unstable-${_sarch}/" ] ; then
rsync -avh --progress ${_rsync_user}@${_rsync_server}::dev/unstable/$_build_arch/* ${_sync_folder}
else
rsync -avh --progress ${_rsync_user}@${_rsync_server}::${_rsync_dir}/* ${_sync_folder}
fi
}
check_files()
{
# Get the file list in the server
export RSYNC_PASSWORD=$(echo ${_rsync_pass})
if [ "${_sync_folder}" = "_testing-${_sarch}/" ] ; then
repo_files=$(rsync -avh --list-only ${_rsync_user}@${_rsync_server}::dev/testing/$_arch/* | awk -F ' ' '{print $NF}')
elif [ "${_sync_folder}" = "_unstable-${_sarch}/" ] ; then
repo_files=$(rsync -avh --list-only ${_rsync_user}@${_rsync_server}::dev/unstable/$_arch/* | awk -F ' ' '{print $NF}')
else
repo_files=$(rsync -avh --list-only ${_rsync_user}@${_rsync_server}::${_rsync_dir}/* | awk -F ' ' '{print $NF}')
fi
# Get the file list in the sync folder
local_files=$(ls -a ${_sync_folder}* | awk -F '/' '{print $NF}')
remove_list=""
for parse_file in ${local_files} ; do
file_exist="false"
for compare_file in ${repo_files} ; do
if [ "${parse_file}" = "${compare_file}" ] ; then
file_exist="true"
fi
done
if [ "${file_exist}" = "false" ] ; then
remove_list="${remove_list} ${parse_file}"
fi
done
if [ "$remove_list" != "" ] ; then
msg "The following packages in ${_sync_folder} don't exist in the sever:"
newline
echo "${remove_list}"
newline
question "Do you want to remove the package(s)? (y/n)"
while true ; do
read yn
case ${yn} in
[yY]* )
newline ;
remove_packages;
break
;;
[nN]* )
newline ;
title "The files will be keeped..." ;
newline ;
break
;;
* )
echo "Enter (y)es or (n)o"
;;
esac
done
fi
2011-02-03 18:54:20 +08:00
}
remove_packages()
{
2011-02-24 23:22:21 +08:00
# remove the package(s) from sync folder
msg "removing the packages(s) from ${_sync_folder}"
pushd $_sync_folder &>/dev/null
rm -rf ${_pkgz_to_remove}
popd &>/dev/null
2011-02-03 18:54:20 +08:00
}
sync_up()
{
2011-02-24 23:22:21 +08:00
# create new pacman database
msg "creating pacman database"
rm -rf ${_sync_folder}*.db.tar.*
pushd ${_sync_folder} &>/dev/null
if [ "${_sync_folder}" = "_testing-${_sarch}/" ] ; then
repo-add testing.db.tar.gz *.pkg.*
elif [ "${_sync_folder}" = "_unstable-${_sarch}/" ] ; then
repo-add unstable.db.tar.gz *.pkg.*
else
repo-add ${_cur_repo}.db.tar.gz *.pkg.*
fi
popd &>/dev/null
# sync local -> server, removing the packages
msg "sync local -> server"
if [ "${_sync_folder}" = "_testing-${_sarch}/" ] ; then
rsync -avh --progress --delay-updates --delete-after ${_sync_folder} ${_rsync_user}@${_rsync_server}::dev/testing/$_arch/
elif [ "${_sync_folder}" = "_unstable-${_sarch}/" ] ; then
rsync -avh --progress --delay-updates --delete-after ${_sync_folder} ${_rsync_user}@${_rsync_server}::dev/unstable/$_arch/
2011-02-03 18:54:20 +08:00
else
2011-02-24 23:22:21 +08:00
rsync -avh --progress --delay-updates --delete-after ${_sync_folder} ${_rsync_user}@${_rsync_server}::${_rsync_dir}
2011-02-03 18:54:20 +08:00
fi
}
#
# startup
#
clear
title "${_script_name} - $_cur_repo-$_build_arch"
if [ "${_args}" = "" ] ; then
2011-02-24 23:22:21 +08:00
error " !! You need to specify a target to remove,"
error " single names like \"attica\" or wildcards (*) are allowed."
newline
exit 1
2011-02-03 18:54:20 +08:00
fi
check_configs
load_configs
check_rsync
check_accounts
# First get the actual packages from the repo
sync_down
2011-02-24 23:22:21 +08:00
# Check if there's any outdated file
msg "Searching removed files"
check_files
2011-02-03 18:54:20 +08:00
# Generate the list of packages to remove
newline
_args=${_args}*
2011-02-24 23:22:21 +08:00
_pkgz_to_remove=$(ls ${_sync_folder}${_args} | awk -F '/' '{print $NF}')
2011-02-03 18:54:20 +08:00
if [ "${_pkgz_to_remove}" = "" ] ; then
2011-02-24 23:22:21 +08:00
exit
2011-02-03 18:54:20 +08:00
fi
warning "The following packages will be removed:"
newline
echo "${_pkgz_to_remove}"
newline
2011-02-24 23:22:21 +08:00
question "Do you really want to remove the package(s)? (y/n) "
2011-02-03 18:54:20 +08:00
while true ; do
2011-02-24 23:22:21 +08:00
read yn
case $yn in
[yY]* )
newline ;
remove_packages ;
sync_up ;
newline ;
title "All done" ;
newline ;
break
;;
[nN]* )
exit
;;
q* )
exit
;;
* )
echo "Enter (y)es or (n)o"
;;
esac
2011-02-03 18:54:20 +08:00
done