Skip to contentSkip to conversation

update-rc.d: support enable/disable function

PATCH Superseded [email protected] 1 participant 5 messages Nov 9, 2018 – Dec 27, 2018

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 update-rc.d: support enable/disable function

From: Changqing Li <[email protected]>

Add support of enable/disable function, so that user can keep previous config after upgrade package

---
 update-rc.d | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)
update-rc.d +70 -0
index e07cf85..1ba97d3 100644
@@ -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,43 @@ makelinks()
 	done
 }
 
+renamelink()
+{
+	local oldstartstop newstartstop lev oldnn newnn
+	if [ "x$1" = "xS" ]; then
+		oldstartstop="K"
+		newstartstop="S"
+	else
+		oldstartstop="S"
+		newstartstop="K"
+	fi
+
+	lev=$2
+	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
+
+}
+
+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 +259,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 +296,31 @@ 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
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/1 ref-variables.xml: update manual page for update-rc.d

From: Changqing Li <[email protected]>

Currently, yocto doc refer link http://www.tin.org/bin/man.cgi?
section=8&topic=update-rc.d. as man page of update-rc.d, but lastest debian udpate-rc.d have big difference with ours, they need insserv and all the initscripts support LSB comment header.

change to new link which is more similar to ours.

---
 documentation/ref-manual/ref-variables.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
documentation/ref-manual/ref-variables.xml +1 -1
index 595f2db..fc7e087 100644
@@ -7116,7 +7116,7 @@ recipes-graphics/xorg-font/font-alias_1.0.3.bb:PR = "${INC_PR}.3"
                     to the <filename>update-rc.d</filename> command.
                     For more information on valid parameters, please see the
                     <filename>update-rc.d</filename> manual page at
-                    <ulink url='http://www.tin.org/bin/man.cgi?section=8&amp;topic=update-rc.d'></ulink>.
+                    <ulink url='https://manpages.debian.org/wheezy/sysv-rc/update-rc.d.8.en.html'></ulink>.
                 </para>
             </glossdef>
         </glossentry>
Signature · 1 line
2.7.4
#2 lore raw
In reply to [email protected]

Ping

Quoted 112 lines · On 11/9/18 5:44 PM, [email protected] wrote:

From: Changqing Li <[email protected]>

Add support of enable/disable function, so that user can keep previous config after upgrade package

---
  update-rc.d | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 70 insertions(+)
update-rc.d +70 -0
index e07cf85..1ba97d3 100644
@@ -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,43 @@ makelinks()
  	done
  }
 
+renamelink()
+{
+	local oldstartstop newstartstop lev oldnn newnn
+	if [ "x$1" = "xS" ]; then
+		oldstartstop="K"
+		newstartstop="S"
+	else
+		oldstartstop="S"
+		newstartstop="K"
+	fi
+
+	lev=$2
+	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
+
+}
+
+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 +259,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 +296,31 @@ 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
Signature · 3 lines
BRs

Sandy(Li Changqing)
#3 lore raw

ping

Quoted 119 lines · Changqing Li

Ping

Quoted 115 lines · On 11/9/18 5:44 PM, [email protected] wrote:

From: Changqing Li <[email protected]>

Add support of enable/disable function, so that user can keep previous config after upgrade package

---
  update-rc.d | 70
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

  1 file changed, 70 insertions(+)
update-rc.d +0 -0
index e07cf85..1ba97d3 100644
@@ -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

update-rc.d +0 -0
@@ -101,6 +102,43 @@ makelinks()

      done
  }
  +renamelink()

update-rc.d +15 -1
+{
+    local oldstartstop newstartstop lev oldnn newnn
+    if [ "x$1" = "xS" ]; then
+        oldstartstop="K"
+        newstartstop="S"
+    else
+        oldstartstop="S"
+        newstartstop="K"
+    fi
+
+    lev=$2
+    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

update-rc.d +14 -0
+
+}
+
+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

update-rc.d +7 -0
@@ -221,6 +259,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

update-rc.d +0 -0
@@ -251,6 +296,31 @@ 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

Signature · 3 lines
BRs

Sandy(Li Changqing)
#4 lore raw

Ping

Quoted 122 lines · Changqing Li

ping

Quoted 119 lines · Changqing Li

Ping

Quoted 115 lines · On 11/9/18 5:44 PM, [email protected] wrote:

From: Changqing Li <[email protected]>

Add support of enable/disable function, so that user can keep previous config after upgrade package

---
  update-rc.d | 70
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

  1 file changed, 70 insertions(+)
update-rc.d +0 -0
index e07cf85..1ba97d3 100644
@@ -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

update-rc.d +0 -0
@@ -101,6 +102,43 @@ makelinks()

      done
  }
  +renamelink()

update-rc.d +15 -1
+{
+    local oldstartstop newstartstop lev oldnn newnn
+    if [ "x$1" = "xS" ]; then
+        oldstartstop="K"
+        newstartstop="S"
+    else
+        oldstartstop="S"
+        newstartstop="K"
+    fi
+
+    lev=$2
+    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

update-rc.d +14 -0
+
+}
+
+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

update-rc.d +7 -0
@@ -221,6 +259,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

update-rc.d +0 -0
@@ -251,6 +296,31 @@ 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

Signature · 3 lines
BRs

Sandy(Li Changqing)