Google play services on Sailfish 4.1

@Gouneesz the script “stuck” at the point where it should install an incompatible package (armv7hl).
That is why it works on XA2, but not in our Xperia 10ii!
Looks like we 're gonna have to do it manually! :slight_smile:

Ok. But I don’t know how. I don’t have any skills with linux…

The script doesn’t work for xperia 10 II because it needs the 64 vit version of lzip. Here is my modified script that works. Before running you also need to install unzip and rsync if not already installed using these commands in terminal:

devel-su pkcon install unzip
devel-su pkcon install rsync

Here’s the script:

#!/bin/sh


set -e

WORKDIR=/home/.aliendalvik_systemimg_patch
TMPWORKDIR="$WORKDIR/tmp"
SQUASHFS_ROOT="$TMPWORKDIR/squashfs-root"
MOUNT_ROOT="$TMPWORKDIR/systemimg_mount"
SYSTEM_IMG=/opt/alien/system.img
ORIG_IMG_FILE=orig_img_path.txt

FEDORA22_REPO=https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/30/Everything/aarch64/os/Packages

OPENGAPPS_ARCH=arm64
OPENGAPPS_API=10.0
OPENGAPPS_VARIANT=pico

GOOGLE_APPS_REMOVE='carriersetup extservicesgoogle extsharedgoogle  googlebackuptransport googlecontactssync  googlefeedback googlepartnersetup'

log() {
printf '%s\n'"$1" > /dev/stderr
}

install_fedora22_rpm() {
pkgname="$1"
pkgversion="$2"

if ! rpm -q "$pkgname" > /dev/null; then
    pkgfile="$pkgname-$pkgversion.fc30.aarch64.rpm"
    firstletter="$(printf '%s' "$pkgfile" | cut -c 1)"
    mkdir "$TMPWORKDIR/rpms"
    curl "$FEDORA22_REPO/$firstletter/$pkgfile" > "$TMPWORKDIR/rpms/$pkgfile"
    pkcon -y install-local "$TMPWORKDIR/rpms/$pkgfile"
    rm "$TMPWORKDIR/rpms/$pkgfile"
    rmdir "$TMPWORKDIR/rpms"
fi

}

install_deps() {

if ! rpm -q squashfs-tools > /dev/null; then
pkcon -y install squashfs-tools
fi

install_fedora22_rpm lzip 1.20-4

}

extract_image() {
mkdir "$MOUNT_ROOT"
mount -o loop,ro "$SYSTEM_IMG" "$MOUNT_ROOT"

if [ -f "$MOUNT_ROOT/$ORIG_IMG_FILE" ]; then
    orig_image="$(cat "$MOUNT_ROOT/$ORIG_IMG_FILE")"
    log "$SYSTEM_IMG already patched, using original from $orig_image"
else
    orig_image="$WORKDIR/system.img.orig.$(date +%Y%m%dT%H%M%S)"
    cp "$SYSTEM_IMG" "$orig_image"
    log "Copying original image $SYSTEM_IMG to $orig_image"
fi
umount "$MOUNT_ROOT"

if [ ! -f "$orig_image" ]; then
    log "$orig_image not found"
    return 1
fi

mount -o loop,ro "$orig_image" "$MOUNT_ROOT"

if [ -f "$MOUNT_ROOT/$ORIG_IMG_FILE" ]; then
    umount "$MOUNT_ROOT"
    rmdir "$MOUNT_ROOT"
    log "$orig_image already patched, please restore original image to $SYSTEM_IMG"
    return 1
fi

mkdir "$SQUASHFS_ROOT"
# rsync needs to be run twice to copy all xattrs. Probably a bug in rsync.
rsync -aSHAX "$MOUNT_ROOT/" "$SQUASHFS_ROOT/"
rsync -aSHAX "$MOUNT_ROOT/" "$SQUASHFS_ROOT/"
umount "$MOUNT_ROOT"
rmdir "$MOUNT_ROOT"

printf '%s' "$orig_image" > "$SQUASHFS_ROOT/$ORIG_IMG_FILE"
log "line 87"
}

build_image() {
cp "$SYSTEM_IMG" "$TMPWORKDIR/system.img.backup"
mksquashfs "$SQUASHFS_ROOT" "$SYSTEM_IMG" -noappend -no-exports -no-duplicates -no-fragments
rm "$TMPWORKDIR/system.img.backup"
rm -r "$SQUASHFS_ROOT"
}

_find_opengapps() {
downloads="$(runuser -l defaultuser -- /usr/bin/xdg-user-dir DOWNLOAD)"
name_pattern="open_gapps-$OPENGAPPS_ARCH-$OPENGAPPS_API-$OPENGAPPS_VARIANT-*.zip"
if [ "$1" != quiet ]; then
log "Searching for Open GApps zip at $downloads/$name_pattern"
fi
find "$downloads" -maxdepth 1 -name "$name_pattern" | sort | tail -n 1
}

get_opengapps_zip() {
opengapps_zip="$(_find_opengapps)"
if [ -z “$opengapps_zip” ]; then
# Show the Open GApps download page to the user instead of automating
# the download of the latest version.
# https://opengapps.org/blog/post/2016/03/18/the-no-mirror-policy/ 1
log "Opening Open GApps download page"
runuser -l defaultuser – xdg-open "https://opengapps.org/?download=true&arch=$OPENGAPPS_ARCH&api=$OPENGAPPS_API&variant=$OPENGAPPS_VARIANT"

log "Waiting for download to start"
while [ -z "opengapps_zip" ]; do sleep 1 opengapps_zip="(_find_opengapps quiet)"
done
log "Detected new download at $opengapps_zip"
log "Waiting for download to finish"
while [ -f “$opengapps_zip” ] && [ -f "$opengapps_zip.part" ]; do
sleep 1
done
sleep 1
if [ ! -f "$opengapps_zip" ]; then
log "Download failed"
return 1
fi
else
log "Found Open GApps zip $opengapps_zip"
fi
printf '%s' "$opengapps_zip"
}

