CKIT

 

INTRO. His name is acronym of Construction Kit and takes origins from my sick imagination with the popular game Tremulous. More than one year ago I've contribuited with my friend Bash in the development of Repoman, a bash's script to handle an archlinux repository. At first moment I found Repoman comfortably and I was glad using it, but after some loops of script I started detect several issues. The first one was the resources needed, it wants CPU and bandwidth at same time and I can't guarantee both, and the second one was the modularity of the tasks. This kind of issues can't be fixed with simple mutations on the code, fixing it means rewrite the whole code. These are the reasons for which I've "invented" CKit.

 

PHILOSOPHY. His philosophy is quite simple: just build items if you need build items, just add items if you need add items. Of course you can do both the tasks with same call, but isn't always so. In building task you can specify more parameters. Which PKGBUILD to use, if you just want the local one or get it from AUR, if you want install packages after their build, if you want build as root, if you want skip integrity check and if you want build all packages without any confirm. The most important parameter is one that allow to use lists from text file, user can specify a list of packages which delete sources every loop, or get their AUR's PKGBUILD regardless from processing tasks. Script has a task to check for newest version of packages, in that way will be created a list which can be used as input for the building task and I'm proud to say that it's cool. There are three major classes of tasks: pre-processing, processing and post-processing. User must launch one task in his class at a loop. There are some rules implemented to prevent user to take jumble between classes, also if I don't wanted really rules. User should have brain with launching the tasks, and he must stick with the idea of the script and the grouping of the tasks. I've made this script for expert users that can read and understand the code, and apply improvements both for their own purpose than for a general one.

 

