diff --git a/README.md b/README.md index 5a1e1eb..d73b606 100644 --- a/README.md +++ b/README.md @@ -13,5 +13,7 @@ In a nutshell: Version 1.1 is an adapted version 1, with remote repository. The idea is to replace NFS by SCP for everything related with connection to repository. +We also have a specific clearing script, which should run directly on remote server. + #### TODO -* clear function is not implemented yet +RAS diff --git a/clear-repo.sh b/clear-repo.sh new file mode 100755 index 0000000..c93c894 --- /dev/null +++ b/clear-repo.sh @@ -0,0 +1,82 @@ +#!/bin/bash + +# The purpose of this script is to clear our custom pacman repository +# i.e. remove older versions of packages +# This script should NOT be run as root. + +# Make sure that AWK rules file is present, readable and correctly set in this script's parameters + +init() { + # Only run if the user is not root + if [[ $USER = 'root' ]] ; then + echo "You cannot run this script as root!" + exit 1 + fi + if [ ! -e $repo_directory/$repo_db_file ] ; then + echo "Could not find db file. Exiting..." + exit 1 + fi + source variables.conf + echo "ArchRepo clearing script" +} + +clearRepo() { + stream=$(tar xOf $repo_directory/$repo_db_file --wildcards */desc | awk -f $awk_rules_file) + + OIFS=$IFS + IFS='|' + stream="${stream:1}" + current="" + for package in $stream + do + IFS=' +' + count=0 + for line in $package; do + if [ $count -eq 0 ]; then + current="$current $line" + else + continue + fi + + ((count++)) + done + + IFS='|' + done + IFS=$OIFS + + cd $repo_directory + reg="^($repo_name.).+" + for filename in *; do + if [[ $filename =~ $reg || $filename = 'sync' || $filename = 'local' || $filename = 'resources' ]]; then + continue + fi + for package in $current; do + if [ $filename = $package ]; then + continue 2 + fi + done + echo "Removing $filename..." + rm $filename + done +} + +run_directory_path=$(pwd) + +# Set parameters +repo_db_file=$repo_name.db.tar +repo_db_filesfile=$repo_name.files.tar +awk_rules_file='parser.awk' + +# Main process + +if [ "$1" = "" ]; then + init + clearRepo +else + echo "Please call this script without any arguments." + exit 1 +fi + +exit 0 diff --git a/update-repo.sh b/update-repo.sh index f51203b..a8be6af 100755 --- a/update-repo.sh +++ b/update-repo.sh @@ -95,8 +95,6 @@ checkUpdates() { echo "Checking for updates:" upgraded_packages="" scp $ssh_options $remote_repository/$repo_db_file $remote_repository/$repo_db_filesfile $run_directory_path/ -# scp $ssh_options $remote_repository/$repo_db_file $run_directory_path/ -# cp $run_directory_path/../$repo_db_filesfile $run_directory_path/ stream=$(tar xOf $run_directory_path/$repo_db_file --wildcards */desc | awk -f $awk_rules_file) OIFS=$IFS @@ -164,13 +162,6 @@ createPackage() { # Create package $1 aur fetch $1 # TODO This could be replaced by a git clone or even a wget+tar thanks to package-query echo "Making $1 package..." cd $1 - ## if linux-lts{414,49} then download kernel source from local repo (saves ~100MB each time) - ## WARNING this onlys works because we already have said sources AND because PKBUILD follow this particular line - ## (not the same in 419 nor 54) - #reg="(linux-lts).+" - #if [[ $1 =~ $reg ]]; then - #sed -i -e "s/\"https:\/\/www.kernel.org\/pub\/linux\/kernel\/v4.x\/\${_srcname}.tar.xz\"/\"https:\/\/archlinux.kto.black\/resources\/\${_srcname}.tar.xz\"/g" ./PKGBUILD - #fi makepkg -s --noconfirm --noprogressbar cd $run_directory_path } @@ -195,54 +186,9 @@ clean() { echo "Done." } -clearRepo() { - stream=$(tar xOf $repo_directory/$repo_db_file --wildcards */desc | awk -f $awk_rules_file) - - OIFS=$IFS - IFS='|' - stream="${stream:1}" - current="" - for package in $stream - do - IFS=' -' - count=0 - for line in $package; do - if [ $count -eq 0 ]; then - current="$current $line" - else - continue - fi - - ((count++)) - done - - IFS='|' - done - IFS=$OIFS - - cd $repo_directory - reg="^($repo_name.).+" - for filename in *; do - if [[ $filename =~ $reg || $filename = 'sync' || $filename = 'local' || $filename = 'resources' ]]; then - continue - fi - for package in $current; do - if [ $filename = $package ]; then - continue 2 - fi - done - echo "Removing $filename..." - rm $filename - done - -} - run_directory_path=$(pwd) # Set parameters -repo_directory='/mnt/archrepo' -repo_name='kto' repo_db_file=$repo_name.db.tar repo_db_filesfile=$repo_name.files.tar awk_rules_file='../parser.awk' @@ -257,15 +203,6 @@ elif [ "$1" = "add" ]; then addPackage $2 elif [ "$1" = "clean" ]; then clean -elif [ "$1" = "clear" ]; then - read -r -p "Are you sure? [y/N] " response - response=${response,,} # tolower - if [[ "$response" =~ ^(yes|y)$ ]]; then - clearRepo - else - echo "Cancelling... Perhaps did you mean 'clean', which empties the local build directory?" - exit 1 - fi else exit 1 fi diff --git a/variables.conf.template b/variables.conf.template index bfd0375..9239efb 100644 --- a/variables.conf.template +++ b/variables.conf.template @@ -2,8 +2,14 @@ # Copy this file as variables.conf, with the correct values +# For both update and clear scripts: +repo_name="" + +# For update script: remote_repository="" ssh_key="" -ssh_options="" - +ssh_options="-i $ssh_key" exlist="" + +# For clear script: +repo_directory=""