Tuesday, July 30, 2013

Disabling directory listings in apache2 and ubuntu

To disable directory listings for a website using apache2 and ubuntu, edit the file
/etc/apache2/sites-available/default

Change the lines:

        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews

to put a - in front of Indexes

        <Directory /var/www/>
                Options -Indexes FollowSymLinks MultiViews

save the file and then restart apache using
/etc/init.d/apache2 restart

Wednesday, January 25, 2012

Fixing the fan on an ASUS EEE Box model B202

Here's the source link
I had to grab a copy out of Google cache to see the content.



Repairing the Asus B202 CPU-fan

After about three years yesterday my trusty Asus EeePC B202 Box which runs my Windows Server 2008 x86 started to make terrible noise. The failure was quickly located: the CPU-fan! When I moved the box around it was silent as usual. But when it was stable it was making loud noise. So the bearings needed some oil obviously.
I decided to disassemble the box to get to the fan, that was not so easy as I thouight it would be:
  1. Take out the HDD and remove the 2 outer screws
  2. Remove the plastic cover carefully as if you would replace the RAM.
  3. Remove the s4 crews in the corners that hold the plastic frame.
  4. Remove the plastic frame very carefully from the front to the back. There are notches to hold it in place. Pull the black tape first, so the power button would remove through the cover slit.
  5. Remove the remaining plastic back cover
  6. Remove the 4 side screws
  7. Remove the 2 top screws. Peel off the first, flat metal cover.
  8. Open then WLAN opening (1 screw) and remove the connector in the corner-side (if the opening is left/bottom, remove the left one!)
  9. Flip the motherboard over and remove the remaining screws.
  10. Remove the metall cover from the back to the front this time. Watch the power LED. Some metal case parts remain on the motherbaord. You need not to remove them.
  11. Peel off the tape that covers fan and heat sink.
  12. Remove the 2 fan srews. disconnect the fan-power.
  13. Remove the fan from the motherboard. it is a Delta Elektronics OEM fan BDB05405HHB (5V 0.36Watts) which is hard to get.
  14. Remove the very small fan screw, that holds the metal cover and than open the clamps to remove the metal cover of the fan.
  15. Now you see the fan. Clean it with pressured air carefully.
  16. Pull the blades from the motor by carefully gripping the fan-blades in 180 degree with thumb and pointing finger and pulling them firmly but carefully straight up. Do not bend or otherwise tork the axle.
  17. Now get some oil (I took the oil from my electric shaver) and a needle. Tip the needle in the oil and bring the sticking oil to the axel ijn the fan blades housing. Do not put it in the motor directly! Use only a very tiny bit of oil. The small drop i sused was even to much!
  18. Now press the fan-blades back into the fan motor. and turn them a little bit. You can also use the presured air to drive the turbine :-) The oil should now we where it supposed to be.
  19. No reassemble the B202 in reverse order(14 to 1).
If you have put the motherboard together without the plastic case you could make a first test (5 to 6). The fan should make no noise now. The wild at hard can do it even before step 10.
I had to nstart the B202 twice to get it to run and it lost the RTC settings so it was back to 10.10.2010 (???). But now it is as quiet as on day one.

Repairing the Asus B202 CPU-fan