CODE. And finally ladies and gentleman this is CKit! Sync from git repository, we have PKGBUILD now!

   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 
 197 
 198 
 199 
 200 
 201 
 202 
 203 
 204 
 205 
 206 
 207 
 208 
 209 
 210 
 211 
 212 
 213 
 214 
 215 
 216 
 217 
 218 
 219 
 220 
 221 
 222 
 223 
 224 
 225 
 226 
 227 
 228 
 229 
 230 
 231 
 232 
 233 
 234 
 235 
 236 
 237 
 238 
 239 
 240 
 241 
 242 
 243 
 244 
 245 
 246 
 247 
 248 
 249 
 250 
 251 
 252 
 253 
 254 
 255 
 256 
 257 
 258 
 259 
 260 
 261 
 262 
 263 
 264 
 265 
 266 
 267 
 268 
 269 
 270 
 271 
 272 
 273 
 274 
 275 
 276 
 277 
 278 
 279 
 280 
 281 
 282 
 283 
 284 
 285 
 286 
 287 
 288 
 289 
 290 
 291 
 292 
 293 
 294 
 295 
 296 
 297 
 298 
 299 
 300 
 301 
 302 
 303 
 304 
 305 
 306 
 307 
 308 
 309 
 310 
 311 
 312 
 313 
 314 
 315 
 316 
 317 
 318 
 319 
 320 
 321 
 322 
 323 
 324 
 325 
 326 
 327 
 328 
 329 
 330 
 331 
 332 
 333 
 334 
 335 
 336 
 337 
 338 
 339 
 340 
 341 
 342 
 343 
 344 
 345 
 346 
 347 
 348 
 349 
 350 
 351 
 352 
 353 
 354 
 355 
 356 
 357 
 358 
 359 
 360 
 361 
 362 
 363 
 364 
 365 
 366 
 367 
 368 
 369 
 370 
 371 
 372 
 373 
 374 
 375 
 376 
 377 
 378 
 379 
 380 
 381 
 382 
 383 
 384 
 385 
 386 
 387 
 388 
 389 
 390 
 391 
 392 
 393 
 394 
 395 
 396 
 397 
 398 
 399 
 400 
 401 
 402 
 403 
 404 
 405 
 406 
 407 
 408 
 409 
 410 
 411 
 412 
 413 
 414 
 415 
 416 
 417 
 418 
 419 
 420 
 421 
 422 
 423 
 424 
 425 
 426 
 427 
 428 
 429 
 430 
 431 
 432 
 433 
 434 
 435 
 436 
 437 
 438 
 439 
 440 
 441 
 442 
 443 
 444 
 445 
 446 
 447 
 448 
 449 
 450 
 451 
 452 
 453 
 454 
 455 
 456 
 457 
 458 
 459 
 460 
 461 
 462 
 463 
 464 
 465 
 466 
 467 
 468 
 469 
 470 
 471 
 472 
 473 
 474 
 475 
 476 
 477 
 478 
 479 
 480 
 481 
 482 
 483 
 484 
 485 
 486 
 487 
 488 
 489 
 490 
 491 
 492 
 493 
 494 
 495 
 496 
 497 
 498 
 499 
 500 
 501 
 502 
 503 
 504 
 505 
 506 
 507 
 508 
 509 
 510 
 511 
 512 
 513 
 514 
 515 
 516 
 517 
 518 
 519 
 520 
 521 
 522 
 523 
 524 
 525 
 526 
 527 
 528 
 529 
 530 
 531 
 532 
 533 
 534 
 535 
 536 
 537 
 538 
 539 
 540 
 541 
 542 
 543 
 544 
 545 
 546 
 547 
 548 
 549 
 550 
 551 
 552 
 553 
 554 
 555 
 556 
 557 
 558 
 559 
 560 
 561 
 562 
 563 
 564 
 565 
 566 
 567 
 568 
 569 
 570 
 571 
 572 
 573 
 574 
 575 
 576 
 577 
 578 
 579 
 580 
 581 
 582 
 583 
 584 
 585 
 586 
 587 
 588 
 589 
 590 
 591 
 592 
 593 
 594 
 595 
 596 
 597 
 598 
 599 
 600 
 601 
 602 
 603 
 604 
 605 
 606 
 607 
 608 
 609 
 610 
 611 
 612 
 613 
 614 
 615 
 616 
 617 
 618 
 619 
 620 
 621 
 622 
 623 
 624 
 625 
 626 
 627 
 628 
 629 
 630 
 631 
 632 
 633 
 634 
 635 
 636 
 637 
 638 
 639 
 640 
 641 
 642 
 643 
 644 
 645 
 646 
 647 
 648 
 649 
 650 
 651 
 652 
 653 
 654 
 655 
 656 
 657 
 658 
 659 
 660 
 661 
 662 
 663 
 664 
 665 
 666 
 667 
 668 
 669 
 670 
 671 
 672 
 673 
 674 
 675 
 676 
 677 
 678 
 679 
 680 
 681 
 682 
 683 
 684 
 685 
 686 
 687 
 688 
 689 
 690 
 691 
 692 
 693 
 694 
 695 
 696 
 697 
 698 
 699 
 700 
 701 
 702 
 703 
 704 
 705 
 706 
 707 
 708 
 709 
 710 
 711 
 712 
 713 
 714 
 715 
 716 
 717 
 718 
 719 
 720 
 721 
 722 
 723 
 724 
 725 
 726 
 727 
 728 
 729 
 730 
 731 
 732 
 733 
 734 
 735 
 736 
 737 
 738 
 739 
 740 
 741 
 742 
 743 
 744 
 745 
 746 
 747 
 748 
 749 
 750 
 751 
 752 
 753 
 754 
 755 
 756 
 757 
 758 
 759 
 760 
 761 
 762 
 763 
 764 
 765 
 766 
 767 
 768 
 769 
 770 
 771 
 772 
 773 
 774 
 775 
 776 
 777 
 778 
 779 
 780 
 781 
 782 
 783 
 784 
 785 
 786 
 787 
 788 
 789 
 790 
 791 
 792 
 793 
 794 
 795 
 796 
 797 
 798 
 799 
 800 
 801 
 802 
 803 
 804 
 805 
 806 
 807 
 808 
 809 
 810 
 811 
 812 
 813 
#!/bin/bash
#

#  CKIT - Construction Kit - 0.531
#    An unofficial archlinux repository manager 
#    over the file transfer protocol.
#
#  Copyright (C) 2010   Dario 'Dax' Vilardi
#                       dax [at] deelab [dot] org
#
#
#  Authors:
#       Dario 'Dax' Vilardi     : bash developer
#       Luca 'Nss'              : ruby developer
#       Giovanni Scafora        : packager
#
#
#
# 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 3 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/>.
#


#################### ENVIRONMENT  ##########################

libdir=$(ruby -rrbconfig -e 'puts Config::CONFIG["sitelibdir"]')
conf="/etc/ckit/ckit.conf"

#################### /ENVIRONMENT  #########################




#################### PRIVATE INTERFACES ####################

die(){ 
    echo "$@"
    exit 1
}

get_aur_tarball(){
    pkg=$1
    cd $builddir
    url="http://aur.archlinux.org/packages/$pkg/$pkg/PKGBUILD"
    if PKGBUILD=$(wget -q -O - "$url"); then
        printf "  -> Getting $pkg from AUR... "
        if wget http://aur.archlinux.org/packages/$pkg/$pkg.tar.gz &>/dev/null; then
            echo "done"
            tar -xf "$pkg.tar.gz"
            rm $pkg.tar.gz
        else
            echo "failed"
        fi
    else 
        echo "  -> $pkg not found on AUR."
    fi
}

ftp_run(){
    # available commands: ls,put,get,delete,rmdir
    command=$1
    file=$2
    ruby -I $libdir $libdir/ruFTP.rb -H $hostname -u $user -p $pass -d $remoteroot/$arch -c $command $file
}

ftp_get_repo(){
    cd $repodir
    [[ -f $repo ]] && rm $repo
    
    echo "==> Getting db "
    ftp_checkfile $repo && ftp_run get $repo
}

ftp_put(){
    file=$1
    ftp_run put $file
}

ftp_delete(){
    file=$1
    ftp_run delete $file
}

ftp_put_repo(){
    cp "$repo" "$repo"_prev
    
    echo "==> Putting db "
    ftp_put $repo
    
    ftp_get_repo
    i=$(stat -c%s "$repo")
    j=$(stat -c%s "$repo"_prev)
    
    [[ $i = $j ]] \
        && echo "  -> Size test ok ($i)"  \
        || echo "  -> Take care: $i ~ $j! restoredb maybe needed"
}

ftp_pkg_delete(){
    pkg=$1
    found=0
    while read -r line; do
        [[ $line = */ ]] || continue
        i="${line%/}"
        repopkg=${i%-*-*}
        if [[ $repopkg == $pkg ]]; then
            found=1
            ftp_run delete $i-$arch.pkg.tar.gz
        fi
    done < <(tar ztf $repo)
    (( found == 0 )) && echo "  -> $pkg not found"
}

ftp_checkfile(){
    file=$1
    ftp_run ls '' | grep $file &>/dev/null \
        && return 0 \
        || return 1
}

lock(){
    ftp_checkfile lock.lk \
        && die "==> Repository in maintenance yet. Please wait!"
    touch $repodir/lock.lk
    echo $(whoami) - $(date) > lock.lk
    echo "==> Locking ftp to prevent jumble between maintenances"
    ftp_put $repodir/lock.lk
}

unlock(){
    echo "==> Unlocking ftp"
    ftp_delete lock.lk
    ftp_checkfile lock.lk \
        && echo "  -> Failed at unlock, remove lock.lk manually!"
    rm $repodir/lock.lk
}

post_build(){
    pkg=($1*.pkg.tar.gz)
    if [[ -s "${pkg[0]}" ]]; then
    
        echo "==> Yo, $1 done :)"
        mv $builddir/$1/$1*.pkg.tar.gz $repodir
    
        echo $1 >> /tmp/CKIT
        cat /tmp/CKIT $repodir/$buildlog > /tmp/$buildlog
        rm /tmp/CKIT
        mv /tmp/$buildlog $repodir/$buildlog
        
        # delete sources for stable packages
        if ! is_devel $1; then deletesrc_run $1; fi
 
    else
        echo "==> WTF, $1 fails at building :("
    fi
}


rmdirsrc(){
    [[ -d $builddir/$1/src ]] \
        && rm -rf $builddir/$1/src \
        && echo "  -> $builddir/$1/src removed"
}

