recovery zip: fix "No OS installed" warning (!169)
Tested on sony-amami with TWRP 3.0.2.
This commit is contained in:
committed by
Oliver Smith
parent
eb30c690fc
commit
b24a2a4c96
@@ -1,5 +1,5 @@
|
||||
pkgname=postmarketos-android-recovery-installer
|
||||
pkgver=0.1.9
|
||||
pkgver=0.1.10
|
||||
pkgrel=0
|
||||
pkgdesc="TWRP compatible postmarketOS installer script"
|
||||
url="https://postmarketos.org"
|
||||
@@ -7,13 +7,19 @@ url="https://postmarketos.org"
|
||||
depends="busybox-extras lddtree cryptsetup multipath-tools device-mapper parted util-linux zip e2fsprogs tar"
|
||||
source="build_zip.sh
|
||||
update-binary
|
||||
disable-warning.c
|
||||
pmos_chroot
|
||||
pmos_install
|
||||
pmos_install_functions
|
||||
pmos_setpw"
|
||||
arch="noarch"
|
||||
arch="all"
|
||||
options="!check"
|
||||
license="GPL3"
|
||||
|
||||
build() {
|
||||
gcc -static -o disable-warning disable-warning.c
|
||||
}
|
||||
|
||||
package() {
|
||||
install -Dm755 "$srcdir/build_zip.sh" \
|
||||
"$pkgdir/sbin/build-recovery-zip"
|
||||
@@ -21,13 +27,16 @@ package() {
|
||||
"$pkgdir/var/lib/postmarketos-android-recovery-installer/META-INF/com/google/android/update-binary"
|
||||
install -Dm755 "$srcdir"/pmos_chroot \
|
||||
"$pkgdir/var/lib/postmarketos-android-recovery-installer/pmos_chroot"
|
||||
install -Dm755 "$srcdir"/disable-warning \
|
||||
"$pkgdir/var/lib/postmarketos-android-recovery-installer/disable-warning"
|
||||
for file in pmos_install pmos_install_functions pmos_setpw; do
|
||||
install -Dm755 "$srcdir/$file" \
|
||||
"$pkgdir/var/lib/postmarketos-android-recovery-installer/chroot/bin/$file"
|
||||
done
|
||||
}
|
||||
sha512sums="924f961e1a488134d265f43724d2b06a908ac1522706dc3f7118f0dec16453aa0a928fef6d9a31a6a747910df665e64f25c94c47a9e3f1d57db19abb0fd8210d build_zip.sh
|
||||
6390fc1b1c7dc8e917bb675d2e59e479782ac7754e97c4781866360ff704afe2d04f173a0ac74e3129db45328fab4b6b77a8717ee2e17c6ff79febadaa8ea034 update-binary
|
||||
bb152e86ce420761dd2dca660552131610bb8f39cb7e30c75689aacc7cccddce17a90c998097f1b63b3d68a20f9c2c4823d8d591de156dff827381fe436f3b9d update-binary
|
||||
38c21dc80aa2530fc06c2960c1318e07d068d403af02133f09ba227106a9b23fb77c3bed904e6135b048846f2733bd5d043235e5ab04598ed9c8fa45cbb15586 disable-warning.c
|
||||
2400d18734d08b3d2f5ec2fe4e802cdcacddea851644b47505eff1aac47302699c171b880bca55dd1704cc9cef9ac26082ac89cee802b6bf57ff8cf649373328 pmos_chroot
|
||||
ef6377f6c062b9a86eb9dfb2aa2c0049fda20f24ec75865a682a50e4655710a18bd7a470deab527e1dd4c273f9ea6a003ec03fc5748d44b1c4fbfc91baa9e358 pmos_install
|
||||
1b19d507a9142e537d052037a0c0768f064ad9131ac8019b234178dc15c0590dbc549ccf553b7a7d55e977df269d4dc0567b520c890738cb80184fc8235222aa pmos_install_functions
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright 2019 Attila Szollosi
|
||||
*
|
||||
* This file is part of postmarketos-android-recovery-installer.
|
||||
*
|
||||
* postmarketos-android-recovery-installer is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* postmarketos-android-recovery-installer is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with postmarketos-android-recovery-installer. If not, see <http:www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
|
||||
void close_FDs()
|
||||
{
|
||||
unsigned int fd;
|
||||
struct dirent* ep;
|
||||
DIR* dp = opendir("/proc/self/fd");
|
||||
if (dp != NULL) {
|
||||
// first two entries are . and ..
|
||||
readdir(dp);
|
||||
readdir(dp);
|
||||
|
||||
while (ep = readdir(dp))
|
||||
if (sscanf(ep->d_name, "%u", &fd) != EOF)
|
||||
close(fd);
|
||||
closedir(dp);
|
||||
} else {
|
||||
// try to close all file descriptors by brute-force
|
||||
// in case the list of open FDs could not be read
|
||||
// from the procfs
|
||||
for (fd = 256; fd >= 0; fd--)
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
// Detach the program from the installation script
|
||||
void daemonize()
|
||||
{
|
||||
pid_t pid;
|
||||
|
||||
pid = fork();
|
||||
if (pid < 0)
|
||||
exit(1);
|
||||
if (pid > 0)
|
||||
exit(0);
|
||||
|
||||
if (setsid() < 0)
|
||||
exit(1);
|
||||
|
||||
pid = fork();
|
||||
if (pid < 0)
|
||||
exit(1);
|
||||
if (pid > 0)
|
||||
exit(0);
|
||||
|
||||
umask(0);
|
||||
chdir("/");
|
||||
close_FDs();
|
||||
}
|
||||
|
||||
// Workaround to disable No OS warning in TWRP
|
||||
// See: https://gitlab.com/postmarketOS/pmbootstrap/issues/1451
|
||||
//
|
||||
// Works by setting the variable tw_backup_system_size to a large
|
||||
// value, so TWRP's check
|
||||
// (tw_backup_system_size < tw_min_system) will result in
|
||||
// false.
|
||||
//
|
||||
// TWRP doesn't allow issuing OpenRecoveryScript commands while
|
||||
// the installation is running, so we have to daemonize the
|
||||
// process to change the value after the installation script
|
||||
// exited.
|
||||
int main()
|
||||
{
|
||||
daemonize();
|
||||
|
||||
int orsin, orsout;
|
||||
|
||||
char command[1024];
|
||||
char result[512];
|
||||
|
||||
char* commands[] = {"set tw_backup_system_size 999",
|
||||
"set tw_app_prompt 0"};
|
||||
|
||||
sleep(4);
|
||||
|
||||
int i;
|
||||
for (i = 0; i < sizeof(commands)/sizeof(char*); i++) {
|
||||
if ((orsin = open("/sbin/orsin", O_WRONLY)) == -1)
|
||||
return 1;
|
||||
strcpy(command, commands[i]);
|
||||
write(orsin, command, sizeof(command));
|
||||
close(orsin);
|
||||
|
||||
// Have to read FIFO file, because it blocks
|
||||
// the thread processing the command
|
||||
// (see man 3 mkfifo)
|
||||
if ((orsout = open("/sbin/orsout", O_RDONLY)) == -1)
|
||||
return 1;
|
||||
read(orsout, result, sizeof(result));
|
||||
close(orsout);
|
||||
|
||||
sleep(3);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/sbin/sh
|
||||
|
||||
# Copyright 2017 Attila Szollosi
|
||||
# Copyright 2017-2019 Attila Szollosi
|
||||
#
|
||||
# This file is part of postmarketos-android-recovery-installer.
|
||||
#
|
||||
@@ -34,3 +34,8 @@ mkdir -p /tmp/postmarketos/
|
||||
unzip -o "$ZIP" "pmos_chroot" -d /tmp/postmarketos/
|
||||
chmod 755 /tmp/postmarketos/pmos_chroot
|
||||
/tmp/postmarketos/pmos_chroot || { fail_info ; exit 1 ; }
|
||||
|
||||
# Disable No OS warning
|
||||
unzip -o "$ZIP" "disable-warning" -d /tmp/postmarketos/
|
||||
chmod 755 /tmp/postmarketos/disable-warning
|
||||
/tmp/postmarketos/disable-warning
|
||||
|
||||
Reference in New Issue
Block a user