Migrate Post From One WordPress Database To Another

Internet No Comments

I made a mistake and posted a blog entry to the wrong WordPress website. A comment was made before I could manually delete and post it to the other website. While I could just lose that comment, I decided it would be interesting to see if I could manually migrate the post content (with comments) directly from one WordPress MySQL database to the other.

After looking at the WordPress database schema, I found that I only needed to pull data from two tables and modify a few column values.

These are the essentials to keep in mind when migrating a post:

  • The two “wp_posts” and “wp_comments” tables contain the data we need to migrate.
  • For “wp_posts”, we need to modify columns “ID”, “post_author” (foreign key to “wp_users” table), and “guid”.
  • For “wp_comments”, we need to modify columns “comment_ID”, “comment_post_ID”, and “comment_parent” (references “comment_ID” for replies).
  • We can ignore tables “wp_postmeta” (contains edit lock info) and “wp_commentmeta” (contains Akismet approval data).
  • No need to deal with categories and tags (kept in “wp_term_taxonomy”, “wp_termmeta”, and “wp_terms” tables). We can manually set category (from the default “Uncategorized”) and insert tags after the migration.
  • Image links in the post will point back at the old WordPress site, so we will need to add the images to the new WordPress site and update the image URLs accordingly.

Before we start, make sure that both the WordPress websites are updated to the same version. (My websites are using the latest WordPress version 4.9.7.)

Read Post From Old WordPress Database

Identify the post identifier that you wish to move. If you click on your post header, the URL will change to include the identifier. For example, my URL is “http://www.chanhvuong.com/3048/how-to-sell-a-used-computer-like-a-car-salesman/” and the post identifier is 3048.

# SSH into your server and log into MySQL.
mysql -u root -p
    # Input your MySQL root password if it is not blank

# Select the <database_name> to read from.
mysql> use <database_name>;

# By default, MySQL is configured to only support reading/writing files from a "mysql-files" directory.
# You could remove this requirement, but I decided to just make use it.
mysql> show variables like 'secure_file_priv';
| Variable_name    | Value                 |
| secure_file_priv | /var/lib/mysql-files/ |

# Output the post content matching <post_id> to a file.
mysql> select * from wp_posts where ID=<post_id> into outfile '/var/lib/mysql-files/post.txt';

# Output the post comments matching <post_id> to a file.
mysql> select * from wp_comments where comment_post_ID=<post_id> into outfile '/var/lib/mysql-files/comments.txt';

Insert Post Into New WordPress Database

While we could modify the column data in the output files, I decided to do manual overwrites when importing. (You will need to be the root user in order to access “/var/lib/mysql-files/” directory.)

# Select the <other_database_name> to write to.
mysql> use <other_database_name>;

# WordPress orders posts by publish date so insert using next auto-increment post id.
# You'll need this to modify the "guid" string below.
mysql> select max(ID)+1 from wp_posts;

# Find a user ID to use as the "post_author".
mysql> select ID,user_login,display_name from wp_users;

# Insert the post into the other database.
# Set ID as NULL so the next auto-increment value will be used.
# Select existing <my_user_id> as post_author.
# Update guid with other WordPress domain and the next auto-increment post id.
mysql> load data infile '/var/lib/mysql-files/post.txt' into table wp_posts set ID=NULL, post_author=<my_user_id>, guid="http://www.<other_domain>.com/?p=<auto_incremended_post_id>";

Inserting comments is problematic because reply comments require the identifier for the parent comment, which doesn’t exist yet.

One solution is to lookup the next auto-incremented comment ID and then edit the “comments.txt” outfile accordingly before importing. However, because my website is active, some comments could be inserted before I do the import, making all the identifiers in the outfile invalid.

The second solution, which I chose, is to import the comments and then manually fix the “comment_parent” identifiers (and the “user_id” which is nonzero for users in “wp_users”).

# Insert the comments into the other database.
# Set comment_ID as NULL so the next auto-increment value will be used.
# Set the comment_post_ID to be our <auto_incremented_post_id> from above.
mysql> load data infile '/var/lib/mysql-files/comments.txt' into table wp_comments set comment_ID=NULL, comment_post_ID=<auto_incremented_post_id>;

# Lookup the newly-inserted comments.
mysql> select comment_ID,comment_author,comment_author_email,comment_parent,user_id from wp_comments where comment_post_ID=<auto_incremented_post_id>;

# Update comment_parent to the correct comment_ID (replace 472365 and 472366 below accordingly).
mysql> update wp_comments set comment_parent=472365 where comment_ID=472366;

# Update user_id for reply comments made by you (replace <my_user_id> and 472366 below accordingly).
mysql> update wp_comments set user_id=<my_user_id> where comment_ID=472366;

