Commit 18a3b799 authored by Manuel's avatar Manuel

New version with GUI

parent 595b516c
......@@ -4,19 +4,20 @@
# maintainer: abveritas[at]chakra-project[dot]org>
pkgname=mirror-check
pkgver=0.4
pkgver=1.0
pkgrel=1
pkgdesc="Checks whether the locally used mirror is synced with the main"
arch=('x86_64')
url="http://www.chakra-project.org"
license=('GPL2')
makedepends=('asciidoc')
source=('mirror-check')
md5sums=('65df3a0a6f4cfbdab679f8e82f4cb666')
source=('mirror-check' 'mirror-check.desktop')
md5sums=('28197d03788026282f8cb01e6081f713'
'5a0a0a1774ecd4808827e4c3cd6eca7c')
package() {
cd ${srcdir}
install -m 755 -D mirror-check "$pkgdir/usr/bin/mirror-check"
install -Dm644 "${srcdir}/mirror-check.desktop" "${pkgdir}/usr/share/applications/mirror-check.desktop"
}
#!/bin/bash
# Check if a mirror is synced
# Usage:
# mirror-check checks all repos
# mirror-check [REPOS...] checks repos given in REPOS
#
# Chakra Mirror-Check - Version 1.0
# Copyright (c) 2013 - Manuel Tortosa <manutortosa@chakra-project.org>
#
# This script is licensed under the GPLv3
if [[ "$#" == "0" ]]; then
repos="$(cat /etc/pacman.conf | grep -v "#" | grep -v "options" | grep "\[" | cut -d[ -f2 | cut -d] -f1 | uniq | sed "{:q;N;s/\n/ /g;t q}")"
else
repos=($*)
fi
echo -e "\e[01;33mChecking ${repos[@]}...\e[00m"
echo " "
for repo in ${repos[@]}; do
mirror="$(grep '^[^#]erver' /etc/pacman.d/mirrorlist |
head -1 | cut -d' ' -f3 |
sed 's,$repo.*,'"$repo/x86_64/${repo}.db.tar.gz,")"
wget -qO /tmp/.${UID}mirrordb.tmp "$mirror"
cmirror="http://chakra-project.org/repo/$repo/x86_64/${repo}.db.tar.gz"
wget -qO /tmp/.${UID}maindb.tmp "$cmirror"
_title="Mirror-Check"
_repos="$(cat /etc/pacman.conf | grep -v "#" | grep -v "options" | grep "\[" | cut -d[ -f2 | cut -d] -f1 | uniq | sed "{:q;N;s/\n/ /g;t q}")"
_parse=""
_count=0
_errors=""
_mode=$(echo ${1})
function select_dialog() {
local repo=""
local repostring=""
for repo in ${_repos[@]}; do
repostring="${repostring} ${repo} ${repo} on "
((_count++))
done
_parse=$(kdialog --title "${_title}" --checklist "Repositories being checked:" ${repostring})
_parse=$(echo ${_parse} | sed 's/"//g')
}
function get_database() {
# Get databases
local mirror="$(grep '^[^#]erver' /etc/pacman.d/mirrorlist | head -1 | cut -d' ' -f3 |sed 's,$repo.*,'"${1}/x86_64/${1}.db.tar.gz,")"
wget -qO /tmp/.${UID}mirrordb.tmp "$mirror"
local cmirror="http://chakra-project.org/repo/${1}/x86_64/${1}.db.tar.gz"
wget -qO /tmp/.${UID}maindb.tmp "$cmirror"
}
function progress_dialog() {
local repo=""
local count=1
local mirror=""
local cmirror=""
local dbusRef=$(kdialog --title "${_title}" --progressbar "Initializing..." ${_count})
for repo in $_parse; do
qdbus $dbusRef Set "" value $count &>/dev/null
qdbus $dbusRef setLabelText "Checking repository: ${repo}" &>/dev/null
((count++))
get_database "${repo}"
if [[ $? != 0 ]]; then
echo "Repo '$repo' could not be found" >&2
continue
_errors=$(echo -e "${_errors} <strong>[${repo}]</strong> could not be found.<br />")
else
md5sum -b /tmp/.${UID}mirrordb.tmp | sed 's/mirror/main/' > /tmp/.${UID}checkmd5.tmp
md5sum -c /tmp/.${UID}checkmd5.tmp >/dev/null 2>/dev/null ||
_errors=$(echo -e "${_errors} <strong>[${repo}]</strong> is not synced.<br />")
fi
done
qdbus $dbusRef close &>/dev/null
}
function results_dialog(){
if [ "${_errors}" != "" ]; then
kdialog --title "${_title}" --sorry "Warning:<br /><br />${_errors}" &>/dev/null
else
kdialog --title "${_title}" --msgbox "Success. Checked mirrors are synced." &>/dev/null
fi
}
function cli_mode() {
echo " "
if [ ! -f "/etc/pacman.conf" ]; then
echo -e "\e[00;31mError. Could not find '/etc/pacman.conf'\e[00m"
echo " "
exit
fi
echo -e "\e[01;33mChecking ${_repos[@]}...\e[00m"
echo " "
for repo in ${_repos[@]}; do
get_database "${repo}"
if [[ $? != 0 ]]; then
echo "Repo '$repo' could not be found" >&2
continue
fi
md5sum -b /tmp/.${UID}mirrordb.tmp | sed 's/mirror/main/' > /tmp/.${UID}checkmd5.tmp
md5sum -c /tmp/.${UID}checkmd5.tmp >/dev/null 2>/dev/null &&
echo -e "\e[01;37m[$repo]\e[00m \e[00;32mis synced\e[00m." ||
echo -e "\e[01;37m[$repo]\e[00m \e[00;31mis not synced\e[00m."
#echo "$repo is not synced."
done
echo " "
done
echo " "
}
if [ "${_mode}" == "--gui" ]; then
if [ ! -f "/etc/pacman.conf" ]; then
kdialog --title "${_title}" --error "Error. Could not find '/etc/pacman.conf'" &>/dev/null
exit
fi
select_dialog
if [ "${_parse}" != "" ]; then
progress_dialog
results_dialog
fi
elif [ "${_mode}" == "--help" ]; then
echo "${_title}"
echo " "
echo "Usage: mirror-check <flag>"
echo " "
echo "--cli Command Line Interface mode (default)"
echo "--gui KDialog GUI"
echo "--help This message"
echo " "
else
cli_mode
fi
\ No newline at end of file
#!/bin/bash
[Desktop Entry]
Type=Application
Version=2.0
Name=MIrror-Check
Icon=network-server-database
Exec=/usr/bin/mirror-check --gui
Categories=Network;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment