Simple script to create Mac OS installation .iso media

Preamble

It is supposed, that you downloaded it with App Store, and it is stored as .app in your /Applications directory.

Below is script. The only parameter you have to customize is a “DIST” variable, which should be your distributive name (“Mojave”, “Catalina” and so on).

This article is based on instructions from techsviewer.com

As a result you should get .iso file on your desktop with name of your distributive (e.g. “Catalina.iso”).

Script

create-macos-iso.sh

DIST=Mojave
DMG_FILE=/tmp/$DIST
DMG_FILE_EXT=/tmp/$DIST.dmg
VOL_NAME=/Volumes/$DIST
INSTALL_APP="Install macOS $DIST.app"
MEDIA_VOL="Install macOS $DIST"
CDR_FILE="$HOME/Desktop/$DIST.cdr"
ISO_FILE="$HOME/Desktop/$DIST.iso"

echo Create dmg... &&
hdiutil create -o $DMG_FILE -size 8500m -volname $VOL_NAME \
       -layout SPUD -fs HFS+J &&

echo Attach dmg... &&
hdiutil attach $DMG_FILE_EXT -noverify -mountpoint $VOL_NAME &&

echo Create install media... &&
sudo /Applications/"$INSTALL_APP"/Contents/Resources/createinstallmedia \
    --volume $VOL_NAME --nointeraction &&

echo Detach $MEDIA_VOL... &&
hdiutil detach /Volumes/"$MEDIA_VOL" &&

echo Convert $DMG_FILE_EXT -\> $CDR_FILE &&
hdiutil convert $DMG_FILE_EXT -format UDTO -o $CDR_FILE &&

echo Rename $CDR_FILE -\> $ISO_FILE &&
mv $CDR_FILE $ISO_FILE &&

echo Cleanup... &&
rm $DMG_FILE_EXT

Anti make install

What to do if you accidentally installed some experimental project to your system folder? Are here any ways to undo install script. Here is a simple solution.

Preamble

below may work or may not, this is all given as-is, you and only you are responsible person in case of some damage, data loss and so on. But I hope things go smooth!

To undo `make install` I would do (and I did) this:

Idea: check whatever script installs and undo this with simple bash script.

1. Reconfigure your build dir to install to some custom dir. I usually do this: `–prefix=$PWD/install`. For CMake, you can go to your build dir, open CMakeCache.txt, and fix CMAKE_INSTALL_PREFIX value.
2. Install project to custom directory (just run `make install` again).
3. Now we push from assumption, that `make install` script installs into custom dir just same contents you want to remove from somewhere else (usually `/usr/local`). So, we need a script.
3.1. Script should compare custom dir, with dir you want clean. I use this:

anti-install.sh

RM_DIR=$1
PRESENT_DIR=$2

echo "Remove files from $RM_DIR, which are present in $PRESENT_DIR"

pushd $RM_DIR

for fn in `find . -iname '*'`; do
# echo "Checking $PRESENT_DIR/$fn..."
if test -f "$PRESENT_DIR/$fn"; then
# First try this, and check whether things go plain
echo "rm $RM_DIR/$fn"

# Then uncomment this, (but, check twice it works good to you).
# rm $RM_DIR/$fn
fi
done

popd

3.2. Now just run this script (it will go dry-run)

bash anti-install.sh <dir you want to clean> <custom installation dir>

E.g. You wan’t to clean /usr/local, and your custom installation dir is /user/me/llvm.build/install, then it would be

bash anti-install.sh /usr/local /user/me/llvm.build/install

3.3. Check log carefully, if commands are good to you, uncomment `rm $RM_DIR/$fn` and run it again. But stop! Did you really check carefully? May be check again?

Good luck!

C++ sql-like Select example (imperfect)

I just would like to keep it here…

May be there is better implementation? Spent on it 30 mins, have no more time today.

// select.cpp

#include <vector>
#include <iostream>

  template<
      typename OutputCollectionT,
      typename OutputItemT = typename OutputCollectionT::value_type
  >
  class Select {
  public:
      template<
          typename InputCollectionT,
          typename InputItemT = typename InputCollectionT::value_type
      >
      class From {
      public:
          static OutputCollectionT Do(
              const InputCollectionT &Input,
              std::function<OutputItemT(const InputItemT &In)> Selector
          ) {
            OutputCollectionT Out;
            for (const InputItemT &In : Input) {
              Out.push_back(Selector(In));
            }
            return Out;
          }
      };
  };

struct A {
    int P1;
    int P2;
    int P3;
};

struct B {
    int P1;
    int P3;
};

int main() {
  std::vector<A> aa = {
      {1, 2, 3},
      {2, 3, 4},
      {3, 4, 5}
  };

  auto bb = Select<std::vector<B>>::From<std::vector<A>>::Do(
      aa, [=] (const A &a) -> B {
        return { a.P1, a.P3 };
      }
  );

  for (auto &b : bb) {
    std::cout
    << "P1:" << b.P1 << ", "
    << "P3:" << b.P3 << "\n";
  }

  return 0;
}

The music of waves (translation of Victor Tsoy song)

I have seen as waves wipe out the footprints on sand.
I have heard as wind sings his song of  the weird.
I have heard as trees strings playing this.

The music of waves.
The music of wind.

It’s hard to say here what the asphalt means.
It’s hard to say here what the vehicle means.
You have here to toss the water up.

The music of waves.
The music of wind.

Who of us remember those who stepped out the way?
Who of us remember those who laughed to sang.
Who of us remember feeling the coldness of gun butt…

The music of waves.
The music of wind.

Stepan Dyatkovskiy: experience, vids, articles and other!