After about three years yesterday my trusty Asus EeePC B202 Box which runs my Windows Server 2008 x86 started to make terrible noise. The failure was quickly located: the CPU-fan! When I moved the box around it was silent as usual. But when it was stable it was making loud noise. So the bearings needed some oil obviously.
I decided to disassemble the box to get to the fan, that was not so easy as I thouight it would be:
  1. Take out the HDD and remove the 2 outer screws
  2. Remove the plastic cover carefully as if you would replace the RAM.
  3. Remove the s4 crews in the corners that hold the plastic frame.
  4. Remove the plastic frame very carefully from the front to the back. There are notches to hold it in place. Pull the black tape first, so the power button would remove through the cover slit.
  5. Remove the remaining plastic back cover
  6. Remove the 4 side screws
  7. Remove the 2 top screws. Peel off the first, flat metal cover.
  8. Open then WLAN opening (1 screw) and remove the connector in the corner-side (if the opening is left/bottom, remove the left one!)
  9. Flip the motherboard over and remove the remaining screws.
  10. Remove the metall cover from the back to the front this time. Watch the power LED. Some metal case parts remain on the motherbaord. You need not to remove them.
  11. Peel off the tape that covers fan and heat sink.
  12. Remove the 2 fan srews. disconnect the fan-power.
  13. Remove the fan from the motherboard. it is a Delta Elektronics OEM fan BDB05405HHB (5V 0.36Watts) which is hard to get.
  14. Remove the very small fan screw, that holds the metal cover and than open the clamps to remove the metal cover of the fan.
  15. Now you see the fan. Clean it with pressured air carefully.
  16. Pull the blades from the motor by carefully gripping the fan-blades in 180 degree with thumb and pointing finger and pulling them firmly but carefully straight up. Do not bend or otherwise tork the axle.
  17. Now get some oil (I took the oil from my electric shaver) and a needle. Tip the needle in the oil and bring the sticking oil to the axel ijn the fan blades housing. Do not put it in the motor directly! Use only a very tiny bit of oil. The small drop i sused was even to much!
  18. Now press the fan-blades back into the fan motor. and turn them a little bit. You can also use the presured air to drive the turbine :-) The oil should now we where it supposed to be.
  19. No reassemble the B202 in reverse order(14 to 1).
If you have put the motherboard together without the plastic case you could make a first test (5 to 6). The fan should make no noise now. The wild at hard can do it even before step 10.
I had to nstart the B202 twice to get it to run and it lost the RTC settings so it was back to 10.10.2010 (???). But now it is as quiet as on day one.

Wednesday, June 29, 2011

Automatically backup flash drive when mounted

Reference: Automating-backup-of-flash-drives

Copy of above in case it disappears


I have a lot of my critical work on a few flash drives which I carry around with me constantly, mainly because I work on a number of machines and would like to have a central repository of my work. After losing one of the drives recently though (bound to happen sooner or later), I looked further into automating the backup process (I had lost about 2 days of work). That’s when I stumbled accross this hint onmacosxhints.com, but the script didn’t exactly fulfil what I had imagined my automated process to do.

Ideally, the automated backup process would have these features:
  1. Not require installation of any third party app
  2. Have the ability to somewhat customize the backup script for each thumb drive
  3. Have the backup script silently run whenever the thumb drive is mounted
  4. Require little to no set up for each new thumb drive that I want to backup
  5. Support spaces in Volume names
  6. Not try to backup the boot drive under any circumstances (don’t ask…)
Updated 2007-03-10: I updated the backup script to include automated handling of archives, and keeps an arbitrary number (specified in the preferences of the script) of incremental archives using rsync's --link-dest parameter, as recommended by John in the comments. This creates what functionally amounts to FULL backups, but with a fraction of the space needed for an actual tar backup. Also it can be configured to keep at most one backup per day, or with minor editing at most one backup for any period of time.
Updated 2007-03-18: I've created a second script which can be used as a drag-n-drop solution. Simply save the script as an application bundle, save it somewhere handy, and drag it to your dock. Now you can drag your thumb drive on the script which will perform the backup, and then eject your drive!
Updated 2008-03-10: Folder action modified to work with Leopard. Well, more like hacked at this point, but it seems to work.

Now to satisfy the first parameter, using Do Something When was out of the question, even though it seems like a good piece of software. That’s when I turned to Fodler Actions, and found this hint again on macosxhints.com. I then proceeded to read the Apple-published Folder Action for automating backups (which, again, didn’t do quite what I wanted), so I came up with this:

A folder action that scans the root folder of the mounted volume, and looks for (one of) a specified file name.
property backup_script : "rsync.app" (* add/change this string to match the name of your script *)
 
on adding folder items to this_folder after receiving these_volumes
    tell application "Finder"
        try
            set the volume_list to every file of this_folder
 
            (* go through all entries in /Volumes/ *)
            repeat with i from 1 to number of items in volume_list
                set this_item to the original item of item i of volume_list
                if the kind of this_item is "Volume" then
                    set this_disk to (this_item as alias)
 
                    (* is this item the newly mounted disk? *)
                    if this_disk is in these_volumes then
 
                        (* iterate through all files in the root of disk *)
                        set searchCmd to "ls -d " & quoted form of POSIX path of this_disk & backup_script
                        (* check to see if a backup script is available *)
                        set searchResult to ""
                        try
                            set searchResult to do shell script searchCmd
                        end try
                        (* run the backup script *)
                        if (searchResult starts with "/Volumes") then
                            set backupFile to POSIX file searchResult as alias
                            open backupFile
                        end if
 
                    end if
                end if
            end repeat
        on error error_message number error_number
            if the error_number is not -128 then
                display dialog error_message buttons {"OK"} default button 1
            end if
        end try
    end tell
