SHC converted shell 'Breaks' on system reboot - bash

I am making a public image on AWS and so am required to 'hide' some shell scripts, but still have them freely usable. We're not looking for the utmost security, I understand SHC can be reverted if a user actually wishes to do so, but it's enough for my requirement.
So that's all good! I have a shell, 'test.sh'. I convert it, 'shc -f test.sh'. The output is a .x and a .x.c file. I run './test.sh.x' - It runs exactly as I expect it to.
So far so good...
But if at any point I reboot the instance, then when I try and run './test.sh.x' again it fails and just outputs a load of random binary stuff.
I have absolutely zero idea what is causing this or why it is causing this. The file is not being edited, or moved, or anything.. It just suddenly does not work anymore. Why?? I've searched online but can't seem to find anyone having this same issue, so any help will be massively appreciated.
And to note, a valid alternative that may not result in the same issue (worth testing at least) is most welcome, as I'm not dead-set on using SHC specifically, it's just the only one I know about currently.

Oooookay, well I unfortunately was never able to fix this issue. Even if I install SHC after I create an instance from my own AMI, and then compile the scripts at this point, the scripts only work until I reboot the system and then they no longer work.
So instead I found a different solution using Bash-Obfuscator, installed and run as follows:
dnf -y install npm nodejs
npm install -g bash-obfuscate
bash-obfuscate test_input.sh -o test_output.sh
And that perfectly does what I needed. There was, however, one thing I quickly learned using Bash-Obfuscator which was quite important - Do NOT have 'echo' commands across multiple lines as it will break your script. The following will break when obfuscated using this command:
echo "Hello
World"
But replacing that with this (which is practically the same thing) works perfectly okay (must be some way the parser is coded):
TEST_VAR="Hello
World"
echo "${TEST_VAR}"
Hope this helps anyone in future.

Related

mkfs.vfat and mkfs.ext3 in CYGWIN

I'm running a bash script in the Embedded Command Line that comes with Quartus II. The bash script was sent to me from someone using linux and I was able to get most of the script to work(removing sudo, changing path, etc.). The only two commands that are still giving me errors are mkfs.ext3 and mkfs.vfat. Are these tucked away somewhere in cygwin that I need to add a path or is there another workaround? I've read some people use mkdofsf but cygwin doesn't appear to have that either.
UPDATE:
Tried using /sbin/mkfs - t vfat and /sbin/mkfs -t ext3 but this left me with a similiar error where mkfs.vfat and mkfs.ext3 were not found.
UPDATE 2: Installed e2fsprogs to solve the error with mkfs.ext3 but this doesn't solve the vfat formatting issue.
These are part of the package e2fsprogs which is available in Cygwin. I've never tried these commands, assuming that access to the raw devices would be blocked by Windows. But I see that cfdisk seems to work. It at least starts up, anyway. So, maybe it is doable.
If they don't work on raw devices, if your scripts are creating file systems on a file or can be modified to do that, that should probably work.
Anyway, e2fsprogs is what you need, but be careful here. Whenever you start making or editing file systems, you have the opportunity to really screw up your system. Just be attentive to what the script is doing, and don't blindly go forward.

Running command with /dev/null on Windows

OK, this question has been asked before (e.g. Is there a /dev/null on Windows?) but I'm trying to find an answer that works, and all of the prior questions just say "change the command to point to NUL"
If I have a curl request (or whatever) which someone ran on a Unix/Mac which includes this:
-o /dev/null
it will throw an error if I try to run it as-is on my Windows box. Therefore, I need to change the command by replacing that with:
-o NUL
My question is, is there something I can do so that I can run the original curl request without needing to make that change?
IOW, can I create a symlink or something similar, so that I don't need to change the curl statement? Basically so I can use the *nix syntax on a Windows box?
Before someone says "how much hassle is it to change the curl", I'm running hundreds of curls a day, often ones which were originally run on a *nix box. Also, if I change to use Windows syntax, then when someone tries to run it on a *nix box, they get issues....

xdg-settings not setting default-web-browser in gentoo

I'm trying to get xdg-open to using chromium to open urls instead of firefox. I noticed that xdg-settings get default-web-browser returns chromium.desktop when it should be chromium-browser-chromium.desktop.
Following the instructions here I tried xdg-settings set default-web-browser chromium-browser-chromium.desktop, which runs with no errors. However when I run xdg-settings get default-web-browser it stills shows chromium.desktop, and xdg-open "http://www.example.com" still uses firefox. I have confirmed that /usr/share/applications/chromium-browser-chromium.desktop is present. Rebooting the machine does not fix the problem.
For now, I've created a "chromium.desktop" sym-link to "chromium-browser-chromium.desktop", but it would be nice to know why xdg-settings is not working.
xdg-* utilities are just quite simple POSIX shell scripts that try their best to handle simple common DE tasks in a seemingly standardized way. But the truth is, that every DE uses its own tools and knobs, and every installation uses different mix of them, so in this case it seems that you're using some non-standard desktop environment, which these poor utilities just cannot handle.
Anyway, if you want to debug your specific issue, run those scripts with sh -vx (eg. sh -vx /usr/bin/xdg-settings) and it will tell you exactly what those scripts are doing and at which point they fail.

Ubuntu 14.04 - How do I play an ogg file on shutdown with a script?

