Skip to content

Commit

Permalink
Merge pull request #3 from circonus-labs/CIRC-5580_circpkg_ubuntu_sup…
Browse files Browse the repository at this point in the history
…port

CIRC-5580 Ubuntu support for circpkg
  • Loading branch information
esproul authored Aug 12, 2020
2 parents bf24f7b + 020dd23 commit 5abcba3
Showing 1 changed file with 42 additions and 38 deletions.
80 changes: 42 additions & 38 deletions circonus-inside/circpkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,53 @@ SUPPRESS_FILE=$OUTPUT_DIR/cpkg.wip
CACHE_MINUTES=5

suppressions() {
if [ -r $SUPPRESS_FILE ]; then
while read -r line || [[ -n "$line" ]]; do
pkg=`echo $line | awk -F= '{print $1;}'`
user=`echo $line | awk -F= '{if($2) {print $2;} else { print "unspecified"; }}'`
echo "$pkg s wip:$user"
done < $SUPPRESS_FILE
fi
if [[ -r $SUPPRESS_FILE ]]; then
while read -r line || [[ -n "$line" ]]; do
pkg=`echo $line | awk -F= '{print $1;}'`
user=`echo $line | awk -F= '{if($2) {print $2;} else { print "unspecified"; }}'`
printf "%s\ts\twip:%s\n" $pkg $user
done < $SUPPRESS_FILE
fi
}

if [ ! -d $OUTPUT_DIR ]; then
echo "error bad cache directory ($OUTPUT_DIR)"
OUTPUT_FILE=/dev/null
if [[ ! -d $OUTPUT_DIR ]]; then
printf "error\`cachedir\ts\tbad cache directory\n"
OUTPUT_FILE=/dev/null
else
find $OUTPUT_FILE -mmin +$CACHE_MINUTES -exec rm {} \; 2>/dev/null
if [ -r $OUTPUT_FILE ]; then
LMOD=`/bin/stat -c "%Y" $OUTPUT_FILE`
CTIME=`/bin/date +%s`
((AGE=$CTIME-$LMOD))
printf "cached\tl\t%d\n" $AGE
cat $OUTPUT_FILE
suppressions
exit
fi
if [ ! -w $OUTPUT_FILE ]; then
if ! touch $OUTPUT_FILE 2> /dev/null; then
echo "error cannot create cache file ($OUTPUT_FILE)"
OUTPUT_FILE=/dev/null
fi
fi
find $OUTPUT_FILE -mmin +$CACHE_MINUTES -exec rm {} \; 2>/dev/null
if [[ -r $OUTPUT_FILE ]]; then
LMOD=`/bin/stat -c "%Y" $OUTPUT_FILE`
CTIME=`/bin/date +%s`
((AGE=$CTIME-$LMOD))
printf "cached\tl\t%d\n" $AGE
cat $OUTPUT_FILE
suppressions
exit
fi
if [[ ! -w $OUTPUT_FILE ]]; then
if ! touch $OUTPUT_FILE 2> /dev/null; then
printf "error\`cachefile\ts\tcannot create cache file\n"
OUTPUT_FILE=/dev/null
fi
fi
fi

case `uname -s` in
Linux)
/bin/rpm -qa --queryformat '%{NAME}\ts\t%{VERSION}-%{RELEASE}\n' circonus* | /usr/bin/tee $OUTPUT_FILE
suppressions
;;
SunOS)
/bin/pkg list -v | /bin/perl -n -e 's#^pkg://circonus/([^@]+)@([^-]+).*$#$1\ts\t$2#g && print;' | /bin/tee $OUTPUT_FILE
suppressions
;;
*)
echo "error\ts\tunsuported platform"
exit
;;
Linux)
if [[ -f /etc/redhat-release ]]; then
# RHEL/CentOS
/bin/rpm -qa --queryformat '%{NAME}\ts\t%{VERSION}-%{RELEASE}\n' 'circonus*' | /usr/bin/tee $OUTPUT_FILE
elif [[ -f /etc/lsb-release ]]; then
# Debian/Ubuntu
/usr/bin/dpkg-query --show --showformat '${Package}\ts\t${Version}\n' 'circonus*' | /usr/bin/tee $OUTPUT_FILE
else
printf "error\`distro\ts\tunsupported Linux distro\n"
fi
suppressions
;;
*)
printf "error\`os\ts\tunsupported platform\n"
exit
;;
esac

0 comments on commit 5abcba3

Please sign in to comment.