end adding folder items to
Download this script

If you already know how to apply folder actions, just save the script above and apply it as a folder action to the /Volumes/ folder. If you don’t know (or don’t remember) how to do that, re-iterating the instructions from this Apple page, follow these steps to do it:
  1. Copy the above code in Script Editor
  2. Save it as a script in /Library/Scripts/Folder Action Scripts/, and give it a descriptive name
  3. In Finder, click Go -> Go to Folder (or just press cmd-shift-G), and type /Volumes/.
  4. Launch the Folder Actions Setup utility (probably located in /Applications/Apple Script/ folder)
  5. Click the Add Folder Action (round plus) button at the bottom left
  6. Drag the small folder icon from the Finder window title bar into the Choose Folder sheet dialog, and click ok.
  7. From the dialog that comes up, chose the script you just saved.
  8. You’re done.
Alternatively (or additionally), you can save this script as an application bundle, save it somewhere handy, and drag it to your dock. When you drag a thumb drive on this application the backup process will start, and as soon as it's done the drive will eject.
property backup_script : "rsync" (* add/change this to match the name of your script *)
 
on open dropped_item
    set this_vol_alias to (dropped_item as alias)
    try
        tell application "Finder"
            if the kind of this_vol_alias is "Volume" then
                set the file_list to every file of this_vol_alias
                repeat with j from 1 to number of items in file_list
                    (* check to see if a backup script is available *)
                    set this_file to name of item j of file_list
                    if this_file is equal to (backup_script & ".app") then
                        open item j of file_list (* run the backup script *)
                    end if
                end repeat
            else
                display alert "This script can only be executed on volumes"
                return
            end if
        end tell
 
        delay 2 (* give some time for the backup script to actually launch *)
        tell application "Finder"
            try
                set bakapp to creator type of process backup_script
                repeat while bakapp is not equal to ""
                    delay 1 (* the backup is still running, we can check again in a second *)
                    set bakapp to creator type of process backup_script
                end repeat
            on error
                if (ejectable of this_vol_alias is true) then
                    (* display alert POSIX path of dropped_item *)
                    eject this_vol_alias
                end if
            end try
        end tell
 
    on error error_message number error_number
        if the error_number is not -128 then
            display dialog error_message buttons {"OK"} default button 1
        end if
    end try
end open
Download this script

Now, for the modified backup script. The properties at the top can be modified on a per copy basis to customize the function of the script.
property archive_backup : true
property number_of_archives : 3 (* 0 for unlimited *)
property with_administrator_privileges : false
property one_archive_per_day : true
 
property display_notification : false
property backup_target : "Backups/" (* MUST be a folder location with trailing slash! Always relative to home folder *)
 
property rsync_params : "-aEz --delete-excluded"
(* END OF PREFERENCES *)
 
