fwts-frontend: v2 update to conditional logic to better detect if we're booted via casper and additional logic to toggle auto shutdown behaviour when testing

Message ID 1327678316-25528-1-git-send-email-vanhoof@canonical.com
State Accepted
Headers show

Commit Message

Chris Van Hoof Jan. 27, 2012, 3:31 p.m.
* v2 use $EUID vs id to check for uid.

Signed-off-by: Chris Van Hoof <vanhoof@canonical.com>
---
 live-image/fwts-frontend-text |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)

Comments

Chris Van Hoof Jan. 27, 2012, 3:48 p.m. | #1
These changes are available in the git repository at:
 git://kernel.ubuntu.com/vanhoof/fwts.git live-image

... I'll toss these into the commit message next time around.

Thanks!

--chris

On 01/27/2012 10:31 AM, Chris Van Hoof wrote:
> * v2 use $EUID vs id to check for uid.
> 
> Signed-off-by: Chris Van Hoof <vanhoof@canonical.com>
> ---
>  live-image/fwts-frontend-text |   19 ++++++++++++++++---
>  1 files changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/live-image/fwts-frontend-text b/live-image/fwts-frontend-text
> index dbf6635..fabdfb2 100755
> --- a/live-image/fwts-frontend-text
> +++ b/live-image/fwts-frontend-text
> @@ -25,12 +25,21 @@ FWTS_DATE=`date +%d%m%Y`
>  FWTS_TIME=`date +%H%M`
>  
>  #
> +# Check if executed as root or with sudo
> +#
> +if [ $EUID -ne 0 ]; then
> +	echo "`basename $0`: must be executed with sudo"
> +	exit 1
> +fi
> +
> +#
>  # for debugging, use:
>  # -  WORK_DIR=./fwts/$FWTS_DATE/$FWTS_TIME
>  # if booting in fwts-live
>  # - change FWTS_AUTO_SHUTDOWN= to alter default shutdown after testing completion
>  #
>  WORK_DIR=/fwts/$FWTS_DATE/$FWTS_TIME
> +FWTS_AUTO_SHUTDOWN="$1"
>  SHUTDOWN_AT_END=1
>  
>  #
> @@ -42,10 +51,14 @@ if [ `grep -qs boot=casper /proc/cmdline; echo $?` -eq 0 ]; then
>  fi
>  
>  #
> -# check /proc/cmdline for FWTS_AUTO_SHUTDOWN to toggle auto shutdown
> +# check /proc/cmdline and argv[1] for FWTS_AUTO_SHUTDOWN to toggle auto shutdown
>  #
> -if [ `grep -qs FWTS_AUTO_SHUTDOWN=1 /proc/cmdline; echo $?` -ne 0 -a $CASPER_DETECTED -eq 1 ]; then
> -	SHUTDOWN_AT_END=0
> +if [ `grep -qs FWTS_AUTO_SHUTDOWN=1 /proc/cmdline; echo $?` -ne 0 ]; then
> +	if [ -n "${CASPER_DETECTED:+x}" ]; then
> +		SHUTDOWN_AT_END=0
> +	elif [ -n "${FWTS_AUTO_SHUTDOWN:+x}" ]; then
> +		SHUTDOWN_AT_END=0
> +	fi
>  fi
>  
>  do_help()
Colin King Jan. 27, 2012, 7:06 p.m. | #2
On 27/01/12 15:31, Chris Van Hoof wrote:
> * v2 use $EUID vs id to check for uid.
>
> Signed-off-by: Chris Van Hoof<vanhoof@canonical.com>
> ---
>   live-image/fwts-frontend-text |   19 ++++++++++++++++---
>   1 files changed, 16 insertions(+), 3 deletions(-)
>
> diff --git a/live-image/fwts-frontend-text b/live-image/fwts-frontend-text
> index dbf6635..fabdfb2 100755
> --- a/live-image/fwts-frontend-text
> +++ b/live-image/fwts-frontend-text
> @@ -25,12 +25,21 @@ FWTS_DATE=`date +%d%m%Y`
>   FWTS_TIME=`date +%H%M`
>
>   #
> +# Check if executed as root or with sudo
> +#
> +if [ $EUID -ne 0 ]; then
> +	echo "`basename $0`: must be executed with sudo"
> +	exit 1
> +fi
> +
> +#
>   # for debugging, use:
>   # -  WORK_DIR=./fwts/$FWTS_DATE/$FWTS_TIME
>   # if booting in fwts-live
>   # - change FWTS_AUTO_SHUTDOWN= to alter default shutdown after testing completion
>   #
>   WORK_DIR=/fwts/$FWTS_DATE/$FWTS_TIME
> +FWTS_AUTO_SHUTDOWN="$1"
>   SHUTDOWN_AT_END=1
>
>   #
> @@ -42,10 +51,14 @@ if [ `grep -qs boot=casper /proc/cmdline; echo $?` -eq 0 ]; then
>   fi
>
>   #
> -# check /proc/cmdline for FWTS_AUTO_SHUTDOWN to toggle auto shutdown
> +# check /proc/cmdline and argv[1] for FWTS_AUTO_SHUTDOWN to toggle auto shutdown
>   #
> -if [ `grep -qs FWTS_AUTO_SHUTDOWN=1 /proc/cmdline; echo $?` -ne 0 -a $CASPER_DETECTED -eq 1 ]; then
> -	SHUTDOWN_AT_END=0
> +if [ `grep -qs FWTS_AUTO_SHUTDOWN=1 /proc/cmdline; echo $?` -ne 0 ]; then
> +	if [ -n "${CASPER_DETECTED:+x}" ]; then
> +		SHUTDOWN_AT_END=0
> +	elif [ -n "${FWTS_AUTO_SHUTDOWN:+x}" ]; then
> +		SHUTDOWN_AT_END=0
> +	fi
>   fi
>
>   do_help()

