Monday, March 30, 2015

Cerberus Alpha: The Lettercase Issue and Finalizing

The issue of lettercase was really the last major hurdle that I had to jump over so I was a little anxious to get it done already. I decided to take a relatively simple approach; if at first you don't succeed, try and try again. Since the intended use is for Windows 8, Cerberus Alpha assumes that the file-name format should be that used in Win 7 / Win 8. If it doesn't get success with that then it tries the other possibility. Technically, this doesn't account for every possible scenario so I still consider it flawed. Will the target program even work in windows if it is not the correct case format? I don't know, but Cerberus Alpha tries to make sure that it replaces with the correct lettering format when undoing the changes. I think that it should be possible to account for every permutation of case, but it would have been more involved than I wanted to code at the time.

I also worked to improve the success counter, but I made a couple mistakes and it didn't work. The program still worked, but it did not correctly report success and therefore did not reboot when finished. That could be really bad because if you try to install twice in a row you could lose your original utilman.exe or sethc.exe. The mistakes boiled down to not having whitespace in the if statement and an incorrect format trying to iterate the second success counter. If the copy command succeeds it does ((successA++)), but successB++ doesn't work on it's own line.

Following this I also fixed the menu screen so that it will appear correctly in either terminal. It is very simple in that it checks if $TERM is "rxvt" and then prints the menu accordingly.

Finally I completed a menu option for uninstalling the sethc.exe patch. I don't know why I didn't do this earlier, but there it is.

And that about wraps up the project. The only thing left to do really is to burn the final version to CD and get it tested on some real world cases.

Friday, March 20, 2015

Cerberus Alpha: File Format Problem and Small Update

I've been busy at work so it's been a while since the last update so I wanted to make a quick post. I've made a little more progress and handled the lettercase issue, but I'll talk about that in the next one. I was going back and forth through so many different editors that I made the mistake of saving a new version directly from Notepad on Windows. That caused some "file not found" errors when trying to run the program, although "ls" and "cat" could find the file fine. I opened it in nano and tried a few things. I didn't notice at first, but nano was saying something about MS-DOS mode, it was an easy to miss message. I found this little command very helpful:

head -1 yourscript | od -c

It would out put

0000000 # ! / b i n / b a s h \r \n

if the format was not correct and

0000000 # ! / b i n / b a s h \n
if the format was correct. As you can see, there was an invisible trailing carriage return after #!/bin/bash that was causing the issue. Apparently due to the MS-DOS text format. Following that there was a simple dos2unix command installed on my system that magically took care of the problem. I don't know if dos2unix is on TinyCore (was using Parted Magic at the time), but if it isn't I may include it. Although, best practice would be to use caution with your file formats because the problem is not immediately obvious.

Anyway, next time I'll talk about the lettercase fix that I made in 1.5 among other things. Hopefully the project will be complete in the next couple weeks!

Here are some screenshots of the main menu:

And Cerberus Alpha's "title screen." Enter 'a' at the main menu.

Monday, March 16, 2015

Cerberus Alpha: NTFS File Systems and Letter Case Headaches

On my test virtual machine I formatted the drives as FAT-32 without thinking, but in reality many Windows drives are formatted as NTFS by default. When I actually tried my test CD, it gave me an error stating that the file system was read only. I thought this was due to some error in the implementation of the mount function, so I tried a few modifications to that. When I finally got around to searching the internet for advice I found that the version of mount on TinyCore Linux by default does not have the ability to mount NTFS file systems. Tiny indeed!

To take care of this issue, all I had to do was add "ntfs-3g" into the list of utilities that my remastered OS would load. With that installed, mount would load the Windows file systems as read-write and cp worked as expected. Before I figured this out, I thought that my output suppressing statement was an issue (1>/dev/null 2&>1) was causing the issue and it actually did actually seem to be a problem because it seemed to mount the file system to /dev/null. I may have to take a look back and see if I can put that back in and it will still work.

The next major issue is one of letter case. I can expect certain files to be named differently depending on the OS:
  • Windows XP:
    • /WINDOWS/system32/
      • utilman.exe
      • sethc.exe
      • cmd.exe
  • Windows 7:
    • /Windows/System32/
      • Utilman.exe
      • sethc.exe
      • cmd.exe
  • Windows 8:          (need to confirm)
    • /Windows/System32/
      • Utilman.exe
      • sethc.exe
      • cmd.exe
