Skip to content

Instantly share code, notes, and snippets.

@hoggren
Last active August 21, 2020 23:02
Show Gist options
  • Select an option

  • Save hoggren/c7a9ebc2e7d02a8a35ae0adc48261cd6 to your computer and use it in GitHub Desktop.

Select an option

Save hoggren/c7a9ebc2e7d02a8a35ae0adc48261cd6 to your computer and use it in GitHub Desktop.

Revisions

  1. hoggren revised this gist Aug 21, 2020. 2 changed files with 25 additions and 23 deletions.
    23 changes: 0 additions & 23 deletions Bootable USB for MacOS
    Original file line number Diff line number Diff line change
    @@ -1,23 +0,0 @@
    #!/bin/bash
    # Usage: ./bootableusb_for_mac.sh /dev/diskX isofile.iso
    USBDISK=$1
    ISOFILE=$2
    TMPFILE="tempoutput"

    if [ "$(whoami)" != "root" ]; then
    echo "no root, qutting"
    exit 0
    fi

    echo "Write image $ISOFILE to $USBDISK, type yes to confirm:"

    read INPUT
    if [ "$INPUT" != "yes" ]; then
    echo "quitting"
    exit 0
    fi

    diskutil unmountDisk $USBDISK
    hdiutil convert -format UDRW -o $TMPFILE $ISOFILE
    dd if=$TMPFILE.dmg of=$USBDISK bs=1m
    rm $TMPFILE.dmg
    25 changes: 25 additions & 0 deletions bootable_usb4mac.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    #!/bin/bash
    # Usage: ./bootable_usb4mac.sh /dev/rdiskX isofile.iso
    # Writing to /dev/rdiskX requires root privilegies, and rdisk is FASTER
    # https://superuser.com/questions/631592/why-is-dev-rdisk-about-20-times-faster-than-dev-disk-in-mac-os-x/631601
    USBDISK=$1
    ISOFILE=$2
    TMPFILE="tempoutput"

    if [ "$(whoami)" != "root" ]; then
    echo "no root, qutting"
    exit 0
    fi

    echo "Write image $ISOFILE to $USBDISK, type YES to confirm:"

    read INPUT
    if [ "$INPUT" != "YES" ]; then
    echo "quitting"
    exit 0
    fi

    diskutil unmountDisk $USBDISK
    hdiutil convert -format UDRW -o $TMPFILE $ISOFILE
    dd if=$TMPFILE.dmg of=$USBDISK bs=1m
    rm $TMPFILE.dmg
  2. hoggren revised this gist Jul 22, 2020. No changes.
  3. hoggren revised this gist Jul 22, 2020. 2 changed files with 0 additions and 20 deletions.
    File renamed without changes.
    20 changes: 0 additions & 20 deletions macos_terminal_goodies2.sh
    Original file line number Diff line number Diff line change
    @@ -1,20 +0,0 @@
    #!/bin/zsh
    # Get version number and name of therunning on a MacOS.
    #
    # Last update: 2019-12-21
    # Author: Patrik Hoggren <[email protected]>

    # MAJOR=`sw_vers -productVersion | awk -F '[.]' '{print $1}'`;
    MINOR=`sw_vers -productVersion | awk -F '[.]' '{print $2}'`;
    # PATCH=`sw_vers -productVersion | awk -F '[.]' '{print $3}'`;

    typeset -A hash
    hash[10]="Yosemite"
    hash[11]="El Capitan"
    hash[12]="Sierra"
    hash[13]="High Sierra"
    hash[14]="Mojave"
    hash[15]="Catalina"
    hash[16]="<Time for some maintenance for this script...>"

    macos_name=${hash[$MINOR]};
  4. hoggren revised this gist Dec 22, 2019. 2 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
  5. hoggren revised this gist Dec 22, 2019. 3 changed files with 43 additions and 51 deletions.
    23 changes: 23 additions & 0 deletions create_bootable_usb.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    #!/bin/bash
    # Usage: ./bootableusb_for_mac.sh /dev/diskX isofile.iso
    USBDISK=$1
    ISOFILE=$2
    TMPFILE="tempoutput"

    if [ "$(whoami)" != "root" ]; then
    echo "no root, qutting"
    exit 0
    fi

    echo "Write image $ISOFILE to $USBDISK, type yes to confirm:"

    read INPUT
    if [ "$INPUT" != "yes" ]; then
    echo "quitting"
    exit 0
    fi

    diskutil unmountDisk $USBDISK
    hdiutil convert -format UDRW -o $TMPFILE $ISOFILE
    dd if=$TMPFILE.dmg of=$USBDISK bs=1m
    rm $TMPFILE.dmg
    51 changes: 0 additions & 51 deletions get-macos-name.sh
    Original file line number Diff line number Diff line change
    @@ -1,51 +0,0 @@
    #!/bin/bash
    # Shell script for bash running on
    # Get version numbers ond the OS name running on a MacOS.
    #
    # Last update: 2019-03-15
    # Author: Patrik Hoggren <[email protected]>

    # MIT License is supplied with this file.
    # If not, you should find it at:
    # http://www.github.com/phoggren/get-macos-name

    if [ "$BASH_ARGV" == "-h" ]; then
    echo "";
    echo " get-macos-name 0.1.0";
    echo "";
    echo "Usage: [-h]";
    echo " -h: Show this message.";
    echo "";
    echo "Outputs the OS version name";
    echo "";
    exit 1;
    fi

    # could be nice to have for some other script :)
    # MAJOR="sw_vers -productVersion | awk -F '[.]' '{print \$1}'";
    MINOR="sw_vers -productVersion | awk -F '[.]' '{print \$2}'";
    # PATCH="sw_vers -productVersion | awk -F '[.]' '{print \$3}'";

    # ANS1=`eval $MAJOR`;
    ANS2=`eval $MINOR`;
    # ANS3=`eval $PATCH`;

    NICEMAP=(
    [10] = "Yosemite"
    [11] = "El Capitan"
    [12] = "Sierra"
    [13] = "High Sierra"
    [14] = "Mojave"
    [15] = "NextV"
    [16] = "<Time for some maintenance for this script...>"
    );

    # maps the OS minor version number (10.x.5) with table above
    MACOS_NAME="${NICEMAP[$ANS2]}";

    if [ -n "$MACOS_NAME" ]; then
    echo $MACOS_NAME;
    exit 0;
    fi

    exit 1;
    20 changes: 20 additions & 0 deletions macos_name.zsh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    #!/bin/zsh
    # Get version number and name of therunning on a MacOS.
    #
    # Last update: 2019-12-21
    # Author: Patrik Hoggren <[email protected]>

    # MAJOR=`sw_vers -productVersion | awk -F '[.]' '{print $1}'`;
    MINOR=`sw_vers -productVersion | awk -F '[.]' '{print $2}'`;
    # PATCH=`sw_vers -productVersion | awk -F '[.]' '{print $3}'`;

    typeset -A hash
    hash[10]="Yosemite"
    hash[11]="El Capitan"
    hash[12]="Sierra"
    hash[13]="High Sierra"
    hash[14]="Mojave"
    hash[15]="Catalina"
    hash[16]="<Time for some maintenance for this script...>"

    macos_name=${hash[$MINOR]};
  6. hoggren created this gist Jul 25, 2019.
    51 changes: 51 additions & 0 deletions get-macos-name.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    #!/bin/bash
    # Shell script for bash running on
    # Get version numbers ond the OS name running on a MacOS.
    #
    # Last update: 2019-03-15
    # Author: Patrik Hoggren <[email protected]>

    # MIT License is supplied with this file.
    # If not, you should find it at:
    # http://www.github.com/phoggren/get-macos-name

    if [ "$BASH_ARGV" == "-h" ]; then
    echo "";
    echo " get-macos-name 0.1.0";
    echo "";
    echo "Usage: [-h]";
    echo " -h: Show this message.";
    echo "";
    echo "Outputs the OS version name";
    echo "";
    exit 1;
    fi

    # could be nice to have for some other script :)
    # MAJOR="sw_vers -productVersion | awk -F '[.]' '{print \$1}'";
    MINOR="sw_vers -productVersion | awk -F '[.]' '{print \$2}'";
    # PATCH="sw_vers -productVersion | awk -F '[.]' '{print \$3}'";

    # ANS1=`eval $MAJOR`;
    ANS2=`eval $MINOR`;
    # ANS3=`eval $PATCH`;

    NICEMAP=(
    [10] = "Yosemite"
    [11] = "El Capitan"
    [12] = "Sierra"
    [13] = "High Sierra"
    [14] = "Mojave"
    [15] = "NextV"
    [16] = "<Time for some maintenance for this script...>"
    );

    # maps the OS minor version number (10.x.5) with table above
    MACOS_NAME="${NICEMAP[$ANS2]}";

    if [ -n "$MACOS_NAME" ]; then
    echo $MACOS_NAME;
    exit 0;
    fi

    exit 1;