Yep, looks good to me.

Acked-by: Colin King <colin.king@canonical.com>
Keng-Yu Lin Jan. 30, 2012, 9:49 a.m. | #3
On Fri, Jan 27, 2012 at 11:31 PM, Chris Van Hoof <vanhoof@canonical.com> wrote:
> * v2 use $EUID vs id to check for uid.
>
> Signed-off-by: Chris Van Hoof <vanhoof@canonical.com>
> ---
>  live-image/fwts-frontend-text |   19 ++++++++++++++++---
>  1 files changed, 16 insertions(+), 3 deletions(-)
>
> diff --git a/live-image/fwts-frontend-text b/live-image/fwts-frontend-text
> index dbf6635..fabdfb2 100755
> --- a/live-image/fwts-frontend-text
> +++ b/live-image/fwts-frontend-text
> @@ -25,12 +25,21 @@ FWTS_DATE=`date +%d%m%Y`
>  FWTS_TIME=`date +%H%M`
>
>  #
> +# Check if executed as root or with sudo
> +#
> +if [ $EUID -ne 0 ]; then
> +       echo "`basename $0`: must be executed with sudo"
> +       exit 1
> +fi
> +
> +#
>  # for debugging, use:
>  # -  WORK_DIR=./fwts/$FWTS_DATE/$FWTS_TIME
>  # if booting in fwts-live
>  # - change FWTS_AUTO_SHUTDOWN= to alter default shutdown after testing completion
>  #
>  WORK_DIR=/fwts/$FWTS_DATE/$FWTS_TIME
> +FWTS_AUTO_SHUTDOWN="$1"
>  SHUTDOWN_AT_END=1
>
>  #
> @@ -42,10 +51,14 @@ if [ `grep -qs boot=casper /proc/cmdline; echo $?` -eq 0 ]; then
>  fi
>
>  #
> -# check /proc/cmdline for FWTS_AUTO_SHUTDOWN to toggle auto shutdown
> +# check /proc/cmdline and argv[1] for FWTS_AUTO_SHUTDOWN to toggle auto shutdown
>  #
> -if [ `grep -qs FWTS_AUTO_SHUTDOWN=1 /proc/cmdline; echo $?` -ne 0 -a $CASPER_DETECTED -eq 1 ]; then
> -       SHUTDOWN_AT_END=0
> +if [ `grep -qs FWTS_AUTO_SHUTDOWN=1 /proc/cmdline; echo $?` -ne 0 ]; then
> +       if [ -n "${CASPER_DETECTED:+x}" ]; then
> +               SHUTDOWN_AT_END=0
> +       elif [ -n "${FWTS_AUTO_SHUTDOWN:+x}" ]; then
> +               SHUTDOWN_AT_END=0

