i0Q8X

BSD: INSTALL, COOKBOOK, PROCESSING INFO
=======================================

PART I. INSTALL
---------------

Virtual Box v.5.2.4

   OS: BSD, FreeBSD 64 bit
   RAM: 4096MB
   VIDEO: 128MB
   HD: Controller IDE, VHD 16GB
   ISO: FreeBSD-11.1-RELEASE-amd64-bootonly.iso

  ftp://ftp.freebsd.org      Main Site
  ftp://ftp.ee.freebsd.org   Estonia
  ftp://ftp.se.freebsd.org   Sweden

Fetching distribution

  base.txz
  kernel.txz

Region: Europe, Estonia, EET

  Default services: SSHD
  Invite virtu into other groups? []: wheel
  user: virtu  password: virtu
  user: root   password: root

Reboot.

  $ cat /etc/rc.conf
  hostname="darkstar"
  ifconfig_em0="DHCP"
  sshd_enable="YES"
  # Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable
  dumpdev="AUTO"

Localization

  https://cooltrainer.org/a-freebsd-desktop-howto/

Check locale

  root@darkstar:~ # locale
  LANG=
  LC_CTYPE="C"
  LC_COLLATE="C"
  LC_TIME="C"
  LC_NUMERIC="C"
  LC_MONETARY="C"
  LC_MESSAGES="C"
  LC_ALL=

Set locale

  root@darkstar:~ # locale -a | grep EE
  et_EE.ISO8859-1
  et_EE.ISO8859-15
  et_EE.UTF-8

Edit profile (et_EE.UTF-8 for Estonia: sort)

  # cp /etc/profile /etc/profile.orig
  ..
  # diff profile.orig profile
  18a19,21
  > LANG=en_US.UTF-8
  > LC_ALL=en_US.UTF-8
  > CHARSET=UTF-8

Edit login.conf

  # cp /etc/login.conf /etc/login.conf.orig
  ..
  # diff login.conf.orig login.conf
  49c49,51
  <       :umask=022:
  ---
  >       :umask=022:\
  >       :charset=UTF-8:\
  >       :lang=en_US.UTF-8:

Rebuild the login database with

  # cap_mkdb /etc/login.conf
  # reboot

Package managememt
..................

  # pkg
  The package management tool is not yet installed on your system.
  Do you want to fetch and install it now? [y/N]: y
  Bootstrapping pkg from
    pkg+http://pkg.FreeBSD.org/FreeBSD:11:amd64/quarterly
  please wait... Verifying signature with trusted certificate
  pkg.freebsd.org.2013102301... done
  Installing pkg-1.10.1...
  Extracting pkg-1.10.1: 100%
  pkg: not enough arguments
  Usage: pkg [-v] [-d] [-l] [-N]
             [-j <jail name or id>|-c <chroot path>|-r <rootdir>]
             [-C <configuration file>] [-R <repo config dir>]
             [-o var=value] [-4|-6] <command> [<args>]

  For more information on available commands and options see 'pkg help'.

  # pkg2ng
  Converting packages from /var/db/pkg
  Analysing shared libraries, this will take a while...
  Checking all packages: 100%

Building nano from source
-------------------------

  $ su # note that BSD's 'su -' is like Debian 'su' and vice versa
  # pkg info
  pkg-1.10.1                     Package manager

  # pkg install wget gettext ncurses
  # wget -c --no-check-certificate  \
      https://www.nano-editor.org/dist/v2.9/nano-2.9.1.tar.xz
  # tar xf nano-2.9.1.tar.xz
  # cd nano-2.9.1
  # ./configure
  # make
  # make install
  # rm -rf nano-2.9.1
  # nano --version
   GNU nano, version 2.9.1

Futher reading:
...............

  1. 8 Things to do after Installing FreeBSD 11 Unix System

    https://linoxide.com/distros/things-installing-freebsd-11/

PART II. COOKBOOK*0
-------------------

*0) 'Seenelkäik', 2012

    Also, "usually they speak there.." use this postulate to google
    the answer. Transform this to "usually we speak here.." in case
    you are human and Earth is your home planet:)

NOTE: data from i0QA5-Names.txt is used.

00. Using nano
..............
                            Bad Habit:)

Remember, there are billion of other hot keys still active!

  Help  -- ^g : (G)et Help    on screen (hint)
  Quit  -- ^x : e(X)it        on screen (hint)

  Save  -- ^o : Write (O)ut   on screen (hint)
  Find  -- ^w : (W)o ist?     on screen (hint)

  Cut   -- ^k : (K)ut         on screen (hint)
  Paste -- ^u : (U)nkut       on screen (hint)

And if you stretch the screen wider than about 1400 pixels, there's a hint at bottom right*4:

  Undo   -- m-u: (U)ndo       m for ALT (meta)
  Redo   -- m-e: r(E)do