Fix Category, Tags, and Images

The post and comments should now be visible on your other WordPress website. You can set the post’s category and tags using the normal editing process. And add any images and update the image URLs in the post body accordingly.

Once you’re confident that the post is displayed correctly, you can delete its duplicate (and related images) from the old WordPress website. Also, you can delete the no longer necessary outfiles from the “/var/lib/mysql-files” directory.

And finally, for completeness, set a redirection from the old post URL to the new post URL.

Some info above gotten from:

No Comments

Fix GPS on iPhone 6s

Mobile Devices No Comments

Two months ago, Google Maps stopped telling me directions when navigating on my Apple iPhone 6s. I could still navigate without the voice prompts though. Two week ago, my current location would only update once per minute. I couldn’t navigate at all. Sometimes, after 5-10 minutes, the GPS location updates would start working correctly again. In any case, my GPS was broken. (Apple Maps exhibited the same GPS problem.)

Note: The intermittent GPS updates reminded me of the refurbished iPhone 5s I got from T-Mobile. It would abruptly lose power in very cold weather. Later I found out that the phone was missing parts inside, specifically, the metal shield over the battery connector; so during cold weather, some parts must have contracted and shorted the battery out. Maybe my GPS problem was similar. Alas, no parts were missing from the iPhone 6s.

I thought it was a software bug because I had updated to iOS 11.2 near the time the GPS started misbehaving. Updating to iOS 11.3 did not fix the GPS problem. I reset the location configuration (under Settings, General, Reset, Reset Location & Privacy), did a “Reset All Settings”, and performed a full system restore (using iTunes), but none of those actions fixed the GPS.

After researching, I could only conclude that the GPS issue was a hardware problem. Most likely, the GPS antenna needed to be replaced.

Tip: If you no longer hear the Google Maps (or Apple Maps) navigational voice prompts, then the iPhone probably was not able successfully to acquire the GPS satellites. However, Google Maps will still roughly (and inaccurately) update your position using the cellular, Wi-Fi, and Bluetooth networks.

While there were numerous instructions on replacing the iPhone 6 GPS antenna, I could only find one Youtube video (from the Netherlands) that had instructions on replacing the iPhone 6s GPS antenna.

The reason is that while the iPhone 6 had a separate GPS antenna, the iPhone 6s uses an integrated cellular, Wi-Fi, and GPS antenna. Unfortunately, different sources refer to the antenna by different names. iFixit calls it the cellular antenna. Some Youtube videos call it the Wi-Fi antenna. Many eBay sellers call it the antenna “retaining bracket” which doesn’t sound like an antenna at all.

Note: To add to the confusion, there is a second Wi-Fi antenna which iFixit calls the “Wi-Fi diversity antenna”. I suppose it is necessary to increase the Wi-Fi reception range.

I ended up purchasing a used, original iPhone 6s antenna by mistake. I was looking for an authentic iPhone 6s antenna (instead of the cheaper “OEM” clones), found one for a reasonable price (almost twice as expensive as the OEM), thought it was new, and purchased it. I installed the antenna by following instructions from the Youtube video above and iFixit’s iPhone 6s Cellular Antenna Replacement page.

Once the antenna was replaced and after testing, I found that the GPS was still not working correctly. While I didn’t see the intermittent GPS location update issue, it would still take several minutes before Google Maps would start updating the location correctly.

Note: Once the GPS was working, I did noticed that in Google Maps (and Apple Maps), the shadow on the location dot pointed in the wrong direction. It was 80 degrees off from my car’s direction of travel. Strangely, the directional shadow was correct when Google Maps was giving walking directions.

Some forums recommended installing an iOS app called GPS Diagnostic: Satellite Test (available for $2.99). The app provided more information on the GPS function and indicated that it was taking several minutes before the phone could acquire the GPS satellites.

Tip: Test the GPS outside with an unobstructed sky. The phone will have problems acquiring the GPS Satellites inside a house.

In conclusion, I purchased a brand new iPhone 6s OEM antenna, installed it, walked outside, opened up the GPS Diagnostics app, and within a few seconds, the phone successfully acquired the GPS satellites. I’ve tested the GPS navigation a couple of times since then and Google Maps worked immediately as expected. The directional shadow was still wrong, but hopefully it will fix itself over time.

Update: Sporadically, the GPS would not be able to acquire the satellite when I first turn it on. I found out that it was because I hadn’t tightened the screws on the GPS antenna enough. Unlike the screws on the other parts (like the metal shields which you don’t need to tighten too much), the screws on the antenna need to be tight to ensure a solid metal connection.