Hope I understand this correctly: this means when executing
fwts-frontend-text plus anything in argv[1] it does not shut down the
machine in the end.

But what is this used for if we can change the auto-shutdown behaviour
with FWTS_AUTO_SHUTDOWN in cmdline?

From the source-level, when $FWTS_AUTO_SHUTDOWN has a value,
SHUTDOWN_AT_END=0. Shall it be named by FWTS_NO_AUTO_SHUTDOWN instead?
Chris Van Hoof Jan. 30, 2012, 3:10 p.m. | #4
On 01/30/2012 04:49 AM, Keng-Yü Lin wrote:
> On Fri, Jan 27, 2012 at 11:31 PM, Chris Van Hoof <vanhoof@canonical.com> wrote:
>> * v2 use $EUID vs id to check for uid.
>>
>> Signed-off-by: Chris Van Hoof <vanhoof@canonical.com>
>> ---
>>  live-image/fwts-frontend-text |   19 ++++++++++++++++---
>>  1 files changed, 16 insertions(+), 3 deletions(-)
>>
>> diff --git a/live-image/fwts-frontend-text b/live-image/fwts-frontend-text
>> index dbf6635..fabdfb2 100755
>> --- a/live-image/fwts-frontend-text
>> +++ b/live-image/fwts-frontend-text
>> @@ -25,12 +25,21 @@ FWTS_DATE=`date +%d%m%Y`
>>  FWTS_TIME=`date +%H%M`
>>
>>  #
>> +# Check if executed as root or with sudo
>> +#
>> +if [ $EUID -ne 0 ]; then
>> +       echo "`basename $0`: must be executed with sudo"
>> +       exit 1
>> +fi
>> +
>> +#
>>  # for debugging, use:
>>  # -  WORK_DIR=./fwts/$FWTS_DATE/$FWTS_TIME
>>  # if booting in fwts-live
>>  # - change FWTS_AUTO_SHUTDOWN= to alter default shutdown after testing completion
>>  #
>>  WORK_DIR=/fwts/$FWTS_DATE/$FWTS_TIME
>> +FWTS_AUTO_SHUTDOWN="$1"
>>  SHUTDOWN_AT_END=1
>>
>>  #
>> @@ -42,10 +51,14 @@ if [ `grep -qs boot=casper /proc/cmdline; echo $?` -eq 0 ]; then
>>  fi
>>
>>  #
>> -# check /proc/cmdline for FWTS_AUTO_SHUTDOWN to toggle auto shutdown
>> +# check /proc/cmdline and argv[1] for FWTS_AUTO_SHUTDOWN to toggle auto shutdown
>>  #
>> -if [ `grep -qs FWTS_AUTO_SHUTDOWN=1 /proc/cmdline; echo $?` -ne 0 -a $CASPER_DETECTED -eq 1 ]; then
>> -       SHUTDOWN_AT_END=0
>> +if [ `grep -qs FWTS_AUTO_SHUTDOWN=1 /proc/cmdline; echo $?` -ne 0 ]; then
>> +       if [ -n "${CASPER_DETECTED:+x}" ]; then
>> +               SHUTDOWN_AT_END=0
>> +       elif [ -n "${FWTS_AUTO_SHUTDOWN:+x}" ]; then
>> +               SHUTDOWN_AT_END=0
> 
> Hope I understand this correctly: this means when executing
> fwts-frontend-text plus anything in argv[1] it does not shut down the
> machine in the end.

Correct argv[1] is just a flag to toggle SHUTDOWN_AT_END when testing
the script, without having to edit it.

> But what is this used for if we can change the auto-shutdown behaviour
> with FWTS_AUTO_SHUTDOWN in cmdline?

FWTS_AUTO_SHUTDOWN= is used at boot in fwts-live to toggle the same
behaviour since /usr/bin/fwts-frontend-text is read-only in a casper
only boot environment, and the script is automatically executed upon
boot, so you have no time to pass argv[1] before it executes.

> From the source-level, when $FWTS_AUTO_SHUTDOWN has a value,
> SHUTDOWN_AT_END=0. Shall it be named by FWTS_NO_AUTO_SHUTDOWN instead?

