How detect launch NSIS installer with arguments - nsis

I have NSIS installer.
How detect launch NSIS installer with arguments?
For example installer.exe /DEBUG

GetOptions:
!include FileFunc.nsh
!include LogicLib.nsh
Function .onInit
${GetParameters} $0
ClearErrors
${GetOptions} $0 "/DEBUG" $1
${IfNot} ${Errors}
MessageBox mb_ok "Debug"
${EndIf}
FunctionEnd

Related

Rename files with different suffixes with only one new suffix

I am trying to modify a pipeline for viral taxonomy analysis. In this pipeline, the variables R1 and R2 are the two input paired-end fastq files. But theses files can be .fastq.gz or .fq.gz. After trimming of these fastq files with the program Trimgalore, the pipeline is coded to rename them by removing the suffix and adding an other. The pipeline can treat only .fq.gz files for the moment:
mv `basename $R1 .fq.gz`_val_1.fq $trimmedR1
mv `basename $R2 .fq.gz`_val_2.fq $trimmedR2
and I am trying to correct it:
#Command to execute:
if [[ "$R1" == *.fq.gz ]]
then
mv `basename $R1 .fq.gz`_val_1.fq $trimmedR1
mv `basename $R2 .fq.gz`_val_2.fq $trimmedR2
else
mv `basename $R1 .fastq.gz`_val_1.fq $trimmedR1
mv `basename $R2 .fastq.gz`_val_2.fq $trimmedR2
fi
but my command above is not correct and I don't know why. I also tried to use the command basename -a but it didn't work too. Thanks in advance to help me correct my code.

Best way to deal with passing arguments to nested script calls and creating a effective menu driven cli

I am writing a central script, which acts as a menu driven cli through which I trigger other scripts based on the input.
#!/bin/bash
echo "Server Name - `hostname`"
echo "-------------------------------"
echo " M A I N - M E N U"
echo "-------------------------------"
echo "1. init"
echo "2. insert"
echo "3. show"
echo "4. update"
echo "5. rm"
echo "6. ls"
echo "7. shutdown -> shutdown the server"
while :
do
printf '> '
read -r varname
set -- $varname
case $1 in
init)
./init.sh $2
echo $status
;;
insert)
./insert.sh $2 $3 '' $4
;;
show)
./show.sh $2 $3
;;
update)
./insert.sh $2 $3 'f' $4
;;
rm)
./rm.sh $2 $3
;;
ls)
./ls.sh $2 $3
;;
shutdown)
exit 0
;;
exit)
exit 0
;;
*)
#echo "Error: Bad request"
;;
esac
done
Current:
I have purposefully added the print '> ' statement so as to get an interactive interface just like node cli.
insert user1 google 'login:blahblah#gmail.com\npass:blah'
$1 is insert
$2 is user1
$3 is google
$4 is 'login:blahblah#gmail.com\npass:blah'
Expected:
I wish to read arguments the same way we pass arguments when we run a script.
Ex:
sh add.sh 10 20
or
sh add.sh "10" "20"
Either way when we read $1 or $2 in the add shell script, we will be getting 10 and 20 as their values.
insert user1 google 'login:blahblah#gmail.com\npass:blah'
$1 is insert
$2 is user1
$3 is google
$4 is login:blahblah#gmail.com\npass:blah
I do not want to get the input and then remove the trailing quotes. I would like to have the exact behaviour when we run a script and pass arguments.
PS: Please suggest how to get a cli just like node too which has access to previously run commands using the Up arrow.
Thanks in advance
The central idea here seems to revolve around these lines:
read -r varname
set -- $varname
The read command reads a whole line of input as literal text (without the possibility of line continuation) and records it as the value of variable varname, then that variable is expanded to provide arguments to the set builtin. But this is not equivalent to presenting the same command line as shell input.
Of particular relevance to the question is that quotation marks arising from variable expansion are not subject to quote removal. Also, brace and tilde expansion happen prior to variable expansion, so they will not be effective for you either.
What you really seem to want is a double expansion. Specifically, this:
eval "set -- $varname"
Do note that eval is very dangerous and subject to exploitation. For example, consider what would happen a user enters this command into your script (which is supposed running with sufficient privilege to perform a system shutdown):
show pwned; rm -rf /*

unrecognized service for my init.d

here is my full code, I just use following code:
case "$1" in
st)
echo 450 > /sys/class/backlight/intel_backlight
;;
stop)
echo
;;
rst)
echo; echo 450 > /sys/class/backlight/intel_backlight
;;
*)
echo "Usage: $0 {st|stop|rst}"
exit 1
;;
esac
why it raise this error
the reason is my init.d file has not "x" permission, so I need first chmod 755 /etc/init.d/brightness before running it
You may want to consider base your init script on the skeleton which live in /etc/init.d. Your script is probably inpcomplete.

Desktop file not executing command

I have this simple command to check if a file exists:
if [ -f /tmp/file.txt ] ; then echo "yes" ; else echo "no" ; fi
If I run it direcly on terminal, it works (shows "yes" if the file exists and "no" if it doesn't). But I want to execute this command inside a .desktop file using it as a value to Exec key:
[Desktop Entry]
Version=1.0
Type=Application
Exec=if [ -f /tmp/file.txt ] ; then echo "yes" ; else echo "no" ; fi
StartupNotify=true
Terminal=false
Categories=Utility;X-XFCE;X-Xfce-Toplevel;
MimeType=x-scheme-handler/custom
Name=Custom Test
Comment=Custom
If I try to execute xdg-open custom:// I get custom://: error opening location: The specified location is not supported, but if I change Exec value to echo "yes" and execute xdg-open custom://, it shows yes on terminal.
What am I missing here?
You are trying to execute shell script coding in .desktop file which is not supported.
The reason why "echo yes" worked is .desktop executes the echo command with paramter as "yes" which is acceptable.
.desktop executes commands along with options and parameters. You can write the shell script code in a .sh file and mentioned it in Exec or Run the code using
Exec=sh -c "if [ -f /tmp/file.txt ] ; then echo 'yes' ; else echo 'no' ; fi"
Here .desktop executes "sh" with options and params
Try setting your Exec to:
bash -c 'if [ -f /tmp/file.txt ] ; then echo "yes" ; else echo "no" ; fi'
The 'if' command is a bash-builtin, not an external command.

NSIS restrict folder installation

I have a NSIS installer I am working on that I need to be able to prevent installation to the "user error" folders (i.e. $SYSDIR, $WINDIR, $DESKTOP etc... )
I want them to be able to chose a installation path but just have the next button be disabled if they chose a location as listed above. I have searched everywhere and can't find an answer to this one.
I was trying to use this but I can still install to desktop:
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE MyDirLeave
!insertmacro MUI_PAGE_DIRECTORY
...
Function MyDirLeave
Push $0
StrLen $0 $DESKTOP
StrCpy $0 $INSTDIR $0
StrCmp $0 $DESKTOP 0 proceed
MessageBox MB_ICONSTOP|MB_OK \
"Installation on DESKTOP is not allowed, choose another directory"
Abort
proceed:
Pop $0
FunctionEnd
Use the .onVerifyInstDir callback function.
Edit:
Function .onVerifyInstDir
StrLen $0 $Desktop
StrCpy $0 $INSTDIR $0
StrCmp $0 $Desktop 0 PathGood
Abort
PathGood:
FunctionEnd

Resources