Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial attempt at a portable MSYS2 #245

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 128 additions & 0 deletions make-file-list-msys2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#!/bin/sh

die () {
echo "$*" >&2
exit 1
}

test -n "$ARCH" &&
test -n "$BITNESS" ||
die "Need ARCH and BITNESS to be set"

pacman_list () {
package_list=$(for arg
do
pactree -u "$arg"
done |
grep -v "^\\($(echo $PACKAGE_EXCLUDES | sed \
-e 's/ /\\|/g' \
-e 's/mingw-w64-/&\\(i686\\|x86_64\\)-/g')\\)\$" |
sort |
uniq) &&
if test -n "$PACKAGE_VERSIONS_FILE"
then
pacman -Q $package_list >"$PACKAGE_VERSIONS_FILE"
fi &&
pacman -Ql $package_list |
grep -v '/$' |
sed 's/^[^ ]* //'
}

install_required () {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't include the stuff about include despite upgrade as guessed it wouldn't be needed

# TODO some of these might not be wanted
# Packages that have been added after Git SDK 1.0.0 was released...
required=
for req in mingw-w64-$ARCH-git-credential-manager $SH_FOR_REBASE
do
test -d /var/lib/pacman/local/$req-[0-9]* ||
test -d /var/lib/pacman/local/$req-git-[0-9]* ||
required="$required $req"
done
test -z "$required" ||
pacman -Sy --noconfirm $required >&2 ||
die "Could not install required packages: $required"
}

this_script_dir="$(cd "$(dirname "$0")" && pwd -W)" ||
die "Could not determine this script's dir"

install_required

SH_FOR_REBASE=dash

BASE_PACKAGES="$(pacman -Qg base | awk '{print $2}' | tr '\n' ' ')"
Copy link
Author

@SteveALee SteveALee Mar 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Peobably don;t need all these. Possible remove via PACKAGE_EXCLUDES

GIT_PACKAGES="mingw-w64-$ARCH-git mingw-w64-$ARCH-git-credential-manager git-extra openssh"
UTIL_PACKAGES=
packages="$BASE_PACKAGES $GIT_PACKAGES $UTIL_PACKAGES"

# TODO need this? should be a parameter? Use BITNESS?
PACKAGE_EXCLUDES="db info heimdal git util-linux curl git-for-windows-keyring
mingw-w64-p11-kit filesystem msys2-launcher-git rebase"
# TODO 05-home-dir.post required by filesystem package but is missing from SDK
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason this file wanted but I was missing it in my SDK

# TODO should we exlude all the tz stuff?
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of stuff like perl (needed or git) Local and TZ files really bloat the zip but I don;t kno when might be needed

EXTRA_FILE_EXCLUDES="/etc/post-install/05-home-dir.post
/mingw$BITNESS/libexec/git-core/git-update-git-for-windows"

pacman_list $packages "$@" |
grep -v -e '\.[acho]$' -e '\.l[ao]$' -e '/aclocal/' \
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not clear if these filters are actually useful given my almost completely different package list