I'm happy with how things are named now, but if you think
FWTS_NO_AUTO_SHUTDOWN is a more clean approach, I'm happy to go that route.

--chris
Colin King Feb. 9, 2012, 11:36 a.m. | #5
On 30/01/12 15:10, Chris Van Hoof wrote:
> On 01/30/2012 04:49 AM, Keng-Yü Lin wrote:
>> On Fri, Jan 27, 2012 at 11:31 PM, Chris Van Hoof<vanhoof@canonical.com>  wrote:
>>> * v2 use $EUID vs id to check for uid.
>>>
>>> Signed-off-by: Chris Van Hoof<vanhoof@canonical.com>
>>> ---
>>>   live-image/fwts-frontend-text |   19 ++++++++++++++++---
>>>   1 files changed, 16 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/live-image/fwts-frontend-text b/live-image/fwts-frontend-text
>>> index dbf6635..fabdfb2 100755
>>> --- a/live-image/fwts-frontend-text
>>> +++ b/live-image/fwts-frontend-text
>>> @@ -25,12 +25,21 @@ FWTS_DATE=`date +%d%m%Y`
>>>   FWTS_TIME=`date +%H%M`
>>>
>>>   #
>>> +# Check if executed as root or with sudo
>>> +#
>>> +if [ $EUID -ne 0 ]; then
>>> +       echo "`basename $0`: must be executed with sudo"
>>> +       exit 1
>>> +fi
>>> +
>>> +#
>>>   # for debugging, use:
>>>   # -  WORK_DIR=./fwts/$FWTS_DATE/$FWTS_TIME
>>>   # if booting in fwts-live
>>>   # - change FWTS_AUTO_SHUTDOWN= to alter default shutdown after testing completion
>>>   #
>>>   WORK_DIR=/fwts/$FWTS_DATE/$FWTS_TIME
>>> +FWTS_AUTO_SHUTDOWN="$1"
>>>   SHUTDOWN_AT_END=1
>>>
>>>   #
>>> @@ -42,10 +51,14 @@ if [ `grep -qs boot=casper /proc/cmdline; echo $?` -eq 0 ]; then
>>>   fi
>>>
>>>   #
>>> -# check /proc/cmdline for FWTS_AUTO_SHUTDOWN to toggle auto shutdown
>>> +# check /proc/cmdline and argv[1] for FWTS_AUTO_SHUTDOWN to toggle auto shutdown
>>>   #
>>> -if [ `grep -qs FWTS_AUTO_SHUTDOWN=1 /proc/cmdline; echo $?` -ne 0 -a $CASPER_DETECTED -eq 1 ]; then
>>> -       SHUTDOWN_AT_END=0
>>> +if [ `grep -qs FWTS_AUTO_SHUTDOWN=1 /proc/cmdline; echo $?` -ne 0 ]; then
>>> +       if [ -n "${CASPER_DETECTED:+x}" ]; then
>>> +               SHUTDOWN_AT_END=0
>>> +       elif [ -n "${FWTS_AUTO_SHUTDOWN:+x}" ]; then
>>> +               SHUTDOWN_AT_END=0
>>
>> Hope I understand this correctly: this means when executing
>> fwts-frontend-text plus anything in argv[1] it does not shut down the
>> machine in the end.
>
> Correct argv[1] is just a flag to toggle SHUTDOWN_AT_END when testing
> the script, without having to edit it.
>
>> But what is this used for if we can change the auto-shutdown behaviour
>> with FWTS_AUTO_SHUTDOWN in cmdline?
>
> FWTS_AUTO_SHUTDOWN= is used at boot in fwts-live to toggle the same
> behaviour since /usr/bin/fwts-frontend-text is read-only in a casper
> only boot environment, and the script is automatically executed upon
> boot, so you have no time to pass argv[1] before it executes.
>
>>  From the source-level, when $FWTS_AUTO_SHUTDOWN has a value,
>> SHUTDOWN_AT_END=0. Shall it be named by FWTS_NO_AUTO_SHUTDOWN instead?
>
> I'm happy with how things are named now, but if you think
> FWTS_NO_AUTO_SHUTDOWN is a more clean approach, I'm happy to go that route.

