summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChangqing Li <changqing.li@windriver.com>2019-04-30 14:56:26 +0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-06-19 14:46:07 +0100
commit88c2fb4a0c47e759d7225cfaf574c7abdc6b1c44 (patch)
treef9d4041d73da007cf37d996f6ab30f0f399e7712
parent22e0692898c3e7ceedc8eb5ff4ec8e0b9c340b2d (diff)
downloadupdate-rc.d-88c2fb4a0c47e759d7225cfaf574c7abdc6b1c44.tar.gz
update-rc.d-88c2fb4a0c47e759d7225cfaf574c7abdc6b1c44.tar.bz2
update-rc.d-88c2fb4a0c47e759d7225cfaf574c7abdc6b1c44.zip
update-rc.d: support enable/disable options
Add support of enable/disable options, refer https://manpages.debian.org/wheezy/sysv-rc/update-rc.d.8.en.html With support of these options, the usr can never change an existing configuration even after upgrading a package. The program will only install links if none are present, otherwise, it will keep the previous configuration. preinst in update-rc.d.bbclass will delete all the links under rcrunlevel.d, this behavior now conflicts with enable/disable options. so remove preinst from the update-rc.d.bbclass [Yocto 12955] Signed-off-by: Changqing Li <changqing.li@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--update-rc.d81
1 files changed, 81 insertions, 0 deletions
diff --git a/update-rc.d b/update-rc.d
index e07cf85..a7fb7bc 100644
--- a/update-rc.d
+++ b/update-rc.d
@@ -27,6 +27,7 @@ usage()
usage: update-rc.d [-n] [-f] [-r <root>] <basename> remove
update-rc.d [-n] [-r <root>] [-s] <basename> defaults [NN | sNN kNN]
update-rc.d [-n] [-r <root>] [-s] <basename> start|stop NN runlvl [runlvl] [...] .
+ update-rc.d [-n] [-r <root>] [-s] <basename> enable|disable [S|2|3|4|5]
-n: not really
-f: force
-v: verbose
@@ -101,6 +102,53 @@ makelinks()
done
}
+# function to disable/enable init script link of one run level
+# $1 should be K/S, means to disable/enable
+# $2 means which run level to disable/enable
+renamelink()
+{
+ local oldstartstop newstartstop lev oldnn newnn
+ if [ "x$1" = "xS" ]; then
+ oldstartstop="K"
+ newstartstop="S"
+ else
+ oldstartstop="S"
+ newstartstop="K"
+ fi
+
+ lev=$2
+ # modifies existing runlevel links for the script /etc/init.d/name by renaming start links to stop link
+ # or stop link to start link with a sequence number equal to the difference of 100 minus the original sequence number.
+ if ls ${etcd}${lev}.d/${oldstartstop}*${bn} >/dev/null 2>&1; then
+ oldnn=`basename ${etcd}${lev}.d/${oldstartstop}*${bn}|cut -c2-3`
+ newnn=$[100-$oldnn]
+ [ $verbose -eq 1 ] && echo "rename ${etcd}${lev}.d/${oldstartstop}${oldnn}${bn} -> ${etcd}${lev}.d/${newstartstop}${newnn}${bn}"
+ if [ $notreally -eq 0 ];then
+ mv ${etcd}${lev}.d/${oldstartstop}${oldnn}${bn} ${etcd}${lev}.d/${newstartstop}${newnn}${bn}
+ fi
+ if [ $dostart -eq 1 ] && [ $newstartstop = "S" ] && [ $lev = $RUNLEVEL ]; then
+ $fn start || true
+ fi
+ fi
+
+}
+
+# function to disable/enable init script link
+# $1 should be K/S, means to disable/enable
+# $2 run level [S|2|3|4|5], optional, If no start runlevel is
+# specified after the disable or enable keywords
+# the script will attempt to modify links in all start runlevels
+renamelinks()
+{
+ if [ $# -eq 2 ]; then
+ renamelink $1 $2
+ else
+ for i in 2 3 4 5 S; do
+ renamelink $1 $i
+ done
+ fi
+}
+
while [ $# -gt 0 ]; do
case $1 in
-n) notreally=1
@@ -221,6 +269,13 @@ case $1 in
;;
start | stop)
+ if [ $# -lt 4 ]
+ then
+ echo "Not enough arguments"
+ usage
+ exit 1
+ fi
+
while [ $# -gt 0 ]; do
if [ $1 = "start" ]; then
letter=S
@@ -251,6 +306,32 @@ case $1 in
makelinks
;;
+ enable | disable)
+ if [ $1 = "enable" ]; then
+ letter=S
+ elif [ $1 = "disable" ]; then
+ letter=K
+ else
+ usage
+ exit 1
+ fi
+ shift
+ #
+ if [ $# -gt 0 ]
+ then
+ case $1 in
+ S|2|3|4|5)
+ renamelinks $letter $1
+ ;;
+ *)
+ usage
+ exit 1
+ ;;
+ esac
+ else
+ renamelinks $letter
+ fi
+ ;;
*)
usage
exit 1