-e '/man/' -e '/pkgconfig/' -e '/emacs/' \
-e '^/usr/lib/python' -e '^/usr/lib/ruby' \
-e '^/usr/share/subversion' \
-e '^/etc/skel/' -e '^/mingw../etc/skel/' \
-e '^/usr/bin/svn' \
-e '^/usr/bin/xml.*exe$' \
-e '^/usr/bin/xslt.*$' \
-e '^/mingw../share/doc/openssl/' \
-e '^/mingw../share/doc/gettext/' \
-e '^/mingw../share/doc/lib' \
-e '^/mingw../share/doc/pcre2\?/' \
-e '^/mingw../share/doc/git-doc/.*\.txt$' \
-e '^/mingw../lib/gettext/' -e '^/mingw../share/gettext/' \
-e '^/usr/include/' -e '^/mingw../include/' \
-e '^/usr/share/doc/' \
-e '^/usr/share/info/' -e '^/mingw../share/info/' \
-e '^/mingw../share/git-doc/technical/' \
-e '^/mingw../itcl/' \
-e '^/mingw../t\(cl\|k\)[^/]*/\(demos\|msgs\|encoding\|tzdata\)/' \
-e '^/mingw../bin/\(autopoint\|[a-z]*-config\)$' \
-e '^/mingw../bin/lib\(asprintf\|gettext\|gnutlsxx\|pcre[013-9a-oq-z]\|quadmath\|stdc++\)[^/]*\.dll$' \
-e '^/mingw../bin/\(asn1\|gnutls\|idn\|mini\|msg\|nettle\|ngettext\|ocsp\|pcre\|rtmp\|xgettext\)[^/]*\.exe$' \
-e '^/mingw../.*/git-\(remote-testsvn\|shell\)\.exe$' \
-e '^/mingw../.*/git-cvsserver.*$' \
-e '^/mingw../.*/gitweb/' \
-e '^/mingw../lib/tdbc' \
-e '^/mingw../libexec/git-core/git-archimport$' \
-e '^/mingw../share/doc/git-doc/git-archimport' \
-e '^/mingw../libexec/git-core/git-cvsimport$' \
-e '^/mingw../share/doc/git-doc/git-cvsexport' \
-e '^/mingw../libexec/git-core/git-cvsexport' \
-e '^/mingw../share/doc/git-doc/git-cvsimport' \
-e '^/mingw../share/git\(k\|-gui\)/lib/msgs/' \
-e '^/mingw../share/nghttp2/' \
-e '^/usr/bin/msys-\(db\|icu\|gfortran\|stdc++\|quadmath\)[^/]*\.dll$' \
-e '^/usr/bin/dumper\.exe$' \
-e '^/usr/share.*/magic$' \
-e '^/usr/share/perl5/core_perl/Unicode/' \
-e '^/usr/share/perl5/core_perl/pods/' \
-e '^/usr/share/perl5/core_perl/Locale/' \
-e '^/usr/share/perl5/core_perl/Pod/' \
-e '^/usr/share/perl5/core_perl/ExtUtils/' \
-e '^/usr/share/perl5/core_perl/CPAN/' \
-e '^/usr/share/perl5/core_perl/TAP/' \
-e '^/usr/share/vim/vim74/lang/' \
-e '^/etc/profile.d/git-sdk.sh$' |
grep -v \
-e '^/mingw../share/locale/' \
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can prolly ditch TZ stuff too

-e '^/usr/share/locale/' |
grep -v \
-e "^\\($(echo $EXTRA_FILE_EXCLUDES |
sed 's/ /\\|/g')\\)\$" |
sort |
grep --perl-regexp -v -e '^/usr/(lib|share)/terminfo/(?!.*/(cygwin|dumb|screen.*|xterm.*)$)' |
sed 's/^\///'

# TODO - need this?
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not at all sure why this is wanted

And shouldn't rebase be being run on 32 bit version?

test -z "$PACKAGE_VERSIONS_FILE" ||
pacman -Q filesystem $SH_FOR_REBASE rebase \
util-linux unzip mingw-w64-$ARCH-xpdf-tools \
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should w64 use BITNESS?

>>"$PACKAGE_VERSIONS_FILE"
152 changes: 152 additions & 0 deletions portable-msys2/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#!/bin/sh

# Build the portable MSYS2

die () {
echo "$*" >&1
exit 1
}

output_directory="$HOME"
include_pdbs=
while test $# -gt 0
do
case "$1" in
--output)
shift
output_directory="$1"
;;
--output=*)
output_directory="${1#*=}"
;;
--include-pdbs)
include_pdbs=t
;;
-*)
die "Unknown option: $1"
;;
*)
break
esac
shift
done

test $# -gt 0 ||
die "Usage: $0 [--output=<directory>] <version> [optional components]"

test -d "$output_directory" ||
die "Directory inaccessible: '$output_directory'"

ARCH="$(uname -m)"
case "$ARCH" in
i686)
BITNESS=32
MD_ARG=128M
;;
x86_64)
BITNESS=64
MD_ARG=256M
;;
*)
die "Unhandled architecture: $ARCH"
;;
esac
VERSION=$1
shift
TARGET="$output_directory"/PortableMSYS2-"$VERSION"-"$BITNESS"-bit.7z.exe
OPTS7="-m0=lzma -mx=9 -md=$MD_ARG -mfb=273 -ms=256M "
TMPPACK=/tmp.7z
SCRIPT_PATH="$(cd "$(dirname "$0")" && pwd)"