I've no opinion either way. I'm happy enough as it stands.

Colin
>
> --chris
>
>
>
Chris Van Hoof Feb. 10, 2012, 9:19 p.m. | #6
On 02/09/2012 06:36 AM, Colin Ian King wrote:
> On 30/01/12 15:10, Chris Van Hoof wrote:
>> On 01/30/2012 04:49 AM, Keng-Yü Lin wrote:
>>> On Fri, Jan 27, 2012 at 11:31 PM, Chris Van
>>> Hoof<vanhoof@canonical.com> wrote:
>>>> * v2 use $EUID vs id to check for uid.
>>>>
>>>> Signed-off-by: Chris Van Hoof<vanhoof@canonical.com>
>>>> ---
>>>> live-image/fwts-frontend-text | 19 ++++++++++++++++---
>>>> 1 files changed, 16 insertions(+), 3 deletions(-)
>>>>
>>>> diff --git a/live-image/fwts-frontend-text
>>>> b/live-image/fwts-frontend-text
>>>> index dbf6635..fabdfb2 100755
>>>> --- a/live-image/fwts-frontend-text
>>>> +++ b/live-image/fwts-frontend-text
>>>> @@ -25,12 +25,21 @@ FWTS_DATE=`date +%d%m%Y`
>>>> FWTS_TIME=`date +%H%M`
>>>>
>>>> #
>>>> +# Check if executed as root or with sudo
>>>> +#
>>>> +if [ $EUID -ne 0 ]; then
>>>> + echo "`basename $0`: must be executed with sudo"
>>>> + exit 1
>>>> +fi
>>>> +
>>>> +#
>>>> # for debugging, use:
>>>> # - WORK_DIR=./fwts/$FWTS_DATE/$FWTS_TIME
>>>> # if booting in fwts-live
>>>> # - change FWTS_AUTO_SHUTDOWN= to alter default shutdown after
>>>> testing completion
>>>> #
>>>> WORK_DIR=/fwts/$FWTS_DATE/$FWTS_TIME
>>>> +FWTS_AUTO_SHUTDOWN="$1"
>>>> SHUTDOWN_AT_END=1
>>>>
>>>> #
>>>> @@ -42,10 +51,14 @@ if [ `grep -qs boot=casper /proc/cmdline; echo
>>>> $?` -eq 0 ]; then
>>>> fi
>>>>
>>>> #
>>>> -# check /proc/cmdline for FWTS_AUTO_SHUTDOWN to toggle auto shutdown
>>>> +# check /proc/cmdline and argv[1] for FWTS_AUTO_SHUTDOWN to toggle
>>>> auto shutdown
>>>> #
>>>> -if [ `grep -qs FWTS_AUTO_SHUTDOWN=1 /proc/cmdline; echo $?` -ne 0
>>>> -a $CASPER_DETECTED -eq 1 ]; then
>>>> - SHUTDOWN_AT_END=0
>>>> +if [ `grep -qs FWTS_AUTO_SHUTDOWN=1 /proc/cmdline; echo $?` -ne 0
>>>> ]; then
>>>> + if [ -n "${CASPER_DETECTED:+x}" ]; then
>>>> + SHUTDOWN_AT_END=0
>>>> + elif [ -n "${FWTS_AUTO_SHUTDOWN:+x}" ]; then
>>>> + SHUTDOWN_AT_END=0
>>>
>>> Hope I understand this correctly: this means when executing
>>> fwts-frontend-text plus anything in argv[1] it does not shut down the
>>> machine in the end.
>>
>> Correct argv[1] is just a flag to toggle SHUTDOWN_AT_END when testing
>> the script, without having to edit it.
>>
>>> But what is this used for if we can change the auto-shutdown behaviour
>>> with FWTS_AUTO_SHUTDOWN in cmdline?
>>
>> FWTS_AUTO_SHUTDOWN= is used at boot in fwts-live to toggle the same
>> behaviour since /usr/bin/fwts-frontend-text is read-only in a casper
>> only boot environment, and the script is automatically executed upon
>> boot, so you have no time to pass argv[1] before it executes.
>>
>>> From the source-level, when $FWTS_AUTO_SHUTDOWN has a value,
>>> SHUTDOWN_AT_END=0. Shall it be named by FWTS_NO_AUTO_SHUTDOWN instead?
>>
>> I'm happy with how things are named now, but if you think
>> FWTS_NO_AUTO_SHUTDOWN is a more clean approach, I'm happy to go that
>> route.
>
> I've no opinion either way. I'm happy enough as it stands.

