Make new git branch with current uncommitted changes

If you have already started work, but forgot to cut a new branch beforehand, you can fix the mistake.

Make a new branch with a command:

git checkout -b newbranchname

Then you can git add and git commit as needed.

References

Weblinks

Ripped off from Move existing, uncommitted work to a new branch in Git – Stack Overflow

Advertisements

Install 32-bit chroot on 64-bit devuan for compiling i386 packages

By accident, I installed 32-bit devuan instead of 64-bit, so all my self-hosted dpkgs didn’t work because they are for x86_64 architecture. So I started trying to compile the dpkgs in the new environment, and one in particular (palemoon) would always exhaust memory.

I found a wonderful reference [1] that explains how to set up a 32-bit chroot on 64-bit debian-based GNU/Linux. I tested my adaptation of the instructions on devuan ceres x86_64.

Install schroot and debootstrap.

sudo apt-get install schroot debootstrap

Set up schroot.

tf=/etc/schroot/chroot.d/ceres32
touch "${tf}" ; chmod 0644 "${tf}"
cat <<EOF >"${tf}"
[ceres32]
description=Devuan ceres 32-bit
directory=/32
type=directory
personality=linux32
users=bgstack15
groups=users,admin
EOF

Install the new distribution.

mkdir /32
debootstrap --arch i386 ceres /32 http://pkgmaster.devuan.org/merged

Now the chroot is minimally viable, but there are a few recommended steps to take before using it.
Symlink in the mtab.

ln -s /proc/mounts /32/etc/mtab

Copy in any system-wide setting as desired.

cp -p /etc/apt/apt.conf /32/etc/apt/      # for proxy settings
cp -p /etc/apt/sources.list /32/etc/apt/  # for universe, security, etc
cp -p /etc/environment /32/etc/           # for proxy and locale settings
cp -p /etc/sudoers /32/etc/               # for custom sudo settings

Disable services in the chroot.

tf=/32/usr/sbin/policy-rc.d
touch "${tf}" ; chmod 0755 "${tf}" ; chown root.root "${tf}" ;
cat <<EOF >"${tf}"
#!/bin/sh
## Don't start any service if running in a chroot.
## See /usr/share/doc/sysv-rc/README.policy-rc.d.gz
if [ "$(stat -c %d:%i /)" != "$(stat -c %d:%i /proc/1/root/.)" ]; then
  exit 101
fi
EOF

Now load up the chroot and prepare a few more packages.

schroot -c ceres32
sudo apt-get update
sudo apt-get install lsb-core

From here, you can install your build dependencies and build i386 dpkgs!

References

Weblinks

  1. Ripped entirely from How do I run 32-bit programs on a 64-bit Debian/Ubuntu? – Unix & Linux Stack Exchange

Age of Empires 2 on Linux – 2019 Edition

# Installing AoC on Linux without PlayOnLinux

## Variables

export AOCWINEPREFIX=~/.wine
export AOCDIR="${AOCWINEPREFIX}"/drive_c/Program\ Files/Microsoft\ Games/Age\ of\ Empires\ II
export voobly_desktop=~/.local/share/applications/Voobly.desktop
export aofe_desktop=~/.local/share/applications/TheForgottenEmpires.desktop
export aoc_desktop=~/.local/share/applications/TheConquerors.desktop
mkdir -p "$( dirname "${voobly_desktop}" )"

# Learn OS and flavor
. /usr/share/bgscripts/framework.sh

# Install wine-staging
# References:
#    https://wine-staging.com/installation.html
#    https://wiki.winehq.org/Debian
case "${thisflavor}" in
   ubuntu|debian|mint|devuan)
      sudo su -
      #wget -nc https://repos.wine-staging.com/wine/Release.key
      dpkg --add-architecture i386 # needed for winehq.org packages
      wget -nc https://dl.winehq.org/wine-builds/Release.key
      apt-key add Release.key && /bin/rm -f Release.key
      {
         echo "# And for Debian Sid this one:"
         echo "deb https://dl.winehq.org/wine-builds/debian/ sid main"
      } >> /etc/apt/sources.list.d/winehq.list
      apt-get update
      apt-get install -y winehq-staging winetricks
      test "${USER}" = "root" && exit
      ;;

   fedora|korora|centos|redhat)
      # Fedora already has wine staging
      sudo dnf -y install wine.i686 winetricks
      ;;
esac 

export WINEPREFIX="${AOCWINEPREFIX}"
export WINEARCH=win32

winetricks -q directplay

