author | Mingrui Lyu <mingrui.lyu@oracle.com> |
Wed, 08 Mar 2017 15:08:55 -0800 | |
branch | s11u3-sru |
changeset 3526 | f34cedd88b2d |
parent 2879 | 6b5e07c2cc4e |
permissions | -rw-r--r-- |
578
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
1 |
#!/bin/ksh |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
2 |
# |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
3 |
# CDDL HEADER START |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
4 |
# |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
5 |
# The contents of this file are subject to the terms of the |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
6 |
# Common Development and Distribution License (the "License"). |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
7 |
# You may not use this file except in compliance with the License. |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
8 |
# |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
9 |
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
10 |
# or http://www.opensolaris.org/os/licensing. |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
11 |
# See the License for the specific language governing permissions |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
12 |
# and limitations under the License. |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
13 |
# |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
14 |
# When distributing Covered Code, include this CDDL HEADER in each |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
15 |
# file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
16 |
# If applicable, add the following below this CDDL HEADER, with the |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
17 |
# fields enclosed by brackets "[]" replaced with your own identifying |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
18 |
# information: Portions Copyright [yyyy] [name of copyright owner] |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
19 |
# |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
20 |
# CDDL HEADER END |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
21 |
# |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
22 |
# |
3526
f34cedd88b2d
25387863 Backport 17900980 to 11.3-SRU - update-manager crontab entry not removed
Mingrui Lyu <mingrui.lyu@oracle.com>
parents:
2879
diff
changeset
|
23 |
# Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved. |
2867
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
24 |
# |
578
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
25 |
|
2867
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
26 |
CP=/usr/bin/cp |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
27 |
CRONTAB=/usr/bin/crontab |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
28 |
DIFF=/usr/bin/diff |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
29 |
GREP=/usr/bin/grep |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
30 |
ID=/usr/bin/id |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
31 |
MKDIR=/usr/bin/mkdir |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
32 |
RM=/usr/bin/rm |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
33 |
RMDIR=/usr/bin/rmdir |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
34 |
SLEEP=/usr/bin/sleep |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
35 |
SVCADM=/usr/sbin/svcadm |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
36 |
SVCPROP=/usr/bin/svcprop |
3526
f34cedd88b2d
25387863 Backport 17900980 to 11.3-SRU - update-manager crontab entry not removed
Mingrui Lyu <mingrui.lyu@oracle.com>
parents:
2879
diff
changeset
|
37 |
PKG=/usr/bin/pkg |
578
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
38 |
|
2867
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
39 |
# |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
40 |
# Check whether the supplied exit code is 0, printing an error message |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
41 |
# if it is not, optionally either disabling an FMRI or exiting. |
645
924bfa132234
4252 SUNWipkg-gui doesn't deliver intermediate directories
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
42 |
# |
2867
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
43 |
# Usage: |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
44 |
# check_failure \ |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
45 |
# <int exit status> <error message> <fmri> <mode> |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
46 |
# |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
47 |
function check_failure { |
645
924bfa132234
4252 SUNWipkg-gui doesn't deliver intermediate directories
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
48 |
|
924bfa132234
4252 SUNWipkg-gui doesn't deliver intermediate directories
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
49 |
typeset RESULT=$1 |
924bfa132234
4252 SUNWipkg-gui doesn't deliver intermediate directories
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
50 |
typeset ERR_MSG=$2 |
2867
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
51 |
typeset FMRI=$3 |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
52 |
typeset MODE=$4 |
645
924bfa132234
4252 SUNWipkg-gui doesn't deliver intermediate directories
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
53 |
|
924bfa132234
4252 SUNWipkg-gui doesn't deliver intermediate directories
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
54 |
if [ $RESULT -ne 0 ] ; then |
2867
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
55 |
echo "Error: $ERR_MSG" |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
56 |
if [ "$MODE" = "degrade" ] ; then |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
57 |
echo "Moving service $FMRI to maintenance mode." |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
58 |
$SVCADM mark maintenance $FMRI |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
59 |
elif [ "$MODE" = "exit" ] ; then |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
60 |
exit 1 |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
61 |
fi |
645
924bfa132234
4252 SUNWipkg-gui doesn't deliver intermediate directories
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
62 |
fi |
2867
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
63 |
return $RESULT |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
64 |
} |
645
924bfa132234
4252 SUNWipkg-gui doesn't deliver intermediate directories
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
65 |
|
2867
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
66 |
# |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
67 |
# Attempt to acquire a pkg5-private lock on the current users crontab. |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
68 |
# Note that this only protects crontab from multiple callers using |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
69 |
# this function, this isn't a generic locking mechanism for cron. |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
70 |
# |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
71 |
function acquire_crontab_lock { |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
72 |
LOCK_OWNED="false" |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
73 |
UID=$($ID -u) |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
74 |
while [ "$LOCK_OWNED" == "false" ]; do |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
75 |
$MKDIR /tmp/pkg5-crontab-lock.$UID > /dev/null 2>&1 |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
76 |
if [ $? -eq 0 ]; then |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
77 |
LOCK_OWNED=true |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
78 |
else |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
79 |
$SLEEP 0.1 |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
80 |
fi |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
81 |
done |
645
924bfa132234
4252 SUNWipkg-gui doesn't deliver intermediate directories
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
82 |
} |
924bfa132234
4252 SUNWipkg-gui doesn't deliver intermediate directories
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
83 |
|
2867
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
84 |
function release_crontab_lock { |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
85 |
UID=$($ID -u) |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
86 |
$RMDIR /tmp/pkg5-crontab-lock.${UID} |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
87 |
} |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
88 |
|
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
89 |
# |
3526
f34cedd88b2d
25387863 Backport 17900980 to 11.3-SRU - update-manager crontab entry not removed
Mingrui Lyu <mingrui.lyu@oracle.com>
parents:
2879
diff
changeset
|
90 |
# Check whether the supplied pkg is installed. |
f34cedd88b2d
25387863 Backport 17900980 to 11.3-SRU - update-manager crontab entry not removed
Mingrui Lyu <mingrui.lyu@oracle.com>
parents:
2879
diff
changeset
|
91 |
# |
f34cedd88b2d
25387863 Backport 17900980 to 11.3-SRU - update-manager crontab entry not removed
Mingrui Lyu <mingrui.lyu@oracle.com>
parents:
2879
diff
changeset
|
92 |
# Usage: |
f34cedd88b2d
25387863 Backport 17900980 to 11.3-SRU - update-manager crontab entry not removed
Mingrui Lyu <mingrui.lyu@oracle.com>
parents:
2879
diff
changeset
|
93 |
# check_installation <fmri> |
f34cedd88b2d
25387863 Backport 17900980 to 11.3-SRU - update-manager crontab entry not removed
Mingrui Lyu <mingrui.lyu@oracle.com>
parents:
2879
diff
changeset
|
94 |
# |
f34cedd88b2d
25387863 Backport 17900980 to 11.3-SRU - update-manager crontab entry not removed
Mingrui Lyu <mingrui.lyu@oracle.com>
parents:
2879
diff
changeset
|
95 |
function check_installation { |
f34cedd88b2d
25387863 Backport 17900980 to 11.3-SRU - update-manager crontab entry not removed
Mingrui Lyu <mingrui.lyu@oracle.com>
parents:
2879
diff
changeset
|
96 |
|
f34cedd88b2d
25387863 Backport 17900980 to 11.3-SRU - update-manager crontab entry not removed
Mingrui Lyu <mingrui.lyu@oracle.com>
parents:
2879
diff
changeset
|
97 |
typeset PACKAGE_FMRI=$1 |
f34cedd88b2d
25387863 Backport 17900980 to 11.3-SRU - update-manager crontab entry not removed
Mingrui Lyu <mingrui.lyu@oracle.com>
parents:
2879
diff
changeset
|
98 |
$PKG list -q $PACKAGE_FMRI |
f34cedd88b2d
25387863 Backport 17900980 to 11.3-SRU - update-manager crontab entry not removed
Mingrui Lyu <mingrui.lyu@oracle.com>
parents:
2879
diff
changeset
|
99 |
return $? |
f34cedd88b2d
25387863 Backport 17900980 to 11.3-SRU - update-manager crontab entry not removed
Mingrui Lyu <mingrui.lyu@oracle.com>
parents:
2879
diff
changeset
|
100 |
} |
f34cedd88b2d
25387863 Backport 17900980 to 11.3-SRU - update-manager crontab entry not removed
Mingrui Lyu <mingrui.lyu@oracle.com>
parents:
2879
diff
changeset
|
101 |
|
f34cedd88b2d
25387863 Backport 17900980 to 11.3-SRU - update-manager crontab entry not removed
Mingrui Lyu <mingrui.lyu@oracle.com>
parents:
2879
diff
changeset
|
102 |
# |
2867
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
103 |
# Update cron with a new crontab file. We pass what we expect the |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
104 |
# current crontab looks like in order to verify that the content hasn't |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
105 |
# changed since we made our modifications. Note that between the time |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
106 |
# we check for crontab modifications, and the time we apply the new |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
107 |
# crontab entries, another program could have altered the crontab entry, |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
108 |
# this is unfortunate, but unlikely. |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
109 |
# |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
110 |
# Usage: |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
111 |
# update_crontab <current crontab> <new crontab> |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
112 |
# |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
113 |
function update_crontab { |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
114 |
|
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
115 |
typeset CURRENT_CRONTAB=$1 |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
116 |
typeset NEW_CRONTAB=$2 |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
117 |
EXIT=0 |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
118 |
CRONTAB_LOCKDIR=/tmp/pkg5-crontab-lock.$UID |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
119 |
|
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
120 |
$CRONTAB -l > $CRONTAB_LOCKDIR/actual-crontab.$$ |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
121 |
$DIFF $CRONTAB_LOCKDIR/actual-crontab.$$ - \ |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
122 |
< $CURRENT_CRONTAB 2>&1 \ |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
123 |
> /dev/null |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
124 |
if [ $? == 0 ]; then |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
125 |
$CRONTAB $NEW_CRONTAB |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
126 |
EXIT=$? |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
127 |
else |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
128 |
echo "Crontab file was modified unexpectedly!" |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
129 |
EXIT=1 |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
130 |
fi |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
131 |
$RM $CRONTAB_LOCKDIR/actual-crontab.$$ |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
132 |
return $EXIT |
645
924bfa132234
4252 SUNWipkg-gui doesn't deliver intermediate directories
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
133 |
} |
924bfa132234
4252 SUNWipkg-gui doesn't deliver intermediate directories
John Rice <john.rice@sun.com>
parents:
578
diff
changeset
|
134 |
|
2867
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
135 |
# |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
136 |
# Add a cron job to the current users crontab entry, passing the FMRI |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
137 |
# we're doing work for, the cron schedule (the first 5 fields of the |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
138 |
# crontab entry) and the command we'd like to run. |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
139 |
# We perform primitive locking around cron to protect this function from |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
140 |
# multiple processes. |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
141 |
# |
2879
6b5e07c2cc4e
16470161 add_cronjob should cope with interrupted shutdown
Tim Foster <tim.s.foster@oracle.com>
parents:
2867
diff
changeset
|
142 |
# This function assumes only a single occurrence of a given command is |
6b5e07c2cc4e
16470161 add_cronjob should cope with interrupted shutdown
Tim Foster <tim.s.foster@oracle.com>
parents:
2867
diff
changeset
|
143 |
# valid in a crontab entry: multiple instances of the same command with |
6b5e07c2cc4e
16470161 add_cronjob should cope with interrupted shutdown
Tim Foster <tim.s.foster@oracle.com>
parents:
2867
diff
changeset
|
144 |
# the same arguments, but with different schedules are not allowed. |
6b5e07c2cc4e
16470161 add_cronjob should cope with interrupted shutdown
Tim Foster <tim.s.foster@oracle.com>
parents:
2867
diff
changeset
|
145 |
# |
2867
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
146 |
# Usage: |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
147 |
# add_cronjob <fmri> <schedule> <cmd> |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
148 |
# |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
149 |
function add_cronjob { |
578
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
150 |
|
2867
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
151 |
typeset FMRI=$1 |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
152 |
typeset SCHEDULE=$2 |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
153 |
typeset CMD=$3 |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
154 |
|
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
155 |
UID=$($ID -u) |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
156 |
CRONTAB_LOCKDIR=/tmp/pkg5-crontab-lock.$UID |
578
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
157 |
|
2867
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
158 |
typeset new_crontab=$CRONTAB_LOCKDIR/pkg5-new-crontab.$$ |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
159 |
typeset current_crontab=$CRONTAB_LOCKDIR/pkg5-current-crontab.$$ |
578
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
160 |
|
2867
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
161 |
# |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
162 |
# adding a cron job is essentially just looking for an existing |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
163 |
# entry, removing it, and appending a new one. |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
164 |
# |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
165 |
acquire_crontab_lock |
2879
6b5e07c2cc4e
16470161 add_cronjob should cope with interrupted shutdown
Tim Foster <tim.s.foster@oracle.com>
parents:
2867
diff
changeset
|
166 |
$CRONTAB -l > $current_crontab |
6b5e07c2cc4e
16470161 add_cronjob should cope with interrupted shutdown
Tim Foster <tim.s.foster@oracle.com>
parents:
2867
diff
changeset
|
167 |
EXIT=0 |
6b5e07c2cc4e
16470161 add_cronjob should cope with interrupted shutdown
Tim Foster <tim.s.foster@oracle.com>
parents:
2867
diff
changeset
|
168 |
# if the crontab doesn't already contain our command, add it |
6b5e07c2cc4e
16470161 add_cronjob should cope with interrupted shutdown
Tim Foster <tim.s.foster@oracle.com>
parents:
2867
diff
changeset
|
169 |
$GREP -q "^[0-9, \*]+ $CMD"$ $current_crontab |
6b5e07c2cc4e
16470161 add_cronjob should cope with interrupted shutdown
Tim Foster <tim.s.foster@oracle.com>
parents:
2867
diff
changeset
|
170 |
if [ $? -ne 0 ]; then |
6b5e07c2cc4e
16470161 add_cronjob should cope with interrupted shutdown
Tim Foster <tim.s.foster@oracle.com>
parents:
2867
diff
changeset
|
171 |
$GREP -v " ${CMD}"$ $current_crontab > $new_crontab |
6b5e07c2cc4e
16470161 add_cronjob should cope with interrupted shutdown
Tim Foster <tim.s.foster@oracle.com>
parents:
2867
diff
changeset
|
172 |
echo "$SCHEDULE $CMD" >> $new_crontab |
578
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
173 |
|
2879
6b5e07c2cc4e
16470161 add_cronjob should cope with interrupted shutdown
Tim Foster <tim.s.foster@oracle.com>
parents:
2867
diff
changeset
|
174 |
update_crontab $current_crontab $new_crontab |
6b5e07c2cc4e
16470161 add_cronjob should cope with interrupted shutdown
Tim Foster <tim.s.foster@oracle.com>
parents:
2867
diff
changeset
|
175 |
EXIT=$? |
6b5e07c2cc4e
16470161 add_cronjob should cope with interrupted shutdown
Tim Foster <tim.s.foster@oracle.com>
parents:
2867
diff
changeset
|
176 |
$RM $new_crontab |
6b5e07c2cc4e
16470161 add_cronjob should cope with interrupted shutdown
Tim Foster <tim.s.foster@oracle.com>
parents:
2867
diff
changeset
|
177 |
fi |
6b5e07c2cc4e
16470161 add_cronjob should cope with interrupted shutdown
Tim Foster <tim.s.foster@oracle.com>
parents:
2867
diff
changeset
|
178 |
$RM $current_crontab |
2867
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
179 |
release_crontab_lock |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
180 |
|
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
181 |
return $EXIT |
578
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
182 |
} |
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
183 |
|
2867
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
184 |
# |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
185 |
# Remove a cron job from the current users crontab entry. We pass the |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
186 |
# FMRI we're doing work for, and the command we wish to remove from |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
187 |
# the crontab. If the the command does not exist in the crontab, this |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
188 |
# is treated as an error. Note that all instances of a given command |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
189 |
# are removed. |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
190 |
# |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
191 |
# Usage: |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
192 |
# remove_cronjob <fmri> <cmd> |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
193 |
# |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
194 |
function remove_cronjob { |
578
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
195 |
|
2867
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
196 |
typeset fmri=$1 |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
197 |
typeset cmd=$2 |
578
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
198 |
|
2867
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
199 |
UID=$($ID -u) |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
200 |
CRONTAB_LOCKDIR=/tmp/pkg5-crontab-lock.$UID |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
201 |
new_crontab=$CRONTAB_LOCKDIR/pkg5-new-crontab.$$ |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
202 |
current_crontab=$CRONTAB_LOCKDIR/pkg5-current-crontab.$$ |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
203 |
|
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
204 |
acquire_crontab_lock |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
205 |
$CRONTAB -l > $current_crontab |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
206 |
$GREP "${cmd}" $current_crontab > /dev/null 2>&1 |
3526
f34cedd88b2d
25387863 Backport 17900980 to 11.3-SRU - update-manager crontab entry not removed
Mingrui Lyu <mingrui.lyu@oracle.com>
parents:
2879
diff
changeset
|
207 |
if [ ! -z $fmri ]; then |
f34cedd88b2d
25387863 Backport 17900980 to 11.3-SRU - update-manager crontab entry not removed
Mingrui Lyu <mingrui.lyu@oracle.com>
parents:
2879
diff
changeset
|
208 |
check_failure $? "command $cmd did not exist in crontab" $fmri \ |
f34cedd88b2d
25387863 Backport 17900980 to 11.3-SRU - update-manager crontab entry not removed
Mingrui Lyu <mingrui.lyu@oracle.com>
parents:
2879
diff
changeset
|
209 |
degrade |
f34cedd88b2d
25387863 Backport 17900980 to 11.3-SRU - update-manager crontab entry not removed
Mingrui Lyu <mingrui.lyu@oracle.com>
parents:
2879
diff
changeset
|
210 |
fi |
578
da257532b3f2
3816 RFE UpdateManager notify users of repo updates
John Rice <john.rice@sun.com>
parents:
diff
changeset
|
211 |
|
2867
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
212 |
$GREP -v "${cmd}" $current_crontab > $new_crontab |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
213 |
|
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
214 |
update_crontab $current_crontab $new_crontab |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
215 |
EXIT=$? |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
216 |
|
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
217 |
$RM $current_crontab $new_crontab |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
218 |
release_crontab_lock |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
219 |
|
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
220 |
return $EXIT |
793902704e21
16069417 need a service to periodically update a pkg(5) repository
Tim Foster <tim.s.foster@oracle.com>
parents:
645
diff
changeset
|
221 |
} |