acks? :D
Keng-Yu Lin Feb. 13, 2012, 9:08 a.m. | #7
On Sat, Feb 11, 2012 at 5:19 AM, Chris Van Hoof <vanhoof@canonical.com> wrote:
> On 02/09/2012 06:36 AM, Colin Ian King wrote:
>>
>> On 30/01/12 15:10, Chris Van Hoof wrote:
>>>
>>> On 01/30/2012 04:49 AM, Keng-Yü Lin wrote:
>>>>
>>>> On Fri, Jan 27, 2012 at 11:31 PM, Chris Van
>>>> Hoof<vanhoof@canonical.com> wrote:
>>>>>
>>>>> * v2 use $EUID vs id to check for uid.
>>>>>
>>>>> Signed-off-by: Chris Van Hoof<vanhoof@canonical.com>
>>>>> ---
>>>>> live-image/fwts-frontend-text | 19 ++++++++++++++++---
>>>>> 1 files changed, 16 insertions(+), 3 deletions(-)
>>>>>
>>>>> diff --git a/live-image/fwts-frontend-text
>>>>> b/live-image/fwts-frontend-text
>>>>> index dbf6635..fabdfb2 100755
>>>>> --- a/live-image/fwts-frontend-text
>>>>> +++ b/live-image/fwts-frontend-text
>>>>> @@ -25,12 +25,21 @@ FWTS_DATE=`date +%d%m%Y`
>>>>> FWTS_TIME=`date +%H%M`
>>>>>
>>>>> #
>>>>> +# Check if executed as root or with sudo
>>>>> +#
>>>>> +if [ $EUID -ne 0 ]; then
>>>>> + echo "`basename $0`: must be executed with sudo"
>>>>> + exit 1
>>>>> +fi
>>>>> +
>>>>> +#
>>>>> # for debugging, use:
>>>>> # - WORK_DIR=./fwts/$FWTS_DATE/$FWTS_TIME
>>>>> # if booting in fwts-live
>>>>> # - change FWTS_AUTO_SHUTDOWN= to alter default shutdown after
>>>>> testing completion
>>>>> #
>>>>> WORK_DIR=/fwts/$FWTS_DATE/$FWTS_TIME
>>>>> +FWTS_AUTO_SHUTDOWN="$1"
>>>>> SHUTDOWN_AT_END=1
>>>>>
>>>>> #
>>>>> @@ -42,10 +51,14 @@ if [ `grep -qs boot=casper /proc/cmdline; echo
>>>>> $?` -eq 0 ]; then
>>>>> fi
>>>>>
>>>>> #
>>>>> -# check /proc/cmdline for FWTS_AUTO_SHUTDOWN to toggle auto shutdown
>>>>> +# check /proc/cmdline and argv[1] for FWTS_AUTO_SHUTDOWN to toggle
>>>>> auto shutdown
>>>>> #
>>>>> -if [ `grep -qs FWTS_AUTO_SHUTDOWN=1 /proc/cmdline; echo $?` -ne 0
>>>>> -a $CASPER_DETECTED -eq 1 ]; then
>>>>> - SHUTDOWN_AT_END=0
>>>>> +if [ `grep -qs FWTS_AUTO_SHUTDOWN=1 /proc/cmdline; echo $?` -ne 0
>>>>> ]; then
>>>>> + if [ -n "${CASPER_DETECTED:+x}" ]; then
>>>>> + SHUTDOWN_AT_END=0
>>>>> + elif [ -n "${FWTS_AUTO_SHUTDOWN:+x}" ]; then
>>>>> + SHUTDOWN_AT_END=0
>>>>
>>>>
>>>> Hope I understand this correctly: this means when executing
>>>> fwts-frontend-text plus anything in argv[1] it does not shut down the
>>>> machine in the end.
>>>
>>>
>>> Correct argv[1] is just a flag to toggle SHUTDOWN_AT_END when testing
>>> the script, without having to edit it.
>>>
>>>> But what is this used for if we can change the auto-shutdown behaviour
>>>> with FWTS_AUTO_SHUTDOWN in cmdline?
>>>
>>>
>>> FWTS_AUTO_SHUTDOWN= is used at boot in fwts-live to toggle the same
>>> behaviour since /usr/bin/fwts-frontend-text is read-only in a casper
>>> only boot environment, and the script is automatically executed upon
>>> boot, so you have no time to pass argv[1] before it executes.
>>>
>>>> From the source-level, when $FWTS_AUTO_SHUTDOWN has a value,
>>>> SHUTDOWN_AT_END=0. Shall it be named by FWTS_NO_AUTO_SHUTDOWN instead?
>>>
>>>
>>> I'm happy with how things are named now, but if you think
>>> FWTS_NO_AUTO_SHUTDOWN is a more clean approach, I'm happy to go that
>>> route.
>>
>>
>> I've no opinion either way. I'm happy enough as it stands.
>
>
> acks? :D