rmsrc(){
    target=( "zip" "ZIP" "rar" "RAR" "bz2" "gz" "part" "jar" "Jar" "deb" "html" "bin" "run" "rpm" "tgz" "pk3" )
    for i in "${target[@]}"; do
        rm $builddir/$1/*$i &>/dev/null && echo "  -> $i removed"
    done
}

copy_log_to_pkgs(){
    IFS=$'\n'
    [[ -s $repodir/$1 ]] \
        && pkgs=($(< $repodir/$1)) \
        || die "==> $1 empty"
}

is_devel(){
    pkg=$1
    REGEX=".*-(svn|cvs|hg|git|bzr|darcs|dev|devel)"
    [[ "$pkg" =~ $REGEX ]] \
        && return 0 \
        || return 1
}

deletesrc_run(){
    pkg=$1
    [[ -d $builddir/$pkg ]] \
        && echo "==> Cleaning $pkg directory" \
        && rmdirsrc $pkg \
        && rmsrc $pkg
}


#################### /PRIVATE INTERFACES ###################




#################### PUBLIC INTERFACES #####################




# DELETESRC
deletesrc(){
    
    if [[ $FROMLOG == 0 ]] && (( ${#pkgs[@]} == 0 )); then 
        copy_log_to_pkgs $deletelog
    else
        (( ${#pkgs[@]} == 0 )) && die "==> Packages needed!"
    fi
    
    for pkg in "${pkgs[@]}"; do
        deletesrc_run $pkg
    done
}
# /DELETESRC



# EDITPKG
editpkg(){
    read -p "==> Package to edit: " pkg
    if [[ -d $builddir/$pkg ]]; then
        echo "==> $pkg:"
        cd $builddir/$pkg
        for file in *; do 
            [[ -f $file ]] && echo "  -> $file"
        done
        read -p "==> Which one to edit? " file
        if [[ -f $builddir/$pkg/$file ]]; then
            echo "==> Editing $pkg/$file"
            $editor "$builddir/$pkg/$file" && echo "  -> Done."
        else
            echo "==> $file not found."
        fi
    else
        echo "==> $pkg not found."
    fi  
}
# /EDITPKG


# EDITLOG
editlog(){
    echo "==> Available logs:"
    cd $repodir
    for file in *log; do
        echo "  -> $file"
    done
    read -p "==> Which one to edit? " log
    if [[ -f $repodir/$log ]]; then
        echo "==> Editing $repodir/$log"
        $editor $repodir/$log && echo "  -> Done."
    else
        echo "==> $log not found."
    fi
}
# /EDITLOG



# OWNPKG
ownpkg(){
    read -p "==> Package to own: " pkg
    if [[ -d $builddir/$pkg ]]; then
        echo "  -> Owning $pkg "
        sudo chown -R $USER $builddir/$pkg && echo "  -> Done."
    else
        echo "  -> $pkg not found."
    fi
}
# /OWNPKG



# CLEARCACHE
clearcache(){
    rm $cachedir/*
}
# /CLEARCACHE



# RESTOREDB
restoredb(){

    cd $repodir
    echo "==> Restoring db from latest backup."
    mv "$repo"_prev "$repo"
    ftp_put_repo

}
# /RESTOREDB



# CHECK
check(){

    [[ -f $repodir/$checklog ]] && rm $repodir/$checklog;
    touch $repodir/$checklog

    ftp_get_repo
    echo "==> Checking for outdated packages"


    while read -r line; do 
        
        [[ $line = */ ]] || continue
        i="${line%/}"

        pkg=${i%-*-*}
        repover=${i#$pkg-}
        
        # AUR check
        url="http://aur.archlinux.org/packages/$pkg/$pkg/PKGBUILD"
        if PKGBUILD=$(wget -q -O - "$url"); then
            aurver="$(eval "$PKGBUILD" &>/dev/null; echo "$pkgver-$pkgrel")"
        else 
            aurver="Null"
        fi
        
        # local check
        if pacman -Q $pkg &> /dev/null; then
            localver="$(LANG=C pacman -Qi "$pkg" | awk '/^Version/ {print $3}')"
        else
            localver="Null"
        fi
        
        # devel check
        if [[ $develcheck == "0" ]] && is_devel $pkg && [[ -d $builddir/$pkg ]]; then 
            cd "$builddir/$pkg" || echo "==> $pkg not available."
            # awk -v foo=something  assigns an awk variable
            # $0 being the whole line, $1 being the first field
            develver=$(makepkg -o 2>&1 | awk -v "pkg=$pkg" '$0 ~ pkg {print $6}')
            cd ~-
            version=$develver
        else
            version=$aurver
        fi
        
        # check
        result=$(vercmp "$repover" "$version")
            
        if (( "$result" < 0 )); then
            if is_devel $pkg; then
                if [[ $develcheck == "0" ]]; then
                    echo "  -> $pkg REPO:$repover LOCAL:$localver CURRENTLY:$version"
                    echo $pkg >> /tmp/CKIT
                    cat /tmp/CKIT $repodir/$checklog > /tmp/$checklog
                    rm /tmp/CKIT
                    mv /tmp/$checklog $repodir/$checklog
                fi
            else
                echo "  -> $pkg REPO:$repover LOCAL:$localver CURRENTLY:$version"
                echo $pkg >> /tmp/CKIT
                cat /tmp/CKIT $repodir/$checklog > /tmp/$checklog
                rm /tmp/CKIT
                mv /tmp/$checklog $repodir/$checklog
            fi
        fi
 
    done < <(tar ztf $repo)
    
}
# /CHECK