I noticed another benefit. Wi-Fi reception is poor in a corner of my house. With the old antenna, the iPhone wouldn’t switch to the LTE network, but would just keep trying and failing to use the Wi-Fi. With the new OEM antenna, the iPhone switches quickly to the LTE network (and back).

I hope the above will help you to fix your iPhone 6s’ GPS woes.

No Comments

You May Not Have the Latest Windows 10 Version

Windows No Comments

I found an issue with my Windows 10 desktop. Unknown to me, it has been running an old version of Windows 10 and is lacking all of the recent security updates. Worse, when I run “Check for updates” (a.k.a. Windows Update), Windows say that it is “up to date”. But Windows 10 lies.

I remember Windows Update complaining about a failed update and asking me to reboot several months ago. After several reboots, Windows stopped complaining so I assumed the problem was solved. But it wasn’t. Windows had given up and then pretended that everything was hunky-dory.

Running “winver” tells me that my desktop’s Windows 10 version is 1703. The latest version is 1709, known as the Fall Creator’s Update. When I check my update history (under Windows Update), it says that the version 1709 update has “failed to install”. There used to be a link to reboot so Windows could try again, but that link is gone.

Update Assistant Required

I check the web and there are all sorts of solutions recommending running sfc (and dism), stopping services, clearing out the update history, etc. I try several but they did not fix the problem. The real problem is that Windows Update is not capable of upgrading to version 1709. Version 1709 requires that we install and run the Windows 10 Update Assistant utility.

The Windows 10 Update Assistant downloads the version 1709 update, installs it, and requests a reboot. (Even though I gave permission to reboot, nothing happened but the Update Assistant quitting. I had to do a manual reboot.) On boot up, a grey screen is shown with a message that the update will take awhile. On my Intel Core i5 system with SSD, it took around 20 minutes to complete the update.

The “winver” utility now says that the version is 1709. Windows Update now indicates that “updates are available” and starts downloading them for installation. (There are about 5 updates including “Definition Update for Windows Defender Antivirus”.)

Cleanup Old Windows Version

The old version of windows is kept under “C:\Windows.old” and takes up a lot of space (22.6GB on my system). The directory is classified as temporary files, so there are several ways to delete it.

  • Run “Disk Cleanup”, select the “C:\” drive, click on “Clean up system files” button on the bottom-left, select “C:\” drive again, check “Previous Windows installation(s) 23.9GB” and “Windows Update Cleanup 1.78GB”, click OK, and confirm by clicking “Delete Files”.
  • Run “Storage”, click on “This PC (C:)”, click on “Temporary files”, check “Previous version of Windows”, and click “Remove files”.
  • Manually deleting the directory.

Note: Either the Disk Cleanup or Storage may freeze when deleting the “Windows Update Cleanup”. This happened on my system. After waiting 20 minutes, I cancelled the cleanup and restarted. The second time through, the operation completed within several seconds.

I recommend uninstalling the “Windows 10 Update Assistant” using the “Add and remove programs”. It is no longer needed. When the next major version update is required, you will want to download the latest version of the Update Assistant then. Uninstalling Update Assistant will delete the “C:\Windows10Upgrade” directory (20MB).

Note: On my desktop, the Windows 10 Update Assistant insists on launching at startup to thank me for updating with a truncated text message. Worse, the close window icon (upper-right X mark) is greyed out. Worst, it places an icon in the system tray. I don’t recall if the system tray icon has a menu option to quit or not.

Check your Windows 10 version and if necessary, update to the latest 1709 version with the Windows 10 Update Assistant.

No Comments

Apple iTunes, A Hard Drive Space Hog

Windows No Comments

My Windows laptop complains that there is very little free space left on the 128GB SSD drive. That’s strange because Windows 10 and the few applications I installed shouldn’t have taken that much space, maybe at most half the hard drive space. I dig around and find that my user’s hidden AppData directory is taking up 47GB!

Further investigation reveals that the culprit is “%APPDATA%\Apple Computer”, belonging to the Apples iTunes application. Specifically, iTunes’ device backup directory uses 34GB and software update directories use 12GB.

I use iTunes to backup and update several iPhones and iPads belonging to myself and different family members. Over the years, there have been many backups and many iOS versions. Because the base memory on the newer iPhone and iPad has increased (from 16GB to 32GB or higher), their backup images have grown in size (more songs, photos, and videos). Worse, iTunes does not automatically delete old iOS images that are no longer in use.

Tip: Windows 10 (and probably Windows 8) includes a Systems Settings app called “Storage” that helps you to view and drill down into the space usage. Run it and select the drive to view how much space each file category is using. Click on the category to drill down further.