Acked-by: Keng-Yu Lin <kengyu@canonical.com>
Colin King Feb. 13, 2012, 4:52 p.m. | #8
On 10/02/12 23:37, Chris Van Hoof wrote:
> I've tested this, it works -- I totally missed that this didnt make the
> fwts upload today :\ ... mind giving it an ack if you're cool with it?
>
> -------- Original Message --------
> Subject: Re: [PATCH] fwts-frontend: v2 update to conditional logic to
> better detect if we're booted via casper and additional logic to toggle
> auto shutdown behaviour when testing
> Date: Fri, 10 Feb 2012 16:19:02 -0500
> From: Chris Van Hoof <vanhoof@canonical.com>
> To: Colin Ian King <colin.king@canonical.com>
> CC: fwts-devel@lists.ubuntu.com
>
> On 02/09/2012 06:36 AM, Colin Ian King wrote:
>> On 30/01/12 15:10, Chris Van Hoof wrote:
>>> On 01/30/2012 04:49 AM, Keng-Yü Lin wrote:
>>>> On Fri, Jan 27, 2012 at 11:31 PM, Chris Van
>>>> Hoof<vanhoof@canonical.com> wrote:
>>>>> * v2 use $EUID vs id to check for uid.
>>>>>
>>>>> Signed-off-by: Chris Van Hoof<vanhoof@canonical.com>
>>>>> ---
>>>>> live-image/fwts-frontend-text | 19 ++++++++++++++++---
>>>>> 1 files changed, 16 insertions(+), 3 deletions(-)
>>>>>
>>>>> diff --git a/live-image/fwts-frontend-text
>>>>> b/live-image/fwts-frontend-text
>>>>> index dbf6635..fabdfb2 100755
>>>>> --- a/live-image/fwts-frontend-text
>>>>> +++ b/live-image/fwts-frontend-text
>>>>> @@ -25,12 +25,21 @@ FWTS_DATE=`date +%d%m%Y`
>>>>> FWTS_TIME=`date +%H%M`
>>>>>
>>>>> #
>>>>> +# Check if executed as root or with sudo
>>>>> +#
>>>>> +if [ $EUID -ne 0 ]; then
>>>>> + echo "`basename $0`: must be executed with sudo"
>>>>> + exit 1
>>>>> +fi
>>>>> +
>>>>> +#
>>>>> # for debugging, use:
>>>>> # - WORK_DIR=./fwts/$FWTS_DATE/$FWTS_TIME
>>>>> # if booting in fwts-live
>>>>> # - change FWTS_AUTO_SHUTDOWN= to alter default shutdown after
>>>>> testing completion
>>>>> #
>>>>> WORK_DIR=/fwts/$FWTS_DATE/$FWTS_TIME
>>>>> +FWTS_AUTO_SHUTDOWN="$1"
>>>>> SHUTDOWN_AT_END=1
>>>>>
>>>>> #
>>>>> @@ -42,10 +51,14 @@ if [ `grep -qs boot=casper /proc/cmdline; echo
>>>>> $?` -eq 0 ]; then
>>>>> fi
>>>>>
>>>>> #
>>>>> -# check /proc/cmdline for FWTS_AUTO_SHUTDOWN to toggle auto shutdown
>>>>> +# check /proc/cmdline and argv[1] for FWTS_AUTO_SHUTDOWN to toggle
>>>>> auto shutdown
>>>>> #
>>>>> -if [ `grep -qs FWTS_AUTO_SHUTDOWN=1 /proc/cmdline; echo $?` -ne 0
>>>>> -a $CASPER_DETECTED -eq 1 ]; then
>>>>> - SHUTDOWN_AT_END=0
>>>>> +if [ `grep -qs FWTS_AUTO_SHUTDOWN=1 /proc/cmdline; echo $?` -ne 0
>>>>> ]; then
>>>>> + if [ -n "${CASPER_DETECTED:+x}" ]; then
>>>>> + SHUTDOWN_AT_END=0
>>>>> + elif [ -n "${FWTS_AUTO_SHUTDOWN:+x}" ]; then
>>>>> + SHUTDOWN_AT_END=0
>>>>
>>>> Hope I understand this correctly: this means when executing
>>>> fwts-frontend-text plus anything in argv[1] it does not shut down the
>>>> machine in the end.
>>>
>>> Correct argv[1] is just a flag to toggle SHUTDOWN_AT_END when testing
>>> the script, without having to edit it.
>>>
>>>> But what is this used for if we can change the auto-shutdown behaviour
>>>> with FWTS_AUTO_SHUTDOWN in cmdline?
>>>
>>> FWTS_AUTO_SHUTDOWN= is used at boot in fwts-live to toggle the same
>>> behaviour since /usr/bin/fwts-frontend-text is read-only in a casper
>>> only boot environment, and the script is automatically executed upon
>>> boot, so you have no time to pass argv[1] before it executes.
>>>
>>>> From the source-level, when $FWTS_AUTO_SHUTDOWN has a value,
>>>> SHUTDOWN_AT_END=0. Shall it be named by FWTS_NO_AUTO_SHUTDOWN instead?
>>>
>>> I'm happy with how things are named now, but if you think
>>> FWTS_NO_AUTO_SHUTDOWN is a more clean approach, I'm happy to go that
>>> route.
>>
>> I've no opinion either way. I'm happy enough as it stands.
>
> acks? :D
>