case "$SCRIPT_PATH" in
*" "*)
die "This script cannot handle spaces in $SCRIPT_PATH"
;;
esac

# Generate a couple of files dynamically

cp "$SCRIPT_PATH/../LICENSE.txt" "$SCRIPT_PATH/root/" ||
die "Could not copy license file"

# TODO this is in vc as is root/usr
mkdir -p "$SCRIPT_PATH/root/etc" ||
die "Could not make etc/ directory"

mkdir -p "$SCRIPT_PATH/root/tmp" ||
die "Could not make tmp/ directory"

mkdir -p "$SCRIPT_PATH/root/bin" ||
die "Could not make bin/ directory"

cp /cmd/git.exe "$SCRIPT_PATH/root/bin/git.exe" &&
cp /mingw$BITNESS/share/git/compat-bash.exe "$SCRIPT_PATH/root/bin/bash.exe" &&
cp /mingw$BITNESS/share/git/compat-bash.exe "$SCRIPT_PATH/root/bin/sh.exe" ||
die "Could not install bin/ redirectors"

cp "$SCRIPT_PATH/../post-install.bat" "$SCRIPT_PATH/root/" ||
die "Could not copy post-install script"

mkdir -p "$SCRIPT_PATH/root/mingw$BITNESS/etc" &&
cp /mingw$BITNESS/etc/gitconfig \
"$SCRIPT_PATH/root/mingw$BITNESS/etc/gitconfig" &&
git config -f "$SCRIPT_PATH/root/mingw$BITNESS/etc/gitconfig" \
credential.helper manager ||
die "Could not configure Git-Credential-Manager as default"
test 64 != $BITNESS ||
git config -f "$SCRIPT_PATH/root/mingw$BITNESS/etc/gitconfig" --unset pack.packSizeLimit

# Make a list of files to include
echo Generating file list
LIST="$(ARCH=$ARCH BITNESS=$BITNESS \
PACKAGE_VERSIONS_FILE="$SCRIPT_PATH"/root/etc/package-versions.txt \
sh "$SCRIPT_PATH"/../make-file-list-msys2.sh "$@" |
grep -v "^mingw$BITNESS/etc/gitconfig$")" ||
die "Could not generate file list"

rm -rf "$SCRIPT_PATH/root/mingw$BITNESS/libexec/git-core" &&
mkdir -p "$SCRIPT_PATH/root/mingw$BITNESS/libexec/git-core" &&
ln $(echo "$LIST" | sed -n "s|^mingw$BITNESS/bin/[^/]*\.dll$|/&|p") \
"$SCRIPT_PATH/root/mingw$BITNESS/libexec/git-core/" ||
die "Could not copy .dll files into libexec/git-core/"

# TODO there are few extra untacked files under /root. Can't figure how they got there
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is probably solved now after drilling down into package filelists

# TODO check for any unwanted pdbs
test -z "$include_pdbs" || {
find "$SCRIPT_PATH/root" -name \*.pdb -exec rm {} \; &&
"$SCRIPT_PATH"/../please.sh bundle-pdbs \
--arch=$ARCH --unpack="$SCRIPT_PATH"/root
} ||
die "Could not unpack .pdb files"

# 7-Zip will strip absolute paths completely... therefore, we can add another
# root directory like this:

LIST="$LIST $SCRIPT_PATH/root/*"

# Make the self-extracting package

type 7za > /dev/null ||
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redirect to the old bit bucket

pacman -Sy --noconfirm p7zip ||
die "Could not install 7-Zip"