I can't say for certain that these are the only possibilities, but at the very least there are two paths and two file names I could encounter. One shortcut I could take is to tell cp to access /*indows/*ystem32 and *tilman.exe, but aside from the fact that ignores the all-caps version of "WINDOWS" this still has a big problem. What do I copy to? If I copy *tilman.exe toutilman_bak.exe for example, how do I know whether I need to copy cmd.exe to Utilman.exe or utilman.exe?

I've come up with a few solutions, but none of them I really like. At the moment, the program assumes you want the Windows 7 version if you're copying Utilman, and the Windows XP version if you're copying sethc.exe. I could assume that Windows doesn't care about the case of Utilman, and then just only deal with the "windows" case issue. Or I could make the "thorough install" option attempt to copy all different possible versions, starting with the most likely. That would slow it down though. I also read something about a "no-case glob" option in bash, so I will have to explore that.

This case issue is what I'm working on at the moment. Another issue I'm working on is that my message regarding number of successful installs does not count correctly, but I may just scrap that idea as it's not very important.

Saturday, March 7, 2015

Cerberus Alpha: Remastering the OS to Load the Program on Boot (Part 2)

Hello! I decided to take a break from the project, and the write up, because I got really busy at work and had to do some traveling. I will get back to the project when I can, but for now I'm going to fill in the rest of the write up while I can. I'm going off of memory at this point, so some things might be less detailed than I'd like.

When we last left off, I had finally discovered the correct method for integrating my program into the remastered iso of TinyCore Linux. The next step was to find the correct place in the boot process to load the program. Some of this really happened side by side, but I thought it would be better to describe the process in two parts. This was really a learning process for me because I needed to find the right time to run my script and TinyCore seems to have an atypical boot up process.

As mentioned previously, my first attempt was to place cerba.sh in /opt/ and modify /opt/bootlocal.sh to start cerba. According to the TinyCore Linux wiki, bootlocal.sh is run "later in the boot process." Unfortunately, it was not late enough. I tried a few implementations of this (changing around the order in bootlocal.sh), but they never worked. The behavior was that it would start cerba.sh, but the behavior was that it would run in an infinite loop (at the main menu) and ignore user input. It seems as though the bash interpreter was not yet running and that bootlocal.sh is more for things like selecting the keyboard layout.

If you search around the internet a bit, the bootlocal.sh option is mentioned a few places, as is placing your script in .X.d to boot, but this would not work because that only runs after the X window system has started and I did not want to wait for that process. My next attempt was to place start cerba from /root/.profile. This was good because it ran the script as root user, but it still had the flashing / looping issue. I tried /tc/.profile (tc is the default login user), but it still had the flashing issue. Another issue that I had was when calling on the script from the .profile I originally placed "exit" at the end of cerba's quit function. This would either exit the boot process entirely, or it would log out the existing user, interrupting the boot process awkwardly. There were other issues encountered that revolved around mounting the file systems and other commands in the script, but I can't quite remember when they were resolved. Either way, it had to do with running cerba at the correct time once all the utilities had loaded.

My next attempt was something that I had to do a little digging to figure out, but once I had it this was essentially the correct solution. I put the script in /etc/profile.d/ and this time it ran correctly without any errors (related to its placement in the boot process at least), except for one. When the program ran, it worked fine, but when I chose to "quit" from the program it would rerun itself! As it turns out, the program was being started from /etc/profile.d/ every time the user logged in, so when I quit the program it tried to login again and reran cerba. My simple solution to this was to place cerbastart.sh which was simply a script that did "sudo cerba" and then "rm /etc/profile.d/cerbastart.sh ." This was my way of ensuring that the program ran once and only once during the initial login. The added benefit of this is that cerba will run once and then continue to boot normally, including into the X window system if that boot option is chosen.

Around this time I placed a copy of the script as /usr/bin/cerba which meant that I could run the program just by entering "cerba" in the terminal. Every thing seemed to be working perfectly so I burnt a test CD and tried it out on my machine at home. When I ran it, though, there was an error about the file system being write protected! This was my next major hurtle, and later the problem of letter case would raise its ugly head again.