set WhereImRunningFrom to path to me
tell application "Finder"
    (* can't run from the script editor *)
    set AppCreator to creator type of WhereImRunningFrom
    if AppCreator is "ToyS" then
        activate of me
        beep
        display alert "This script cannot run directly from ScriptEditor"
        return
    end if
 
    (* NEVER run from the hard drive! *)
    set bootVolume to name of disk of home (* safety feature! *)
    set NameOfDisk to name of disk of WhereImRunningFrom
    if NameOfDisk is bootVolume then
        beep
        display alert "Should not run this script from the boot volume!"
        return
    end if
 
    (* setup backup dir *)
    set homeDir to path to home folder from user domain
    set backup_folder to POSIX path of homeDir & backup_target
    try
        (* quick and dirty check to see if folder exists - must be a good way to do this in applescript? *)
        do shell script "cd " & backup_folder
    on error
        try
            do shell script "mkdir " & backup_folder
        on error
            display alert "There was an error creating the backup folder " & backup_folder
            return
        end try
    end try
 
    (* find source and target *)
    set backupBase to NameOfDisk & "-Backup"
    set targetDir to backup_folder & quoted form of backupBase
    set sourceDir to quoted form of ("/Volumes/" & NameOfDisk & "/")
 
    (* set up archive filename *)
    if archive_backup then
        set thedate to current date
        set theday to day of thedate
        set themonth to month of thedate
        set theyear to year of thedate
        set thetime to time of thedate
 
        set thedate to "-" & theyear & "-" & shortMonth(themonth) of me & "-" & theday as string
        if not one_archive_per_day then set thedate to thedate & "-" & thetime as string
 
        set backupFolder to quoted form of (backup_folder & backupBase & thedate  & "/")
    end if
end tell
 
(* do the backup *)
(* try *)
if with_administrator_privileges then
    set excluded to " "
else
    set excluded to " --exclude='.Trash*' --exclude='.Spotlight*'  "
end if
 
if archive_backup then
    set posixDir to POSIX file backup_folder
    set fileList to list folder posixDir
    set archiveList to {}
    tell application "Finder"
        (* Search for existing backups *)
        repeat with i from 1 to number of items in fileList
            set thisFile to item i of fileList
            set filePath to path to resource thisFile in bundle posixDir
            if thisFile starts with backupBase then
                set archiveList to archiveList & POSIX path of filePath
            end if
        end repeat
    end tell
 
    (* List existing backups in order of last modified date *)
    set latestArchive to ""
    set linkDest to ""
    set listString to ""
    repeat with x from 1 to number of items in archiveList
        set listString to listString & " " & quoted form of item x of archiveList
    end repeat
    set newString to do shell script "ls -dt " & listString (* sort files by modified date *)
    set theList to (paragraphs of newString)
 
    (* Clear out outdated backups *)
    if (number of items in theList is greater than number_of_archives) and (number_of_archives is greater than 0) then
        repeat with y from (number_of_archives + 1) to (number of items in theList)
            do shell script "rm -Rf " & quoted form of item y of theList
        end repeat
    end if
    if number of items in theList is greater than 0 then
        set latestArchive to quoted form of item 1 of theList
        if latestArchive is equal to backupFolder then
            (* Preserve same target folder *)
            if number of items in theList is greater than 1 then
                set latestArchive to quoted form of item 2 of theList
            else
                set latestArchive to ""
            end if
        end if
    end if
 
    if latestArchive is not equal to "" then
        set linkDest to " --link-dest=" & latestArchive
    end if
    set theScript to "rsync " & rsync_params & linkDest & excluded & sourceDir & " " & backupFolder & "; touch " & backupFolder
else
    set theScript to "rsync " & rsync_params & excluded & sourceDir & " " & targetDir & "; touch " & targetDir
end if
 
if with_administrator_privileges then
    do shell script theScript with administrator privileges
else
    do shell script theScript
end if
 
activate of me
beep
if display_notification then display alert NameOfDisk & " drive backed up"
(*
on error
    display alert "There was an error backing up " & NameOfDisk
end try
*)
 
 
to shortMonth(themonth)
    set MonthList to {January, February, March, April, May, June, July, August, September, October, November, December}
    set mm to 1
    repeat until item mm of MonthList = themonth
        copy mm + 1 to mm
    end repeat
    if mm < 10 then copy "0" & mm to mm
    return mm
end shortMonth
Download this script

Copy the above code in Script Editor, and save it as an Application bundle giving it the name "rsync". If you wish to give it a different name, or maintain a number of copies each with a different name, make sure to modify the first line of the Folder Action script appropriately.

Finally, I can just drop a copy of the rsync application bundle in any thumb drive I want to keep a backup of, and apply the Folder Action to any computer I want to maintain backups on. Since the backup script is using rsync for the backup, I can have multiple backups on any number of computers and they will all mirror the contents of the thumb drive whenever the thumb drive is mounted on them. Additionally, a tar-gzipped copy of the thumb drive can optionally be created with a date stamp for archiving. Deletion of old archives must be managed manually.

If you are having permission issues with some of the files on one of your thumb drives, you can enable thewith_administrator_privileges property in the backup script. This will cause the script to ask you for a password every time the thumb drive is mounted before performing the backup, but will perform the backup as an administrator eliminating any permission issues.

I feel that this script can still be improved, but for now it works just fine for my needs. If you have any suggestions for improving this process, feel free to add them in the comments.

Monday, June 6, 2011