Below are instructions on how to free up the drive space on Windows.

Delete Device Backups

To delete the backups using iTunes:

  1. Browse to menu “Edit->Preferences…”.
  2. Click on “Devices” (top-right icon).
  3. Select the unwanted backup listed under “Device backups:” and click “Delete Backup”.

Tip: Look for duplicate device backups to delete. Usually the device’s old backup is overwritten by the new backup; however, sometimes iTunes won’t overwrite and will create a new backup instead.

iTunes will move the deleted backups to the “%LOCALAPPDATA%\Temp” directory so you will want to clean up that directory manually or by using the free CCleaner tool. (Unfortunately, Windows’ built-in “Disk Cleanup” app does not empty the “%LOCALAPPDATA%\Temp” directory.)

Alternatively, you can manually delete all the backups using the command line:

# Change directory to the device backup directory
cd "%APPDATA%\Apple Computer\MobileSync\Backup"

# Delete all subdirectories under device backup directory
for /d %d in (*) do rmdir /s %d

# You will be prompted to confirm deletion for each subdirectory.
# Note: We can pass a "/q" quiet flag to "rmdir" to not prompt, but that is dangerous!

Delete iOS Images

Delete the iOS images using the command line below. iTunes will download them again in the future if necessary.

# Delete iPad iOS images (ex: iPad3,2_9.3.5_13G36_Restore.ipsw)
cd "%APPDATA%\Apple Computer\iTunes\iPad Software Updates"
del *.ipsw

# Delete iPhone iOS images (ex: iPhone_4.0_64bit_10.3.1_14E304_Restore.ipsw)
cd "%APPDATA%\Apple Computer\iTunes\iPhone Software Updates"
del *.ipsw

# Delete iPod iOS images (ex: iPod4,1_6.1.6_10B500_Restore.ipsw)
cd "%APPDATA%\Apple Computer\iTunes\iPod Software Updates"
del *.ipsw

Note: iTunes 12.6.2 and earlier versions would also backup the apps, taking up more space than later versions. Later versions will re-download the apps from the App Store on the device when restoring.

If you use iTunes to backup and update iOS devices and find that your computer is running out of drive space, you may be suffering from the same issue that I have above. I hope that the above info will help you to slay your iTunes space hog.

Tip: Instructions are similar for Macs. Look in the “~/Library/Application Support/MobileSync/Backup” and “~/Library/iTunes” directories.

No Comments

Update to Latest Ubuntu Kernel

Linux No Comments

Recently I got an email from DigitalOcean to update my server’s kernel to protect against the Meltdown and Spectre exploits. The instructions are the normal update commands that I usually run, “apt-get update” and “apt-get dist-upgrade”.

After doing the update, I thought that I would double-check the kernel version. The latest Ubuntu 14.04 kernel is “3.13.0-143-generic”. The kernel that my server was using is “3.13.0-039-generic”. My server was running an extremely old version of the kernel.

Supposedly, the Ubuntu GrubLoader should automatically run the latest installed kernel version after a reboot. However, my server was not doing that. It appears to be an issue with DigitalOcean’s droplet configuration.

The workaround is to use the DigitalOcean web interface to change the kernel from “DigitalOcean GrubLoader v0.2 (20160714)” to “DigitalOcean GrubLoader v0.1 (20160527)” (or vice versa). Then shutdown the server (using the command line) and switch the droplet back on using the DigitalOcean web interface. Somehow, changing the GrubLoader version makes the GrubLoader start working properly again.

Here are the full instructions to ensure that your Ubuntu server is running the latest kernel:

# Show Ubuntu version
lsb_release -a

# Show kernel version (alternatively, run "uname -a" or "cat /proc/version")
uname -r

# Update apt-get repository
sudo apt-get update

# Install any updates, handle dependencies automatically
sudo apt-get dist-upgrade

# Reboot so Grub will load any newly-installed kernel version
sudo reboot

# After reboot, show kernel version
uname -r

# If the kernel version is not the latest "3.13.0-143-generic" or later,
# go to the DigitalOcean web interface and switch the droplet's kernel
# from "DigitalOcean GrubLoader v0.2" to "DigitalOcean GrubLoader v0.1"
# (or vice versa).

# Doublecheck by listing the installed kernel image(s)
dpkg --list | grep linux-image-generic

# Shutdown the server
sudo poweroff

# On the DigitalOcean web interface, refresh the Droplet details until
# you see the power switch (located to right of Droplet name) go to
# the Off position.  Switch it back to the On position.

# After server boots up, show kernel version (you should see latest)
uname -r