Acked by: Colin King <colin.king@canonical.com>

Patch

diff --git a/live-image/fwts-frontend-text b/live-image/fwts-frontend-text
index dbf6635..fabdfb2 100755
--- a/live-image/fwts-frontend-text
+++ b/live-image/fwts-frontend-text
@@ -25,12 +25,21 @@  FWTS_DATE=`date +%d%m%Y`
 FWTS_TIME=`date +%H%M`
 
 #
+# Check if executed as root or with sudo
+#
+if [ $EUID -ne 0 ]; then
+	echo "`basename $0`: must be executed with sudo"
+	exit 1
+fi
+
+#
 # for debugging, use:
 # -  WORK_DIR=./fwts/$FWTS_DATE/$FWTS_TIME
 # if booting in fwts-live
 # - change FWTS_AUTO_SHUTDOWN= to alter default shutdown after testing completion
 #
 WORK_DIR=/fwts/$FWTS_DATE/$FWTS_TIME
+FWTS_AUTO_SHUTDOWN="$1"
 SHUTDOWN_AT_END=1
 
 #
@@ -42,10 +51,14 @@  if [ `grep -qs boot=casper /proc/cmdline; echo $?` -eq 0 ]; then
 fi
 
 #
-# check /proc/cmdline for FWTS_AUTO_SHUTDOWN to toggle auto shutdown
+# check /proc/cmdline and argv[1] for FWTS_AUTO_SHUTDOWN to toggle auto shutdown
 #
-if [ `grep -qs FWTS_AUTO_SHUTDOWN=1 /proc/cmdline; echo $?` -ne 0 -a $CASPER_DETECTED -eq 1 ]; then
-	SHUTDOWN_AT_END=0
+if [ `grep -qs FWTS_AUTO_SHUTDOWN=1 /proc/cmdline; echo $?` -ne 0 ]; then
+	if [ -n "${CASPER_DETECTED:+x}" ]; then
+		SHUTDOWN_AT_END=0
+	elif [ -n "${FWTS_AUTO_SHUTDOWN:+x}" ]; then
+		SHUTDOWN_AT_END=0
+	fi
 fi
 
 do_help()