Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: b1b4d0686e
Fetching contributors…

Cannot retrieve contributors at this time

file 86 lines (72 sloc) 2.719 kb
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
#!/bin/bash
# #
# This code is written for Lunar Linux, see #
# http://lunar-linux.org #
# #
############################################################
# #
# $FUNCTIONS/queue #
# includes add_queue and remove_queue #
# #
# 20020527 #
# #
############################################################
# #
# Copyrighted Kagan Kongar 2002 under GPLv2 #
# #
############################################################

# Definition:
# a queue is a multielement data structure from which elements
# can be removed only in the same order in which they are inserted;
# that is, it follows a FIFO constraint.

# function: add_queue
# usage : add_queue <file_name> <item_name>
# purpose : adds an item to the end of a queue

add_queue() {
  debug_msg "add_queue ($@)"
   in_queue() {
  debug_msg " in_queue ($@)"
      grep -q "^"$2"\$" "$1" && return 0 || return 1
   }

   [ "$#" -ne 2 ] && return 1

   [ -f "$1" ] || touch $1 2>/dev/null || return 1

   lock_file $1 &&
   ! in_queue $1 $2 && echo "$2" >> $1
   unlock_file $1
}

# function: remove_queue
# usage : remove_queue <file_name> |name|
# purpose : removes an item from a queue OR pops the first element from a queue

remove_queue() {
  debug_msg "remove_queue ($@)"

   [ -f "$1" ] || return 1

   if [ -n "$2" ];
   then
      TMP_QUEUE="$TMPDIR/lunar_remove_queue.$$"
      rm -f $TMP_QUEUE 2>/dev/null
      lock_file $1 &&
      cat "$1" | grep -v "^"$2"\$" > $TMP_QUEUE
      cat "$TMP_QUEUE" > $1
      unlock_file $1
      rm -f $TMP_QUEUE 2>/dev/null
   else
      lock_file $1 &&
      echo `cat "$1" | sed 1!d` &&
      cat "$1" | sed "1d" > $1 &&
      unlock_file $1
  fi
}


push_install_queue() {
  debug_msg "push_install_queue ($@)"
  remove_queue $REMOVE_QUEUE "$1"
  remove_queue $INSTALL_QUEUE "$1"
  ! module_installed "$1" &&
  add_queue $INSTALL_QUEUE "$1"
}


push_remove_queue() {
  debug_msg "push_remove_queue ($@)"
  remove_queue $INSTALL_QUEUE "$1"
  remove_queue $REMOVE_QUEUE "$1"
  module_installed "$1" &&
  add_queue $REMOVE_QUEUE "$1"
}
Something went wrong with that request. Please try again.