# If you can't ssh into your server or you want the later
# "DigitalOcean GrubLoader v0.2" version, just repeat the steps above
# to change the GrubLoader version.

# Remove dependencies and packages which are no longer used
sudo apt-get autoremove

# If you get a "you may need to re-run your boot loader[grub]" warning,
# optionally update Grub's configuration.
sudo update-grub

Info above derived from:

No Comments

Re-subscribe to Let’s Encrypt Renewal Reminder Emails

Linux No Comments

Let’s Encrypt will automatically email expiration notices when your domain’s SSL certificate is coming up for renewal at 20 days, 10 days, and 1 day before the expiration date. (Recently, I received notices at 19 days and again at 10 days.)

I’ve found these renewal reminders very helpful because in the past, they’ve told me that the certificate auto-renewal process I had created (see Free SSL Certificate from Let’s Encrypt for Nginx) was broken. (Initially, I had attempted to setup the auto-renewal process to execute as a non-root user, but frequent updates requiring root access kept breaking it. I ended up configuring the auto-renewal to use root access.)

The renewal email body contains a link with the title “If you want to stop receiving all email from this address, click…” at the end. Unfortunately, the link is very long, taking up 3 to 4 lines of text (on my screen) and making it easy to click on by accident. More unfortunate, clicking on the link will disable the sending of expiration reminders to your email address for all domain certificates, not just the particular domain certificate in question. This change cannot be undone; you cannot re-register the same email address.

However, there is a re-registration workaround documented at Let’s Encrypt’s Expiration Emails page. The workaround takes advantage of how most email services will ignore the plus symbol and whatever follows it in an email address. For example, “myuser+1@mydomain.com” is treated the same as “myuser@mydomain.com”.

To re-subscribe your email address, run the command below in your certbot installation directory. (You will be prompted to input your sudo password if necessary.)

$ cd certbot
$ ./certbot-auto register --update-registration --email myuser+1@mydomain.com

Requesting to rerun ./certbot-auto with root privileges...
Saving debug log to /var/log/letsencrypt/letsencrypt.log

Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'
d like to send you email about EFF and
our work to encrypt the web, protect its users and defend digital rights.
(Y)es/(N)o: N

 - Your e-mail address was updated to myuser+1@mydomain.com.

The community support page, Accidentally Unsubscribed, mentions an alternative workaround using LetsMonitor.org. LetsMonitor.org appears to be an external website which periodically checks the expiration date on your domain’s SSL certificate. I haven’t tried it but I don’t see any reason why it wouldn’t work.

No Comments

Create Animated GIF With Photoshop

Audio Visual No Comments

Creating an animated GIF is pretty easy with Adobe Photoshop. I will show you how I created the animated eye that you see to the right, using instructions from Build Animated GIFs in Photoshop. The secret is to use Photoshop’s Animation window.

Note: I found other web instructions that recommend using a Timeline window, but I could not find such a feature in my Adobe Photoshop CS5 version.

Layers Galore

The first step is to create layers, one or more of which together will construct each animation frame. While I could construct each frame using just one layer each, I decided to separate out the static “Animate Me” eyebrow image into its own layer and to include that layer in every frame.

  1. Create a new Photoshop project.
  2. The project is created with a default background layer.
  3. Draw the eyebrow. In my case, I wrote the eyebrow text using the Typing Tool and then warped the text using the Arc style.

I drew the eye using an oval for the outer rim and a circle for the pupil. (I lost the original image so re-created it to the right below by horizontally flipping one of the partial eye image and combining. That’s why the lines look too thick.)

To animate the eye blinking, I subtracted and added arc lines as necessary.

  1. Create a new layer by using menu Layer, New, Layer…, and click Ok.
  2. Select the new layer.
  3. Draw the eye using a circle and an oval.
  4. Duplicate the eye layer using menu Layer, Duplicate Layer…, and click Ok.
  5. Edit the eye by subtracting and adding arc lines.
  6. Repeat the above to create additional eye layers as necessary.

Animation Frames

Open the Animation window by going to menu Window and selecting Animation. The Animation window will appear at the bottom and there will be one frame already existing.

  1. To create another frame, select the existing frame and then click on the page icon (“Duplicates selected frames”) to the left of the trash icon (“Deletes selected frames”) at the bottom of the Animation window.
  2. Repeat to create the number of frames you desire.
  3. Select each frame and then select the layer(s) you want to be visible in that frame.
  4. The number of second(s) under each frame indicates the delay before the animation moves to the next frame. Adjust those delay times accordingly.

Note: Selecting the frame determines what is visible on the screen (that is, whatever layers are selected as visible in that frame). Selecting the layer (in the Layer window) still determines which layer a graphical operation will affect. To avoid confusion, you might want to manually ensure that the layer you select is enabled for the frame selected.