Still have to remember:

  -- Hint area: priorities by pairs

    Most important: Help    2: File->Save    4: Find       6: Kut
    1:              Quit    3: File->Open    5: Replace    7: Unkut

  ctrl ^  switch visual marking on/off
  ctrl w  start search DIALOG [^W: Where is]
  alt  w  repeat search
  ctrl \  start replace DIALOG (a -- replace all instances)
  alt  #  toggle show line numbers
  alt  $  toggle ($)oftwrap (long line wrapping)
  alt  r  toggle regex search on/off (while in search)

Put your famous presets into ~/.nanorc

  set regexp        # enable regex search-replace
  set nohelp        # -x
  set linenumbers   # -l
  set morespace     # -O
  set softwrap      # -$

Tired enough? BTW, there is ncurses based midnight editor*6:

           The editor is very easy to use and requires no tutoring.
           To see what keys do what, just consult the appropriate
           pull-down menu.
           cat /usr/local/share/mc/help/mc.hlp | grep 'very easy'

  pkg install mc
  mc -u

Build from source

  pkg install autogen automake autoconfig autotools git get-text
  git clone git://github.com/MidnightCommander/mc.git
  sh autogen.sh
  ./configure (todo..)

  | Putty has ability to copy-paste. In mcedit, hold __SHIFT__ and     |
  | select by mouse                                                    |
  |                                                                    |
  |   https://superuser.com/questions/884245                           |
  |   /copy-and-paste-text-in-midnight-commander-mc-via-putty-in-linux |
  |                                                                    |
  | Good answer -- immediate reaction: LOL -..                         |

Your device doesn't allow to install editor of your choice? (not enough privileges, embedded system, etc..)

vi is usualy available. sometimes ed.

Found here:

  1. https://www.chrisnewland.com/find-and-replace-with-nano-47

  2. https://askubuntu.com/questions/73444
     /how-to-show-line-numbering-in-nano-when-opening-a-file

  3. https://stackoverflow.com/questions/7745535
     /regex-based-matching-and-sustitution-with-nano

  4. https://askubuntu.com/questions/332961/undo-functionality-in-nano

  5. https://unix.stackexchange.com/questions/122795
     /long-line-wrapping-in-nano

  6. https://forums.freebsd.org/threads/55627/

01. Space to Newline in sed
...........................

  $ echo Ärda Ääri Ääse Ääsi | sed 's/ /\
  > /g'
  Ärda
  Ääri
  Ääse
  Ääsi

  https://stackoverflow.com/questions/1421478
  /how-do-i-use-a-new-line-replacement-in-a-bsd-sed

Another way:

  echo Ärda Ääri Ääse Ääsi | sed -e 's/ /\'$'\n/g'

  http://nlfiedler.github.io/2010/12/05/newlines-in-sed-on-mac.html

02. Random
..........

  $RANDOM # 0..32767  `expr $RANDOM / 1424`  (0..23)

  ABC=(A B D E G H I J K L M N O P R S T U V Õ Ä Ö Ü)

  ${ABC[`expr $RANDOM / 1424`]}

  | shuf   # shuffle

03. Remove Newline with tr
..........................

  for c in R Õ B A K I D E L Ä T S O N U G V J Ö M P H Ü
  do
    echo $c
  done | sort | tr -d '\n'

  ABCDEFGHIJKLMNOPRSZTUVWÕÄÜ

04. Temporary locale
....................

  $ cat whatamess | LC_COLLATE="et_EE.UTF-8" sort | tr -d '\n'
  ABDEGHIJKLMNOPRSTUVÕÄÖÜ

  inspired by https://gist.github.com/earthgecko/3089509

05. lines from regexa to regexb: sed
....................................

   -n  By default, each line of input is echoed to the standard output
       after all of the commands have been applied to it.  The -n option
       suppresses this behavior.

  $ cat whatamess | sed -n '/Õ/,/A/p'
  Õ
  B
  A

  inspired by

    https://www.cyberciti.biz/faq
    /unix-linux-sed-print-only-matching-lines-command/

06. grep and regex OR
.....................

  $ cat surename | awk '{print $2}' | grep '\(kin\|dev\)$'
  Lebedev
  Sorokin
  Medvedev
  Lukin
  $ cat surename | awk '{print $2}' | grep '\(kin\)\|\(dev\)$'
  Lebedev
  Sorokin
  Medvedev
  Lukin