# mount AoE2 disc
sudo mkdir -p /mnt/aoe2
sudo mount -v -o loop /mnt/public/CDROMs/Games/AgeOfEmpires/ISO/AOE2.ISO /mnt/aoe2

# install AoE2
wine /mnt/aoe2/AOESETUP.EXE

# mount AoC disc
sudo mkdir -p /mnt/age2_x1
sudo mount -v -o loop /mnt/public/CDROMs/Games/AgeOfEmpires/ISO/AGE2_X1.ISO /mnt/age2_x1

# install AoC
wine /mnt/age2_x1/AOCSETUP.EXE

sudo umount -lv /mnt/age2_x1 ; sudo umount -lv /mnt/aoe2 ; sudo rmdir /mnt/aoe2 /mnt/age2_x1

# Install aoc 1.0c
cp -p /mnt/public/Support/Setups/Games/Age2XPatch.exe "${AOCDIR}"
wine "${AOCDIR}"/Age2XPatch.exe

# Install AoFE
# If the download is working.
#cp -p '/mnt/public/Age Of Empires/Downloaded/AoFE_Launcher.exe' "${AOCDIR}"
#pushd "${AOCDIR}"; wine "${AOCDIR}"/AoFE_Launcher.exe ; popd
# Alternate instruction for getting AoFE
pushd "${AOCDIR}" ; unzip '/mnt/public/Age Of Empires/Downloaded/fe_update.zip' ; mv Age2_x1/* age2_x1/ && rmdir Age2_x1 ; popd

# Install voobly
cp -p /mnt/public/Age\ Of\ Empires/Downloaded/voobly-v2.2.4.51.exe "${AOCDIR}"
wine "${AOCDIR}"/voobly-v2.2.4.51.exe

# get WololoKingdoms, as of 2018-09-22
# which I generated on my one Windows machine with the tool from https://github.com/AoE2CommunityGitHub/WololoKingdoms/releases and the Steam version of the game.
wk_dir="${AOCDIR}/Voobly Mods/AOC/Data Mods"
mkdir -p "${wk_dir}"
pushd "${wk_dir}" ; time 7za x /mnt/public/Age\ Of\ Empires/Wololo\ Kingdoms/WololoKingdoms.full.2018-09-11.zip ; popd

# customize voobly desktop file
tf=${AOCWINEPREFIX}/voobly.sh
touch "${tf}"; chmod 0755 "${tf}"
cat < "${tf}"
#!/bin/sh
env WINEPREFIX="${WINEPREFIX}" STAGING_WRITECOPY=1 /usr/bin/wine C:\\\\Program\\ Files\\\\Voobly\\\\voobly.exe
EOFVOOBLYSH

mkdir -p ~/.local/share/icons
cp -p '/mnt/public/Age Of Empires/Images/voobly.png' ~/.local/share/icons/
touch "${voobly_desktop}"; chmod 0755 "${voobly_desktop}"
cat < "${voobly_desktop}"
[Desktop Entry]
Name=Voobly
Exec="${tf}"
Type=Application
StartupNotify=true
Path=${WINEPREFIX}/dosdevices/c:/Program Files/Voobly
Icon=/home/${USER}/.local/share/icons/voobly.png
StartupWMClass=voobly.exe
Comment=Matchmaking service for AoC
Categories=Game;StrategyGame;
EOFVOOBLY

# customize AoFE desktop file
cp -p '/mnt/public/Age Of Empires/Images/age2_x2.png' ~/.local/share/icons/
touch "${aofe_desktop}"; chmod 0755 "${aofe_desktop}"
cat < "${aofe_desktop}"
[Desktop Entry]
Name=The Forgotten Empires
Exec=env WINEPREFIX="${WINEPREFIX}" /usr/bin/wine "${AOCDIR}/age2_x1/age2_x2.exe" /nostartup
Type=Application
StartupNotify=true
Path=${AOCDIR}
Icon=/home/${USER}/.local/share/icons/age2_x2.png
StartupWMClass=age2_x1.exe
Comment=Forgotten Empires 2.2 mod for AoC
Categories=Game;StrategyGame;
EOFAOFE

# customize AoC desktop file
thisicon="$( find ~ -regex '.*.local.*age2_x1.*png' 2>/dev/null | sort | tail -n1 )"
touch "${aoc_desktop}"; chmod 0755 "${aoc_desktop}"
cat < "${aoc_desktop}"
[Desktop Entry]
Name=The Conquerors
Exec=env WINEPREFIX="${WINEPREFIX}" /usr/bin/wine "${AOCDIR}/age2_x1/age2_x1.exe" /nostartup
Type=Application
StartupNotify=true
Path=${AOCDIR}
Icon=${thisicon}
StartupWMClass=age2_x1.exe
Comment=Age of Empires 2: The Conquerors Expansion
Categories=Game;StrategyGame;
EOFAOC

echo done

Firefox disable recommended extensions

Firefox apparently is trying to jump the shark with even more pocket-esque behavior. This is why I install Pale Moon (and its Linux page) on my new builds instead of Firefox.

I normally schedule my posts, in case you couldn’t tell, for the morning of every fourth day. But this post is going out immediately.

Disable Firefox’s “Contextual Feature Recommender” with this entry in prefs.js:

user_pref("browser.newtabpage.activity-stream.asrouter.userprefs.cfr", false);

You can extrapolate the about:config option.

Other places on the Internet show you how to do it through the gui if you prefer.

References

My own research (diff prefs.js prefs.js.old)

List files in dpkg that is not installed

Ripped directly from dpkg – How do I get a list of installed files from a package? – Ask Ubuntu
To see all the files the package installed onto your system, do this:

dpkg-query -L

To see the files a .deb file will install

dpkg-deb -c

To see the files contained in a package NOT installed, do this once (if you haven’t installed apt-file already:

sudo apt-get install apt-file
sudo apt-file update

then

apt-file list

xorg show current config

If you already have X running, and you try to generathe the xorg.conf file, you might get an error.

$ sudo Xorg -configure 
(EE) 
Fatal server error:
(EE) Server is already active for display 0
        If this server is no longer running, remove /tmp/.X0-lock
        and start again.
(EE) 
(EE) 
Please consult the The X.Org Foundation support 
         at http://wiki.x.org
 for help. 
(EE) 

What you need to do is use another virtual display/terminal/whatever (I’m still learning these terms).

sudo X :2 -configure

Thanks to Joe-ubunt at the Ubuntu Forums: [SOLVED] generate xorg.conf from current configuration

FreeFileSync 10.9 on CentOS 7

Now, you can go install FreeFileSync 10.9 on CentOS 7 from an rpm built on CentOS 7! The upstream release follows some newer versions of libs (clearly compiled on a different platform than CentOS or even Fedora), and I have now compiled those versions based on the work of a genius fellow over at city-fan.

To get FreeFileSync on CentOS 7, you need to load up two of my coprs as seen in the following table.

COPR name repo file
bgstack15/stackrpms bgstack15-stackrpms-epel-7.repo
bgstack15/FreeFileSync bgstack15-FreeFileSync-epel-7.repo

The application depends on some newer libs, which are all available in a second copr.

======================================================================================
 Package                   Arch   Version                Repository              Size
======================================================================================
Installing:
 freefilesync              x86_64 10.9-2.el7             bgstack15-stackrpms    3.2 M
Installing for dependencies:
 libpsl                    x86_64 0.7.0-1.el7            bgstack15-FreeFileSync  45 k
 openssl-freefilesync-libs x86_64 1:1.1.0h-3.stack.el7   bgstack15-FreeFileSync 1.2 M
Updating for dependencies:
 curl                      x86_64 7.64.0-2.0.cf.rhel7    bgstack15-FreeFileSync 557 k
 libcurl                   x86_64 7.64.0-2.0.cf.rhel7    bgstack15-FreeFileSync 502 k
 libssh2                   x86_64 1.8.0-10.0.stack.rhel7 bgstack15-FreeFileSync 103 k

Transaction Summary
======================================================================================
Install  1 Package  (+2 Dependent packages)
Upgrade             ( 3 Dependent packages)

Total download size: 5.6 M
Is this ok [y/d/N]: 

The artifacts used to produce this build are in my gitlab.

CentOS 7 learn used grub entry

With the major changes introduced in CentOS 7 from CentOS 6 (systemd, grub2, and more), determining exactly which grub menu entry will be used at next boot is a little more difficult than before.

I wrote a quick script that calculates this for you: learn-used-grub-entry

#!/bin/sh
# File: learn-used-grub-entry
# Location: /usr/bin
# Author: bgstack15
# Startdate: 2019-01-28 11:27
# Title: Script that Determines Which Grub Entry Will be Used
# Purpose:
# Package: bgscripts
# History:
# Usage:
#    for RHEL7/grub2
# Reference:
#    original research
# Improve:

test -z "${LUGE_GRUB_CFG}" && LUGE_GRUB_CFG=/boot/grub2/grub.cfg
test -z "${LUGE_ETC_DEFAULT_GRUB}" && LUGE_ETC_DEFAULT_GRUB=/etc/default/grub
# use option LUGE_OUTPUT which is one of ["kernel","","initram"]

grub_saved_name="$( grub2-editenv - list | awk -F'=' '{print $NF}' )"
use_number="$( awk -F'=' '/^GRUB_DEFAULT/{print $NF}' "${LUGE_ETC_DEFAULT_GRUB}" )"

use_entry=""
# calculate true value
if test "$( echo "${use_number}" | tr '[[:upper:]]' '[[:lower:]]' )" = "saved" ;
then
   # it is the saved value (which is same as last used)
   use_entry="${grub_saved_name}"
else
   # calculate used name from number
   use_entry="$( grep -E -e '^menuentry' "${LUGE_GRUB_CFG}" | sed -r -n -e "$(( use_number + 1 ))p" )"
fi

# calculate which value to display or just display name
LUGE_grep=1
case "${LUGE_OUTPUT:-${1}}" in

   "num" | "number" )
      # just show the number
      unset LUGE_grep
      echo "${use_number}"
      ;;

   "kernel"|"vmlinuz" )
      # show kernel
      LUGE_regex="linux(16|32|64)"
      LUGE_awk_val='$2'
      ;;

   "initram" | "initrd" | "initramfs" )
      # show initram
      LUGE_regex="initrd|initram"
      LUGE_awk_val='$2'
      ;;

   *)
      # DEFAULT VALUE, so mistyped or not defined
      unset LUGE_grep
      echo "${use_entry}"
      ;;
esac

# show complicated value if necessary
if test -n "${LUGE_grep}" ;
then
   sed -n -r -e "/${use_entry}/,/^\s*\}/p" "${LUGE_GRUB_CFG}" | awk "/${LUGE_regex}/{print ${LUGE_awk_val}}"
fi

# exit cleanly
true

Run game in dosbox and make nice menu icon for it

When I want to play an old-school DOS game, I use the emulator DOSBox. I discovered that DOSBox has its own icon and uses its title in the window, and not the name of the game running inside. I now have a solution to change the icon and title that I want.

First of all, I make my .desktop file call my shell script.

$ cat ~/.local/share/applications/st25.desktop
[Desktop Entry]
Version=1.0
Name=Star Trek 25th Anniversary
Comment=1993 DOS computer game
Keywords=Game;Star Trek;
Exec=/usr/share/st25/st25.sh
Terminal=false
X-MultipleArgs=false
Type=Application
Icon=/usr/share/st25/st25.png
Categories=Game;AdventureGame;

The shell script calls dosbox with the custom batch file (from the olden days of non-free operating systems)

$ cat /usr/share/st25/st25.sh
#!/bin/sh
# Star Trek: 25th Anniversary game
GAMEDIR=/usr/share/st25
ICONFILE="${GAMEDIR}/st25.png"
cd "${GAMEDIR}"
dosbox ST25.BAT &
sleep 1
tid="$( xwininfo -root -children -all | grep -iE "dosbox.*STARTREK" | awk '{print $1}' )"
echo "modifying id ${tid}"
xseticon -id "${tid}" "${ICONFILE}"
xdotool set_window --name "STARTREK" "${tid}"
xdotool search --name "STARTREK" set_window --classname "STARTREK" --class "STARTREK" windowunmap windowmap

The above shell script is where the magic happens. The main emulator is executed and placed in the background. After a short delay, some X tools are used to find the specific application’s window ID.
A custom application named xseticon (available in my Fedora copr) written by Paul Evans is used to change the icon used by the window.
The more easily available xdotool (probably already bundled by your distro) can change the window name.
Additionally, xdotool can hide and re-show the window, to make the window manager and panel recognize the new icon and name!

And just for completeness’s sake, here is the batch file.

$ cat /usr/share/st25/ST25.BAT
REM ST25.BAT
REM Star Trek: 25th Anniversary game

MOUNT C /usr/share/st25
C:
STARTREK.EXE
exit

Conclusion

This is my preferred way to run a DOS-based application: desktop file, shell script, batch file. Yes, it spawns the extra process with the shell script, but I want to be able to call an application from the command line easily.

How do you make your DOS programs accessible to users on cli or the desktop?

References

For a complete list of Internet resources used to build this process, see my other post, X11 change application titlebar and icon in window manager panel.