# UPDATEPKGBUILD
updatepkgbuild(){
    
    echo "==> Updating local PKGBUILD from AUR"
    
    (( ${#pkgs[@]} == 0 )) \
        && [[ $FROMLOG == "0" ]] \
        && copy_log_to_pkgs "$updatelog"
    
    if (( ${#pkgs[@]} == 0 )); then
    
        ftp_get_repo
        
        IFS=$'\n' read -d '' -a lines < <(tar ztf "$repo")
        for line in "${lines[@]}"; do
            [[ $line = */ ]] || continue
            i="${line%/}"
            pkg=${i%-*-*}
            read -p "  -> $pkg: update? (y/n) " answer
            [[ "$answer" == "y" ]] && get_aur_tarball "$pkg"
        done
        
    else
    
        for pkg in "${pkgs[@]}"; do
            get_aur_tarball "$pkg"
        done
        
    fi
        
}
# /UPDATEPKGBUILD



# BUILD
build(){

    # filter & replace $pkgs from checklog if asked
    if (( ${#pkgs[@]} == 0 )); then
        if [[ $FROMLOG == "0" ]]; then
            copy_log_to_pkgs "$checklog"
        else
            die "==> Nothing to build."
        fi
    fi
    

    for pkg in "${pkgs[@]}"; do
        
        sudo=""
        asroot=""
        i=""
        
        echo "==> $pkg"
        cd $builddir
        
        
        if [[ $noconfirm == "0" ]]; then
            # aur
            [[ $aur == "0" ]] && get_aur_tarball $pkg
            # root
            [[ $root == "0" ]] && sudo="sudo" && asroot="--asroot"
            # install
            [[ $install == "0" ]] && i="-i"
            # skipmd5sums
            [[ $skipmd5sums == "0" ]] && skipinteg="--skipinteg"
            # filter
            [[ ! -s $pkg/PKGBUILD ]] \
                && die "  -> PKGBUILD not found."
            # makepkg
            cd $pkg && $sudo makepkg $i -s $asroot $skipinteg
            post_build $pkg
        else
            # build?
            read -p "  -> do you want upgrade? (y/n) " answer
            if [[ "$answer" == "y" ]]; then
            
                # aur
                if [[ $aur == "0" ]]; then
                    get_aur_tarball $pkg
                else
                    read -p "  -> Do you want get tarball from AUR? (y/n) " answer
                    [[ "$answer" == "y" ]] && get_aur_tarball $pkg
                fi
                
                # root
                if [[ $root == "0" ]]; then
                    sudo="sudo"
                    asroot="--asroot"
                else
                    read -p "  -> Do you want build as root? (y/n) " answer
                    [[ "$answer" == "y" ]] && sudo="sudo" && asroot="--asroot"
                fi
                
                # install
                if [[ $install == "0" ]]; then
                    i="-i"
                else
                    read -p "  -> Do you want install package after build? (y/n) " answer
                    [[ "$answer" == "y" ]] && i="-i"
                fi
                
                # skipmd5sums
                if [[ $skipmd5sums == "0" ]]; then
                    skipinteg="--skipinteg"
                else
                    read -p "  -> Do you want skip md5sums check? (y/n) " answer
                    [[ "$answer" == "y" ]] && skipinteg="--skipinteg"
                fi
                
                # filter
                [[ ! -s $pkg/PKGBUILD ]] \
                    && die "  -> PKGBUILD not found."
                
                # makepkg
                cd $pkg && $sudo makepkg $i -s $asroot $skipinteg
                post_build $pkg
                
            fi
        fi
    
    done
    
    
    # show built packages
    copy_log_to_pkgs "$buildlog"
    echo "==> Packages waiting to be added:"
    for pkg in "${pkgs[@]}"; do
        echo "  -> $pkg"
    done
    
}
# /BUILD



# ADD
add(){

    cd $repodir
    
    # init
    [[ ! -s $repodir/$buildlog ]] \
        && die "==> Nothing to add, build packages first!"
        
    # lock ftp
    lock
    
    # get db
    ftp_get_repo
    
    # remove old packages
    echo "==> Deleting previous packages"
    copy_log_to_pkgs "$buildlog"
    for pkg in "${pkgs[@]}"; do
        ftp_pkg_delete $pkg
    done
    rm $buildlog $checklog
    
    # repo-add
    echo "==> Adding packages queued"
    for file in *.pkg.tar.gz; do 
        printf "  -> $file... "
        repo-add $repo $file &>/dev/null && \
            echo "done" || \
            echo "fail"
    done
    
    # put db
    ftp_put_repo
    
    # put new packages
    echo "==> Uploading packages"
    for file in *.pkg.tar.gz; do 
        ftp_put $file && mv $file $cachedir
    done
    
    # unlock ftp
    unlock
    
    echo "==> Repository updated! Gj, see ya."

}
# /ADD



# REMOVE
remove(){

    # init
    (( ${#pkgs[@]} == 0 )) && die "==> Packages needed!"

    cd $repodir
    
    # lock ftp
    lock
    
    ftp_get_repo
    echo "==> Removing from ftp"
    for pkg in "${pkgs[@]}"; do
        ftp_pkg_delete $pkg
    done
    
    echo "==> Removing from db"
    for pkg in "${pkgs[@]}"; do
        printf "  -> $pkg... "
        repo-remove $repo $pkg &>/dev/null \
            && echo "done" \
            || echo "failed"
    done
        
    ftp_put_repo
    
    # unlock ftp
    unlock

# /REMOVE



# DIFFREPO
diffrepo(){
    cd $repodir
    if [[ $arch == "i686" ]]; then
        ftp_get_repo
        mv $repo repo1
        arch="x86_64"
        echo "==> Temporally changing arch to $arch"
        ftp_get_repo
        mv $repo repo2
        arch="i686"
        echo "==> Restoring arch to $arch"
    else
        ftp_get_repo
        mv $repo repo1
        arch="i686"
        echo "==> Temporally changing arch to $arch"
        ftp_get_repo
        mv $repo repo2
        arch="x86_64"
        echo "==> Restoring arch to $arch"
    fi
    
    [[ -f list1 ]] && rm -f list1 
    [[ -f list2 ]] && rm -f list2
    touch list1 list2
    
    while read -r line; do
        [[ $line = */ ]] || continue
        i="${line%/}"
        pkg=${i%-*-*}
        ver=${i#$pkg-}
        echo $pkg - $ver > foo
        cat foo list1 > bar
        rm foo
        mv bar list1
    done < <(tar ztf repo1)
    
    while read -r line; do
        [[ $line = */ ]] || continue
        i="${line%/}"
        pkg=${i%-*-*}
        ver=${i#$pkg-}
        echo $pkg - $ver > foo
        cat foo list2 > bar
        rm foo
        mv bar list2
    done < <(tar ztf repo2)
    
    rm -f repo1 repo2
    
    $diff list1 list2
        
}
# /DIFFREPO


# HELP
help(){
    echo "==> CKIT - Construction KIT!"
    echo "==> Preprocessing:"
    echo "  -> -D[L] packages: delete sources from package's directory"
    echo "  -> -DL: delete sources from package's directory by deletelog"
    echo "  -> -U[L]: Update tarball from AUR"
    echo "  -> -UL: Update tarball from AUR by updatelog"
    echo "  -> -O: Own package"
    echo "  -> -E: Edit a file from package"
    echo "  -> -h: This help"
    echo "==> Processing:"
    echo "  -> -B[b][a][r][i][s][n][L] packages: build packages."
    echo "  -> -Bb: build all packages, don't need with -n"
    echo "  -> -Ba: get tarball from AUR"
    echo "  -> -Br: build as root"
    echo "  -> -Bi: install packages after builds"
    echo "  -> -Bs: skip integrity check"
    echo "  -> -Bn: don't ask confirm"
    echo "  -> -BL: build from checklog"
    echo "  -> -L: edit log files"
    echo "  -> -C[d]: check for outdated stable packages"
    echo "  -> -Cd: check for outdated stable and devel packages"
    echo "  -> -R packages: remove packages from repository"
    echo "==> Postprocessing:"
    echo "  -> -A: add built packages"
    echo "  -> -H: clear cache"
    echo "  -> -T: restore remote db from a failed upload"
    echo "  -> -X: take a view of both the repository"
}
# /HELP



#################### /PUBLIC INTERFACES ####################





#################### MAIN ##################################


# test config file
[[ ! -s $conf ]] \
        && die "==> Configuration file not found!" \
        || source $conf


# test workspaces
mkdir -p "$builddir" "$repodir" "$cachedir"


# test logs
logs=( "$buildlog" "$checklog" "$updatelog" "$deletelog" )
for log in "${logs[@]}"; do
    [[ ! -f $repodir/$log ]] && touch $repodir/$log
done


test -z "$1" && die "==> RTFM, see ya!"


# primary
ADD=1
BUILD=1
CHECK=1
REMOVE=1
BUILDFROMCHECK=1
UPDATEPKGBUILD=1
CLEARCACHE=1
RESTOREDB=1
OWNPKG=1
EDITPKG=1
DELETESRC=1
HELP=1
FROMLOG=1
DIFFREPO=1
# secondary
buildall=1
aur=1
root=1
install=1
skipmd5sums=1
noconfirm=1
develcheck=1

    
x=1         # Avoids an error if we get no options at all.
while getopts "ABarisnCdRUHLTOEDXh" opt; do
    case "$opt" in
        A) ADD=0;;
        B) BUILD=0;;
        a) aur=0;;
        r) root=0;;
        i) install=0;;
        s) skipmd5sums=0;;
        n) noconfirm=0;;
        C) CHECK=0;;
        d) develcheck=0;;
        R) REMOVE=0;;
        U) UPDATEPKGBUILD=0;;
        H) CLEARCACHE=0;;
        L) FROMLOG=0;;
        T) RESTOREDB=0;;
        O) OWNPKG=0;;
        E) EDITPKG=0;;
        D) DELETESRC=0;;
        X) DIFFREPO=0;;
        h) HELP=0;;
    esac
    x=$OPTIND