07. tar and BSD
...............

  $ tar cv -f - i0Q | bzip2 > i0Q.tar.bzip2
  a i0Q
  a i0Q/whatamess
  a i0Q/boys
  a i0Q/girls
  a i0Q/surename
  a i0Q/etc
  a i0Q/etc/profile
  a i0Q/etc/login.conf
  $ ls -l
  total 28
  drwxr-xr-x  3 virtu  virtu    512 Dec 26 18:57 i0Q
  -rw-r--r--  1 virtu  virtu  20767 Dec 26 19:02 i0Q.tar.bzip2

  PS G:\tmp> pscp virtu@192.168.1.226:/usr/home/virtu/i0Q.tar.bzip2 .
  Using keyboard-interactive authentication.
  Password for virtu@darkstar:
  i0Q.tar.bzip2             | 20 kB |  20.3 kB/s | ETA: 00:00:00 | 100%
  PS G:\tmp>

08. TAB character in bash?
..........................

For example:

  echo $string | sed 's/[_]/TAB/g'

Where TAB means the tab key (This works in a shell script not interactively).

  https://stackoverflow.com/questions/6392249
  /how-to-enter-a-tab-char-on-command-line

  | Precede it with Control+V, followed by TAB to suppress the usual   |
  | expansion behavior.                                                |

09. Set TAB size in bash
........................

Once:

  https://www.linuxquestions.org/questions/linux-general-1
  /tab-width-in-bash-how-do-i-set-it-322368/

  $ echo "hello   world" | expand -t 32
  hello                           world

  whatever | expand -t 24,34,52 # etc...

  $ echo -n "b    e" | expand -t 6 | od -x
  0000000      2062    2020    2020    0065
  0000007

Session:

  https://stackoverflow.com/questions/10782699
  /how-to-set-4-space-tab-in-bash

It's your terminal that manages the output. Use the tabs command to change the behavior:

  $ tabs 4

  $ echo -e "a\tb"
  a   b
  $ tabs 8

Note: Default is 8.

10. for..do..done or find?
..........................

  $ cd ~/poirot
  $ for each in '*.srt'; do grep -H 'gratitude' $each; done

  $ find . -name '*.srt' -exec grep -HnA1 'gratitude' {} \;
  ./poirot-3-8.srt:2592:it has the most sincere gratitude
  ./poirot-3-8.srt-2593-of Hercule Poirot.
  ..

11. diff and patch
..................

      .. ihr Vater litt an Angstattacken ..
      oder Schizophrenie?
      Alice. The Darkest Hour, 2018, 25:15

  $ echo 1 2 3 | tr ' ' '\n' > orig; cat orig
  1
  2
  3
  $ cp orig upd; ed upd
  6
  2c
  uuu
  .
  ,p
  1
  uuu
  3
  w
  8
  q
  $ diff orig upd | tee my.patch
  2c2
  < 2
  ---
  > uuu
  $ patch orig -i my.patch -o -
  patching file ppppp (read from orig)
  1
  uuu
  3

12. How to remove a file whose filename begins with a '-'

  https://unix.stackexchange.com/questions/1519
  /how-do-i-delete-a-file-whose-name-begins-with-hyphen-a-k-a-dash-
  or-minus

Use "--" to make rm stop parsing command line options, like this:

  rm -- --help

  '--' indicates the unambiguous end of options. Found in ubuntu bionic, man awk

III. MAKE USE OF FREEBSD BOX

1. BUILD NAWK WITH UNICODE SUPPORT
..................................

Build:

Install dependencies:

  # pkg install wget flex bison ncurses

Add missing header as /usr/include/utmp.h (found here:)

  http://www.retro11.de/ouxr/211bsd/usr/include/utmp.h.html

Code:

  #ifndef _UTMP_H_
  #define _UTMP_H_

  #define _PATH_UTMP  "/var/run/utmp"
  #define _PATH_WTMP  "/usr/adm/wtmp"

  #define UT_NAMESIZE 15
  #define UT_LINESIZE 8
  #define UT_HOSTSIZE 16
  struct utmp {
      char    ut_line[UT_LINESIZE];
      char    ut_name[UT_NAMESIZE];
      char    ut_host[UT_HOSTSIZE];
      long    ut_time;
  };

  #endif

Build libraries:

  $ wget -c --no-check-certificate https://freefr.dl.sourceforge.net
      /project/heirloom/heirloom/070715/heirloom-070715.tar.bz2
  $ tar xf heirloom-070715.tar.bz2

  $ cd /usr/home/virtu/heirloom-070715
  $ make
  $ cd nawk

Patch nawk with diff below and build it:

  $ diff main.c.orig main.c
  69c69
  < int main(int argc, unsigned char *argv[], unsigned char *envp[])
  ---
  > int main(int argc, char *argv[], char *envp[])
  $ make

Use:

  $ ./awk 'BEGIN {if (match("One Üks Ein"," [a-zÜ]+ ")) print RLENGTH}'
  5

