# vim:sts=4:sw=4: ############################################################################ ############################################################################ ############################ This file is in P4 ############################ ############################################################################ ############################################################################ # $Id: //depot/ops/corp/grhat/scripts/Makefile.changeset#12 $ # Target location is /software/grhat/targets/ FILES=$(shell find files -type f 2>/dev/null) P4GRHAT=/home/$(LOGNAME)/src/ops/corp/grhat UPDNAME=$(shell basename `pwd`) UPDFILE=$(P4GRHAT)/updates/$(UPDNAME) all: checkp4runme workfiles.tar.bz2 runme done testroot: @if [ $$UID -eq 0 ]; then echo "You can't be root"; exit 1; fi @echo "Please type your password to seed sudo" @sudo echo @echo "Password received or not needed, continuing..." checkfiles: testroot # sudo is for files like ~root/.ssh/authorized_keys, non readable by users @find ../ -type f | grep /files/ | sudo xargs md5sum | sed 's/\.\.\/.*\/files\///' | sort +1 -u > /tmp/files.tree @find $(P4GRHAT)/tree -type f | xargs md5sum | sed "s/`echo $(P4GRHAT) | sed 's/\//\\\\\//g'`\/tree\///" | sort +1 > /tmp/p4.tree @diff -u /tmp/p4.tree /tmp/files.tree > /tmp/p4tofiles.diff; exit 0 @/bin/rm /tmp/p4.tree /tmp/files.tree @cat /tmp/p4tofiles.diff checkp4runme: testroot @if [ ! -f $(UPDFILE) ]; then echo "$(UPDFILE) missing in your p4 directory"; exit 1; fi runme: testroot $(UPDFILE) @sudo touch runme @echo "Checking if $(UPDFILE) is checked in" @cd $(P4GRHAT)/updates || exit 1; \ if [ `p4 diff $(UPDNAME) | wc -l` -gt 1 ]; then \ echo -e '\E[42m'; \ echo "Warning, $(UPDNAME) is different from the p4 copy"; \ p4 diff -du $(UPDNAME); \ echo "Type ENTER to continue with a file different from the p4 copy or ^C to quit"; \ echo -e '\E[40m'; \ read; \ fi @echo "Checking if $(UPDFILE) is up to date with p4" @cd $(P4GRHAT)/updates || exit 1; \ if [ `p4 sync -n $(UPDNAME) | wc -l` -gt 0 ]; then \ echo -e '\E[42m'; \ echo "WARNING, $(UPDNAME)"; \ echo "is not up to date with the p4 version"; \ echo "Are you really _REALLY_ sure you want to push this file?"; \ echo "Type ENTER to continue or ^C to quit"; \ echo -e '\E[40m'; \ read; \ fi @if cmp $@ $(UPDFILE) &>/dev/null; then \ echo "$@ up to date"; \ else \ echo "Updating $@"; \ diff -u runme $(UPDFILE) | less; \ echo "Type ENTER to confirm; ^C to quit"; read || exit 1; \ cp -f $(UPDFILE) /tmp || exit 1; \ echo 'Work around over-restrictive umask' >/dev/null ; \ cp -f $(UPDFILE) /tmp || exit 1; \ chmod o=g /tmp/$(UPDNAME) || exit 1; \ chmod o-w /tmp/$(UPDNAME) || exit 1; \ sudo mv -f /tmp/$(UPDNAME) runme || exit 1; \ sudo chown root.root runme || exit 1; \ fi workfiles.tar.bz2: testroot updatefiles @sudo chown -R root.root files @echo "Rebuilding $@" @sudo tar cjf $@ files done: @echo -e "You can type make checkfiles to make sure all files in the p4 tree are in your\nchangesets (but they may not be for some tags/targets like srvgold)\n" @echo "Consider typing make newdate if you want to force clients to re-pull this update" newdate: @sudo bash -c "date '+%s' > updatedate" @echo "Done" updatefiles: testroot $(FILES) @echo @echo "Checking that files in runme are in files/" # grep -v ' \\$$' removes installfile /foo $VAR, which can't be checked @IFS=" "; for file in `grep ^installfile runme | grep -v '/*$$' | grep -v ' \\$$' | sed -e "s/installfile //" -e 's/ *$$//' -e "s/.* \([^ ]* [^ ]*\)/\1/" -e "s/ /\//" -e "s/'\*'/*/" -e "s/^\///"`; \ do \ if [ ! -e files/$$file ]; then \ echo -e "$$file missing, type the following to create it:\nmake files/$$file; make"; \ exit 1; \ fi \ done files/%: $(P4GRHAT)/tree/% @echo "Checking if $? is checked in" @cd $(P4GRHAT) || exit 1; \ if [ `p4 diff $? | wc -l` -gt 1 ]; then \ echo "Warning, $? is different from the p4 copy"; \ p4 diff -du $?; \ echo "Type ENTER to continue with a file different from the p4 copy or ^C to quit"; \ read; \ fi @echo "Checking if $? is up to date with p4" @cd $(P4GRHAT) || exit 1; \ if [ `p4 sync -n $? | wc -l` -gt 0 ]; then \ echo -e '\E[42m'; \ echo "WARNING, $?"; \ echo "is not up to date with the p4 version"; \ echo "Are you really _REALLY_ sure you want to push this file?"; \ echo "Type ENTER to continue or ^C to quit"; \ echo -e '\E[40m'; \ read; \ fi @echo "Updating $@" @P4FILE=$(P4GRHAT)/tree/`echo $@|sed "s/^files//"`; \ if [ -f $@ ]; then \ if ! cmp $@ $$P4FILE; then \ diff -u $@ $$P4FILE | less; \ echo "Type ENTER to confirm; ^C to quit"; read; \ else \ echo -e "make had a bogus dependency on $@\nbecause your p4 files look more recent then the /software ones, updating date"; \ fi; \ else \ echo "$@ is a new file, installing..."; \ fi @cp -f $(P4GRHAT)/tree/`echo $@|sed "s/^files//"` /tmp @-sudo mkdir -p `echo $@ | sed "s/$$(basename $@)//"` 2>/dev/null @sudo mv -f /tmp/`basename $@` $@ # Work around over-restrictive umask @sudo chmod o=g $@ @sudo chmod o-w $@ @sudo chown root.root $@