done
shift $(($x-1))
pkgs=("$@")



# rule
if [[ $REMOVE == "0" ]]; then
    [[ $BUILD == "0" ]] && die "==> Not allowed."
    [[ $RESTOREDB == "0" ]] && die "==> Not allowed."
    [[ $ADD == "0" ]] && die "==> Not allowed."
fi
[[ $DELETESRC == "0" ]] && [[ $UPDATEPKGBUILD == "0" ]] && die "==> Not allowed."


# preproccessing
[[ $FROMLOG == "0" ]] && [[ $UPDATEPKGBUILD == "1" ]] && [[ $BUILD == "1" ]] && [[ $DELETESRC == "1" ]] && editlog
[[ $UPDATEPKGBUILD == "0" ]] && updatepkgbuild
[[ $OWNPKG == "0" ]] && ownpkg
[[ $EDITPKG == "0" ]] && editpkg
[[ $DELETESRC == "0" ]] && deletesrc
[[ $HELP == "0" ]] && help


# processing
[[ $BUILD  == "0" ]] && build
[[ $CHECK == "0" ]] && check
[[ $REMOVE == "0" ]] && remove


# postprocessing
[[ $ADD  == "0" ]] && add
[[ $CLEARCACHE == "0" ]] && clearcache
[[ $RESTOREDB == "0" ]] && restoredb
[[ $DIFFREPO == "0" ]] && diffrepo



#################### /MAIN #################################

 
SEO by Artio