2. LOOM (RETRO DOS GAME) IN A BROWSER
.....................................

  (todo...)
  Getting Started on FreeBSD

  https://www.ibm.com/developerworks/community/blogs/karsten/entry
  /emscripten_running_your_c_c_programs_web_pages?lang=en

  pkg install node www/npm python cmake
  wget -c --no-check-certificate https://s3.amazonaws.com/mozilla-games/emscripten/releases/emsdk-portable.tar.gz
  tar xf emsdk-portable.tar.gz
  cd emsdk-portable
  ./emsdk update
  ./emsdk install latest

  CTRL-F9     Kill (close) DOSBox

3. VISUAL PYTHON AND JUPYTER NOTEBOOK
.....................................

  (todo...)

4. PROCESSING TEXT FILES
........................

Source:

  http://nimi.ee/tudrukute-nimed
  http://nimi.ee/poiste-nimed

  $ cat boys | grep -v '^.\?$' | LC_COLLATE="et_EE.UTF-8" sort

  $ cat girls | grep -v '^.\?$' | LC_COLLATE="et_EE.UTF-8" sort

  $ cat girls | grep -v '^.\?$' | sed 's/ \+/\'$'\n/g' | wc -l
  2326

  $ cat boys | grep -v '^.\?$' | sed 's/ \+/\'$'\n/g' | wc -l
  2518

  $ cat surename | awk '{print $2 " "  $3}' | sed 's/[0-9]//g' | \
    grep "[^ ] [^ ]" | grep -v 'va$' | grep '[^aeiou] .\+a$'
  Nikitin Nikitina
  Kuzmin Kuzmina
  Iljin Iljina
  Sorokin Sorokina
  Kalinin Kalinina
  Fomin Fomina
  Voronin Voronina
  Kostin Kostina
  Lukin Lukina

Concusion:
  male   ^name(v|n)$

  $ cat surename | awk '{print $2 " "  $3}' | sed 's/[0-9]//g' | \
    grep "[^ ] [^ ]" | wc -l
       125

draft.. HINTS
.............

  while : ; do
    actions
    [[ current_time <= $cutoff ]] || break
  done

TIPS
....

create user, invite to group wheel

  # adduser

Use chpass to change user login settings

  /etc/rc.conf

To enable sshd in /etc/rc.conf

  sshd_enable="YES"

  /etc/rc.d/sshd start

Use following to add created user (virtu) to group wheel
(to make work su, sudo)

  # pw user mod virtu -G wheel
  # groups virtu

To activate network in

  # cat /etc/rc.conf
  ..
  ifconfig_em0="DHCP"
  ..

  # dhclient em0

Bootstrap pkg:

  # pkg
  # pkg2ng

Force pkg to reinstall

  https://forums.freebsd.org/threads/59313/

  # pkg-static bootstrap -f

To install gnome, firefox, gedit

  pkg install gnome-desktop gnome-terminal gdm xorg xf86-video-fbdev
  pkg install sudo firefox gedit

Add the following lines in /etc/rc.conf

  gnome_enable="YES"
  moused_enable="YES"
  dbus_enable="YES"
  hald_enable="YES"

To add guest additions to virtual box

  # pkg install virtualbox-ose-additions

Add the following lines in /etc/rc.conf

  vboxguest_enable="YES"
  vboxservice_enable="YES"

Now /etc/rc.conf looks like:

  sshd_enable="YES"
  ifconfig_em0="DHCP"
  gnome_enable="YES"
  moused_enable="YES"
  dbus_enable="YES"
  hald_enable="YES"
  vboxguest_enable="YES"
  vboxservice_enable="YES"

Now reboot, Gnome login starts automatically.

Annex A. FreeBSD on the Raspberry Pi B: A TL;DR
...............................................

  http://rollvs.uk/2016/07
  /freebsd-on-the-raspberry-pi-b-a-tldr/index.html

Don’t bother.

FreeBSD 10.3 (The latest production release) doesn’t have Hard Floats, which means it has to calculate all of it’s floating point arithmetic on the CPU. This means it’s dog slow. So slow, it’s pretty much unusable.

Installing and extracting the ports tree took over 6 hours.

Adding a 256Mb swapfile and increasing the maximum amount of tmpFS memory from 30Mb to 60Mb in /etc/fstab actually allowed it to compile pkg. Unfortunately, there were no binary packages by default.

it took four days of committed fiddling just to compile and install emacs, and even then it was too slow to use. While we’re at it, why are both Perl and Python required dependencies for a text editor written in C and Lisp? /gripe.

------------------------------------------------------------------------

BSD Book

  1. https://www.freebsd.org/doc/handbook/



Don’t get me wrong, I love FreeBSD and would install it on all my machines for daily work (hardware support willing), but it’s just not ready for this platform.