Save that GIF

To save the project to an animated GIF file, use menu File, Save for Web & Devices…. I just accept the defaults and click Save.

Note: If you save using menu File, Save As…, and select Format as “CompuServe GIF (*.GIF)”, you will end up with a static GIF image (containing the layer selected in the frame selected), not an animated GIF.

To test the GIF file, open it in a browser. If you open it in the default image or photo viewer, you will only see the first frame and no animation.

For your reference, you can download my Photoshop project file, animate_me.psd, containing the eye animation above.

No Comments

Re-install MacPorts After MacOS Upgrade

Mac OS X No Comments

I upgraded from Mac OS X 10.10 Yosemite to macOS 10.12 Sierra. After that, any MacPorts command I ran returned the following error:

Error: Current platform "darwin 16" does not match expected platform "darwin 14"
Error: If you upgraded your OS, please follow the migration instructions: https://trac.macports.org/wiki/Migration
OS platform mismatch
    while executing
"mportinit ui_options global_options global_variations"
Error: /opt/local/bin/port: Failed to initialize MacPorts, OS platform mismatch

The problem is that MacPorts is specific to a Mac OS X platform. The best way to fix this problem is to follow the Migrating a MacPorts installation guide.

Totally Clean Slate

MacPorts migration provides a “restore_ports.tcl” script to restore all the ports (a.k.a. packages) once you have upgraded MacPorts. However, I decided to start from a clean slate and only install ports as I needed them.

# Save list of installed ports (FYI for myself)
port -qv installed > ~/ports_installed.txt

# Save list of ports you manually installed (exclude dependency ports)
port installed requested > ~/ports_requested.txt

# Uninstall all installed ports
sudo port -f uninstall installed