echo "Creating archive" &&
(cd / && 7za a $OPTS7 $TMPPACK $LIST) &&
(cat "$SCRIPT_PATH/../7-Zip/7zSD.sfx" &&
echo ';!@Install@!UTF-8!' &&
echo 'Title="Portable MSYS2 for Windows '$BITNESS'-bit"' &&
echo 'BeginPrompt="This archive extracts a minimal MSYS2 for Windows '$BITNESS'-bit"' &&
echo 'CancelPrompt="Do you want to cancel the portable MSYS2 installation?"' &&
echo 'ExtractDialogText="Please, wait..."' &&
echo 'ExtractPathText="Where do you want to install portable MSYS2?"' &&
echo 'ExtractTitle="Extracting..."' &&
echo 'GUIFlags="8+32+64+256+4096"' &&
echo 'GUIMode="1"' &&
echo 'InstallPath="%%S\\PortableMSYS2"' &&
echo 'OverwriteMode="0"' &&
echo "RunProgram=\"git-bash.exe --needs-console --hide --no-cd --command=post-install.bat\"" &&
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing post-install.bat looks good to me.

echo ';!@InstallEnd@!' &&
cat "$TMPPACK") > "$TARGET" &&
echo "Success! You will find the new installer at \"$TARGET\"." &&
echo "It is a self-extracting .7z archive." &&
rm $TMPPACK
106 changes: 106 additions & 0 deletions portable-msys2/root/README.portable
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
README.portable
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops will need to rewrite this

=======================

This version of Git for Windows is portable, i.e. does not need to
be installed. It will run from any directory you place it in, even
from a USB thumbdrive. It will not write permanent entries into the
Windows registry. It does not need administrator privileges to "install".


Installation
------------

This package is contained in a 7-zip archive with a file name of the form
'PortableGit-<versionstring>.7z.exe'. It is a self-extracting archive:
you can (double-)click it and it will ask for the desired target directory
(which defaults to C:\Program Files\Git). You may change that as needed or
desired. Your user account needs write access to the selected directory.
(You can move that directory with all its contents to a different place or
computer at any time should you later desire so).

*NOTE*: if you decide to unpack the archive using 7-Zip manually, you must
run the `post-install.bat` script. Git will not run correctly
otherwise.

Functional differences to the non-portable Git for Windows
----------------------------------------------------------

This version does not offer you the convenient right-click context menu
entries "Git GUI Here" and "Git Bash Here", because these would require
to add entries into the Windows registry.


Warning
-------

Since this portable package does not modify any Windows %path%
variables, it is not possible to run the git.exe and gitk.exe files
directly. Start the Git Bash or Git Cmd instead, or add the cmd/ folder
to your %path%.


How to start using PortableGit
------------------------------

If you are comfortable with a Unix-like shell, just launch 'git-bash.exe'.

If not, just launch 'git-cmd.exe'.

Alternatively, you can execute these commands to modify the %path%
variable temporarily:

set gitdir=c:\portablegit
set path=%gitdir%\cmd;%path%

Adjust the 'gitdir' according to your setup. As long as you do not
close the command window, you can now simply type "git" or "gitk" to
really call "c:\portablegit\cmd\git.exe" or "c:\portablegit\cmd\gitk.exe".

By default, git-cmd and git-bash use the directory they were started from as
the working directory when run. You can override this by passing --cd-to-home
to them, which will set the user's home directory as the working directory (as
if Git for Windows was installed).

In addition, if you set the HOME environment variable (either permanently or
for the current session only) you can make Git store and use the configuration
files in the directory specified in that variable. And if you specify
--cd-to-home, git-bash and git-cmd will use that as the working directory when
launched, too. For example:

set HOME=%cd%/home
git --cd-to-home
will use the relative directory named home (%cd% specifies the current
directory).

Quick start
-----------

Start configuring git with your personal settings:
git config --global user.name "Joe Sixpack"
git config --global user.email joe.sixpack@g_mail.com

Start using git:
git --help


How to change %path% permanently
--------------------------------

You may also want to make the modification to the %path% variable a
permanent one. The %path% variable may be changed:

* either on a System level (for all users in the lower pane), if you are
an Administrator
* or for your own user account only (in the upper pane).

To change the %path% variable permanently:

* right-click "My Computer",
* select "Properties",
* open "Advanced",
* click "Environment Variables",
* highlight the "Path" variable,
* click "Edit" (either in upper or in lower pane),
* add your specific path to front of "Variable value" field, separated
by a semicolon from the existing entry.

Loading