install_opengapps() {
unzip "$(get_opengapps_zip)" -d "$TMPWORKDIR/opengapps/"

for p in $GOOGLE_APPS_REMOVE; do
    rm "$TMPWORKDIR/opengapps/Core/$p-all.tar.lz"
done

if [ -f "$TMPWORKDIR/opengapps/Core/extservicesgoogle-all.tar.lz" ]; then
    rm -r "$SQUASHFS_ROOT/system/priv-app/ExtServices"
fi
if [ -f "$TMPWORKDIR/opengapps/Core/extsharedgoogle-all.tar.lz" ]; then
    rm -r "$SQUASHFS_ROOT/system/app/ExtShared"
fi
if [ -f "$TMPWORKDIR/opengapps/Core/setupwizardtablet-all.tar.lz" ]; then
    rm "$TMPWORKDIR/opengapps/Core/setupwizardtablet-all.tar.lz"
fi
mkdir "$TMPWORKDIR/opengapps_2"
for f in "$TMPWORKDIR"/opengapps/Core/*.tar.lz; do
    lzip -c -d "$f" | tar -x -C "$TMPWORKDIR/opengapps_2"
done
rm -r "$TMPWORKDIR/opengapps/"

cp -r "$TMPWORKDIR"/opengapps_2/*/*/* "$SQUASHFS_ROOT/system/"

rm -r "$TMPWORKDIR/opengapps_2/"

}

set_traps() {
# shellcheck disable=SC2064
trap "$*" EXIT HUP INT QUIT PIPE TERM
}

cleanup() {
if [ ! -f "$SYSTEM_IMG" ] && [ -f "$TMPWORKDIR/system.img.backup" ]; then
mv "$TMPWORKDIR/system.img.backup" “$SYSTEM_IMG” || :
fi

umount "$MOUNT_ROOT" || :
rm -r "$TMPWORKDIR" || :
set_traps -
exit 1
}

set_traps cleanup

systemctl stop aliendalvik

mkdir -p "$WORKDIR"
mkdir -p "$TMPWORKDIR"

install_deps
extract_image
install_opengapps
build_image

rmdir "$TMPWORKDIR"

set_traps -
exit 0
3 Likes

I’m hopeless. Still no luck

@Gouneesz
Don’t know whether this resource points you in the right direction:
https://linuxhandbook.com/run-shell-script/

You should wrap your sh script inside

code tags like ` some
code `
which will look then
some code

or maybe just prepend >

some
code

lines

or simple normal quote?

or

#some
lines

of code

Last approach, so wrap it like
[code]
some
lines
of code
[/code]

Thanks, fixed above now

here’s my script hope it helps

1 Like

For any late comers to this thread and avoid any future confusion, remember for Xperia 10II need to use script by anig which includes for 64-bit Sailfish:
FEDORA22_REPO=https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/30/Everything/aarch64/os/Packages
whilst for earlier devices that from ubuntuscofield which has:
FEDORA22_REPO=https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/22/Everything/armhfp/os/Packages

1 Like

Copy install_opengapps.sh (by anig)and opengapps arm64 pico 10 to the Downloads folder but gets an error message when installing(./install_opengapps.sh) “Bash: ./install_opengapps.sh: not found”. Sony xperia 10 II.

I think I had the same problem. Solution for me was that I had windows line endings on the .sh file and linux like Sailfish cannot understand Windows line endings. So after I changed line endings to linux style the script works on my Xperia 10 II.

How can I do it? Linux style? I have only windows pc.

@ubuntuscofield wrote:
i got it to work with my xa2 ultra on 4.1 using the arm 64 file

what? you have arm64 sailfishos for XA2 ? custom build or Xperia 10ii image?

How did you do it? Change to linux style

For instance in Visual Studio Code you can change line endings. In Windows line endings are CRLF and in Linux LF.

Ok. Thanks. Now I get it done.

I have been running the Google Play Store for years on my XA2, however, since upgrading to 4.0 (I skipped a few upgrades), the Play Store doesn’t run (it starts loading, then shows a black screen). I ran the script above using the 32-bit pico v10 gapps. Do I need to reinstall Play Store, or what am I missing?

Also, after installing the new gapps, I have another strange problem: My previously installed apps (those that still work) refuse to go to the background. I have to shut them down, I can’t swipe from the side to put them in the background.

EDIT: I figured it out. I am still on Sailfish 4.0, so Android 10 is not compatible. I downloaded the gapps v9 pico, went into your script and changed the 10.0 to 9.0, and after running the script the Google Play Store and all the apps are working perfectly again! Thanks for the script!

Hello
Thank you for the script. However, I can see that your script refers to ‘nemo’. Beware that on fresh install since 4.0, the default user is ‘defaultuser’. You should replace ‘/home/nemo’ with ‘$HOME’ and ‘runuser -l nemo …’ with ‘runuser -l $USER …’ for the script to work on any install.

1 Like

i believe since 4.1 xa2 ultra will be running on 64, correct me if im wrong

nope ) i has 4.1.0.24 - its x32 … (or it fully compatible with armv7hl :grin: )