# Clean any partially-completed builds
# Remove leftover build files (this should be done automatically already)
sudo rm -rf /opt/local/var/macports/build/*

# Remove download files
sudo rm -rf /opt/local/var/macports/distfiles/*

Note: I noticed that executables like svn (from subversion port) were left behind in /usr/bin and could still be used.

Partially Clean Slate

If you decide to keep your existing ports and to use the “restore_ports.tcl” script, you might consider cleaning out inactive packages:

# Get list of inactive ports you likely no longer need
# Alternative command: port echo inactive
port installed inactive

# Remove all of the inactive ports
sudo port uninstall inactive

Install macOS-specific MacPorts

Install the latest MacPorts for your macOS version:

  1. Install or upgrade to the latest version of Xcode Developer Tools (free from the Mac’s App Store) and run it once.
  2. Install the latest Command Line Developer Tools by running this command in the Terminal app:
    xcode-select --install
  3. Download and install the MacPorts package matching your Mac OS X version. It will overwrite the existing MacPorts installation.

Update MacPorts Configuration

The new MacPorts installer won’t modify the existing configuration file so you will need to update it manually. The updated configuration file “macports.conf.default” is located in the “/opt/local/etc/macports” directory. The old configuration file “macports.conf” is also in the same location.

Before overwriting the old file with the new, I recommend doing a file comparison:

cd /opt/local/etc/macports/
diff macports.conf macports.conf.default

Note: If you prefer a nice graphical user interface, you can use the FileMerge application which comes with Xcode. Just run FileMerge and input the paths to the two files to compare them.

There wasn’t any significant difference between the two files (beyond comments), but I went ahead and overwrote the old one with the new.

cd /opt/local/etc/macports/
sudo cp macports.conf.default macports.conf

Note: There are two other MacPorts configuration files, “variants.conf” and “sources.conf”, which the migration guide doesn’t mention. I compared them anyways and the only significant difference I found was in the “sources.conf” where the “rsync” value was different. I overwrote the “sources.conf” with the latest to ensure that everything is updated.

If you didn’t do a totally clean slate, you will want to follow the migration instructions on how to run the “restore_ports.tcl” script.

Some info above derived from:

No Comments

iPhone Missing From Windows 10 File Explorer

Mobile Devices, Windows No Comments

Under Windows 7, whenever I connected my iPhone, I would see a device drive appear in the File Explorer, which allowed me to manually copy photos from the iPhone to my computer. Under Windows 10, the device drive no longer appeared. I found the solution to this problem at iPhone doesn’t show up in Windows 10 File Explorer [Solved].

On my system, the cause is Windows 10 neglecting to install the “MTP USB Device” driver. MTP stands for Media Transfer Protocol, which Microsoft uses to allow access to files (like photos and videos) on iOS and Android devices. Under my Windows 10 machine, when I connect my iPhone, Windows 10 only installs the “Apple Mobile Device USB Driver” which iTunes uses. It does not install the “MTP USB Device” driver which File Explorer requires.

The solution is to manually install the “MTP USB Device” driver. This fix also worked for my iPad and iPod Touch.

Note: You may also have this problem under Windows 7 or 8. Or with an Android device. The steps below should still work.

Install MTP USB Device

To manually install the “MTP USB Device” driver:

  1. Connect the iPhone, iPad, or iPod to the Windows computer. Trust the computer if prompted to (only need to do this once when you first connect a new device).
  2. On the computer, run the “Device Manager” application.
  3. Open the “Universal Serial Bus controllers” section.
  4. Right-click on the “Apple Mobile Device USB Driver” and select “Update driver”. A dialog window will appear.
  5. Select “Browse my computer for driver software” and then “Let me pick from a list of available drivers on my computer”.
  6. Select the “MTP USB Device” driver in the “Show compatible hardware” listbox. Click Next.
  7. Once done, you will get a “Windows has successfully updated your drivers” message. Click Close to quit the dialog window.
  8. In the “Device Manager”, if you open “Portable Devices”, you will now see a new “MTP USB Device” driver listed. However, the device still doesn’t appear in the File Explorer and worse, the “Apple Mobile Device USB Driver” is gone (iTunes won’t show the attached device icon any longer).
  9. Disconnect and reconnect the iOS device. Windows will now load both the “Apple Mobile Device USB Driver” and “MTP USB Device” driver.
  10. The iOS device should now appear in the File Explorer under “This PC” and “Devices and drives”.

Note: If you check “Portable Devices” under the “Device Manager” again, you will now see the “Apple iPhone”, “Apple iPad”, or “Apple iPod” driver listed. The “MTP USB Driver” is renamed to the specific device type.

You should only need to manually install the “MTP USB Device” driver once for each new iOS device. Windows 10 should automatically load the “MTP USB Device” driver on subsequent connections.

Re-install MTP USB Device

I have seen a behavior when on a subsequent connection, Windows 10 did not successfully load the “MTP USB Device” for my iPhone. When I checked “Portable Devices” in the “Device Manager”, I saw the “Apple iPhone” driver with a caution icon, meaning it was in error state.

To fix the issue, I just right-clicked on the “Apple iPhone” and selected the “Update driver” option. And then I followed the instructions above from step 5 onward.

Hopefully your Windows 10 system does not have this problem. If it does, I hope the steps above will resolve your issue.

No Comments

Factory Image Flash a Nexus 5 Android Phone

Mobile Devices No Comments

I needed to re-image a Google Nexus 5 Android GSM smartphone with its stock factory image. Because I haven’t done this in a long while, I thought I would document what I did.

The instructions below should also work for the Google Pixel phone. I did the re-image using my Windows 10 desktop, but you can also do it on a Mac.

Note: Please backup your data because a factory image flash will destroy everything!

Install ADB and Fastboot

We need to install the software tools necessary to flash an Android phone. These are the Android Debug Bridge (adb), used to communicate with an Android device, and fastboot, used for writing directly to a device’s flash memory.

Thankfully, Google has separated these tools from the Android SDK into a smaller “SDK Platform Tools” package.

  1. Download the SDK Platform Tools package; I downloaded “platform-tools-latest-windows.zip”.
  2. Unzip to a directory, say “C:\Program Files\platform-tools”.
  3. Add that directory to the %PATH% environment variable.
  4. Launch a Command Prompt window and run “adb version”. I got “Android Debug Bridge version 1.0.39” as the response.

Enable USB Debugging

Enable USB debugging so adb can talk to the phone:

  1. On the phone, go to Settings, “About phone”, and scroll to the bottom until you see “Build number”.
  2. Click on the “Build number” seven times. You’ll see popups telling you how many times more to press to enable “Developer options”. (Ex: “You are now 3 steps away from being a developer.”)
  3. Once done (you’ll see a “You are now a developer!” popup message), go back to Settings and you will see a new menu “Developer options”. Click to go into it.
  4. Near the top, you will see an option “USB debugging”. Enable it.
  5. Plug the phone into the computer and answer “OK” when prompted with “Allow USB debugging?”. (Windows 10 was able to automatically find and install the Nexus 5 driver. If your operating system fails to do so, you may need to find and install the driver for your phone manually.)
  6. Open a Command Prompt window and run “adb devices”. It should list one device.

Note: You can see the status of and control how the USB connection behaves. On the connected phone, drag from the top, and you will see a message relating to the USB connection. If USB debugging is enabled, you will see the “USB debugging connected, Touch to disable USB debugging” message. If you disable USB, you will see a new “USB for charging, Touch for more options” message. You can change USB options to “File transfers” if you wish to browse files (such as pictures) located on the phone.

Find Factory Image

The hardest part of this process was finding the correct factory image to download for the Nexus 5. There were so many listed without any helpful instructions as to which image to download.

Here’s what I did:

  1. Locate Google’s Factory Images for Nexus and Pixel Devices page.
  2. Find the factory images for the “Nexus 5”, which is code-named “hammerhead”. (The “Nexus 5X” has code-name “bullhead”.)
  3. Locate the last image, which is the latest and greatest version, “6.0.1 (M4B30Z, Dec 2016)”. (“M4B30Z” and similar are build labels, not model numbers, as I originally thought. So any of them should work with the Nexus 5, though an older Nexus 5 image would prompt you to update the latest.)
  4. Unzip the downloaded “hammerhead-m4b30z-factory-625c027b.zip” file to any location; I just left the unzipped “hammerhead-m4b30z” folder in the Downloads folder.

Flash Factory Image

This is the easiest step because Google has provided a script with the factory image that does all the work.

  1. Open a Command Prompt window and change directory to the unzipped factory image folder.
  2. Run the “flash-all.bat” script. It only took 125 seconds to complete, ending with the message “finished. total time: 125.757s”.

The Nexus 5 then rebooted.

Note: It is recommended to do a data reset after a factory image flash. To do so, go to Settings on the phone, “Backup & reset”, and “Factory data reset”.

Need To Know

For your reading pleasure, below is the output of the “flash-all.bat” script:

C:\Users\username\Downloads\hammerhead-m4b30z> flash-all.bat
target reported max download size of 1073741824 bytes
sending 'bootloader' (3124 KB)...
OKAY [  0.316s]
writing 'bootloader'...
OKAY [  0.543s]
finished. total time: 0.863s
rebooting into bootloader...
OKAY [  0.100s]
finished. total time: 0.101s
target reported max download size of 1073741824 bytes
sending 'radio' (45489 KB)...
OKAY [  1.748s]
writing 'radio'...
OKAY [  3.130s]
finished. total time: 4.881s
rebooting into bootloader...
OKAY [  0.100s]
finished. total time: 0.102s
extracting android-info.txt (0 MB) to RAM...
extracting boot.img (8 MB) to disk... took 0.033s
target reported max download size of 1073741824 bytes
archive does not contain 'boot.sig'
archive does not contain 'dtbo.img'
archive does not contain 'dt.img'
extracting recovery.img (9 MB) to disk... took 0.061s
archive does not contain 'recovery.sig'
extracting system.img (996 MB) to disk... took 6.279s
archive does not contain 'system.sig'
archive does not contain 'vbmeta.img'
archive does not contain 'vendor.img'
wiping userdata...
mke2fs 1.43.3 (04-Sep-2016)
Creating filesystem with 7137786 4k blocks and 1785856 inodes
Filesystem UUID: b6135b46-f5a1-11e7-9dd3-33ea8476e3c7
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

wiping cache...
mke2fs 1.43.3 (04-Sep-2016)
Creating filesystem with 179200 4k blocks and 44832 inodes
Filesystem UUID: b66edade-f5a1-11e7-be2f-2fbe1c3d8ae8
Superblock backups stored on blocks:
        32768, 98304, 163840

Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

Bootloader Version...: HHZ20h
Baseband Version.....: M8974A-
Serial Number........: 04a0b345437de8e6
checking product...
OKAY [  0.100s]
checking version-bootloader...
OKAY [  0.098s]
checking version-baseband...
OKAY [  0.099s]
sending 'boot' (9156 KB)...
OKAY [  0.529s]
writing 'boot'...
OKAY [  0.780s]
sending 'recovery' (10014 KB)...
OKAY [  0.587s]
writing 'recovery'...
OKAY [  0.828s]
erasing 'system'...
OKAY [  0.988s]
sending 'system' (1020657 KB)...
OKAY [ 35.063s]
writing 'system'...
OKAY [ 69.580s]
erasing 'userdata'...
OKAY [ 14.754s]
sending 'userdata' (4416 KB)...
OKAY [  0.369s]
writing 'userdata'...
OKAY [  0.497s]
erasing 'cache'...
OKAY [  0.580s]
sending 'cache' (428 KB)...
OKAY [  0.229s]
writing 'cache'...
OKAY [  0.217s]

finished. total time: 125.757s
Press any key to exit...

For more details, I found this page, How to flash a factory image | Return to stock | Unroot your Nexus 5, very helpful.

No Comments