So, I'm attempting to have a script play a short ogg file on shutdown/restart but I seem to be having some sort of trouble actually getting it to work. Right now, I have the script in init.d and have symbolic links in rc0.d and rc6.d that all seem to work when manually executed. The script and the links all start with "K99" because the system supposedly proceeds alphabetically through the list and K99 should make it execute at the correct time. (I've tried other things, like K00, K50 and the "S" variations because I saw some other scripts with that; but they didn't seem to change anything.)
#!/bin/sh
## play shutdown sound
pulseaudio --start
echo -e "Shutdown sound script."
/usr/bin/play /home/username/Downloads/sound_file.ogg
sleep 3
The script is pretty simple I think. The ogg file and the script are both at 755 permissions. The file is only about 3s long, so I don't think that's a problem either. Originally, it seemed as if the script wasn't working at all so I added the sleep command. It seems to take about three seconds longer to shut down now, so I think the script IS running, but I have a feeling that Ubuntu is perhaps killing the audio daemon (if there is one?) before the script goes off, but I'm not sure. I've spent a few days trying to figure this seemingly simple thing out. Any ideas?
Sorry if this ends up being trivial, I'm a bit of a novice with Ubuntu system things. (Though I'd be fine with a simple fix! :) )
UPDATE
It works as it should now! After some searching about why the sound might be playing multiple times and especially on startup, I learned a bit more about the upstart system. It looks through the etc/init/ directory and runs the scripts in there on start up. I remembered that I had experimented by putting an upstart script there when the sound was still not playing at all. Apparently I had forgotten to remove it and it was executing on all run levels thus leading to the double shutdown and startup instances. Now it's gone and all is as it should be. (Although now that I've fixed it, I'm a bit sick of hearing the sound and might have to find a new one, lol.) Thanks for the help, all.
TL;DR: Put a script in init.d and symbolically link to etc/rc0.d (and etc/rc6.d if you want it on reboot too). If it plays multiple times, you've probably got a duplicate somewhere it shouldn't be.
To execute a script at shutdown
Put your script in /etc/rc0.d
Make it executable (sudo chmod +x script.sh)
Note: The scripts in this directory are executed in alphabetical
order
PulseAudio
PulseAudio is a sound server. It allows you to do advanced operations on your sound data as it passes between your application and your hardware.
Start PulseAudio at the begging of your script:
pulseaudio --start
Note: You must try/use this commands in your script because starting audio daemon and playing your ogg file is just a matter of time.

Setting up vim autocomplete for the Go programming language

EDIT:
I was generally interested to know how people had their go autocomplete set up for vim and was looking for advice on it.
Related to my original question, I think I know I can just go to:
https://github.com/nsf/gocode
copy the files that they provide there and just start using the vim autocomplete. However, I wanted to know what people thought and how the go community has the vim autocomplete set up.
Also, I have followed the intructions as were posted there and I still cannot make the autocompletion work for my go in vim. So I am looking for other alternatives or ideas on how to make it work. Not sure what the problem is. Currently when I try to autocomplete it simply writes the word PANIC instead of showing me the options for autocompletion.
ORIGINAL:
I was trying to set up my vim such that it could auto complete the Go programming language, however, I was following the instructions in the following page:
https://github.com/nsf/gocode
and I was not sure what they meant and I was a little scared of maybe changing my vim set up in a way that might be damaging by doing it wrongly.
The first thing that confused me is it says:
Install official Go vim scripts from $GOROOT/misc/vim. If you did that already, proceed to the step 2.
However, I was not sure what that even meant. I did go to that directory in my terminal and read the readme.txt file and I it said how to activate the syntax highlighting which I already had anyway. Is that everything I have to do for that step?
On step 2 it says:
do:
vim/update.sh
They actually provide the code that update.sh is but I was not sure what the beginning of the cp command meant i.e. its:
#!/bin/sh
mkdir -p "$HOME/.vim/autoload"
mkdir -p "$HOME/.vim/ftplugin/go"
cp "${0%/*}/autoload/gocomplete.vim" "$HOME/.vim/autoload"
cp "${0%/*}/ftplugin/go/gocomplete.vim" "$HOME/.vim/ftplugin/go"
But what does the ${0%/*} part do? and even if I know what the update.sh is, where do I even run this, since this vim/update.sh is done at a relative path?
I know update.sh wants me to copy some files to $HOME/.vim/ftplugin/go and $HOME/.vim/autoload, but I even did a find from ~ and couldn't find such files, so I am unsure on what to copy. I know where it should go, but not where the file even is. Does someone know where those files are or an easier or more detailed explanation on how to make vim auto-complete for go?
Thanks for the help in advance! :)
Some of the problems that I have discovered that I have, not sure if its expected, but in the $GOROOt/misc/vim/ftplugin/go I do not have the gocomplete.vim file at all. I have other stuff that seems irrelevent like an fmt.vim import.vim and a test.sh file.
But the odd thing is that at $GOROOt/misc/autoload I do not have the gocomplete.vim file but I instead have a complete.vim file. Not sure if that the same or why the name of the file would have changed. Anyway has their go autocomplete set up and mind sharing what they have and if they know what the differences might be with what I have encountered? Thanks!
ADDITION to Question
I am also generally interested in how other people have their auto-complete set up for their go in vim. Feel free to share that too!
Have you executed the update.sh command already? I'm pretty confident that it will work.
All of your Vim configuration is stored in ~/.vim/, ~/.vimrc and ~/.gvimrc (with Vim 7.4, you can put the last two also inside the first directory). To backup your Vim configuration, just store those somewhere (or put all of your dotfiles under version control, as many now do).
The ${0%/*} manipulates the script's file name ($0) like dirname does: It cuts off the script file name itself (everything at the end * until the last /). With this, you can invoke the script from anywhere, e.g. $GOROOT/misc/vim/update.sh or cd misc; vim/update.sh or cd misc/vim; ./update.sh.
The script also ensures that the autoload and ftplugin subdirs exist, and creates them if they don't yet. Just give it a try!

Resources