Skip to content

Commit

Permalink
build termux-display script update
Browse files Browse the repository at this point in the history
  • Loading branch information
jiaxinchen-max committed Mar 19, 2024
1 parent 64bbb9c commit 85f6106
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 19 deletions.
32 changes: 16 additions & 16 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@
android:windowSoftInputMode="stateHidden"
android:theme="@style/Theme.AppCompat.DayNight.NoActionBar"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->

<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
<!-- <category android:name="android.intent.category.LEANBACK_LAUNCHER" />-->
<!-- </intent-filter>-->
<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts" />
</activity>
<activity
Expand All @@ -94,16 +94,16 @@
android:resizeableActivity="true"
android:theme="@style/Theme.TermuxActivity.DayNight.NoActionBar"
tools:targetApi="n">
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<!-- <category android:name="android.intent.category.LEANBACK_LAUNCHER" />-->
<!-- </intent-filter>-->
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>

<meta-data
android:name="android.app.shortcuts"
Expand Down
106 changes: 106 additions & 0 deletions build_termux_package
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/bin/bash
set -e
cd "$(dirname "$0")"

TERMUX_PKG_NAME="termux-display-nightly"
TERMUX_PKG_HOMEPAGE="https://github.com/termux/termux-x11"
TERMUX_PKG_DESCRIPTION="Companion package for termux-x11 app"
TERMUX_PKG_MAINTAINER="Twaik Yont @twaik"
TERMUX_PKG_REVISION=0
#TERMUX_PKG_VERSION=$(grep versionName app/build.gradle | cut -d '"' -f 2)
TERMUX_PKG_VERSION=1
TERMUX_PKG_DEPENDS="xkeyboard-config"

TERMUX_PKG_FULLVERSION="$TERMUX_PKG_VERSION-$TERMUX_PKG_REVISION"

### Deploy .deb package

DEB_PACKAGE_PATH=app/build/outputs/apk/debug/${TERMUX_PKG_NAME}-${TERMUX_PKG_FULLVERSION}-all.deb
PACMAN_PACKAGE_PATH=app/build/outputs/apk/debug/${TERMUX_PKG_NAME}-${TERMUX_PKG_FULLVERSION}-any.pkg.tar.xz

INTERMEDIATES=shell-loader/build/intermediates
DATA_DIR=$INTERMEDIATES/data
CONTROL_DIR=$INTERMEDIATES/control
PACKAGE_DIR=$INTERMEDIATES/package
PREFIX=$DATA_DIR/data/data/com.termux/files/usr

rm -rf $DEB_PACKAGE_PATH $PACMAN_PACKAGE_PATH $DATA_DIR $CONTROL_DIR $PACKAGE_DIR $INTERMEDIATES/.PKGINFO $INTERMEDIATES/.BUILDINFO $INTERMEDIATES/.MTREE

mkdir -p $PREFIX/bin/
mkdir -p $PREFIX/libexec/termux-display
mkdir -p "$(dirname $DEB_PACKAGE_PATH)"

cp termux-x11-display $PREFIX/bin/
mv $PREFIX/bin/termux-x11-display $PREFIX/bin/termux-display
cp shell-loader/build/outputs/apk/debug/shell-loader-debug.apk \
$PREFIX/libexec/termux-display/loader.apk

mkdir -p $CONTROL_DIR
cat <<EOF > $CONTROL_DIR/control
Package: $TERMUX_PKG_NAME
Architecture: all
Maintainer: $TERMUX_PKG_MAINTAINER
Version: $TERMUX_PKG_FULLVERSION
Homepage: $TERMUX_PKG_HOMEPAGE
Depends: $TERMUX_PKG_DEPENDS
Description: $TERMUX_PKG_DESCRIPTION
EOF

cat <<EOF > $CONTROL_DIR/postinst
#!/data/data/com.termux/files/usr/bin/sh
chmod -w /data/data/com.termux/files/usr/libexec/termux-display/loader.apk
EOF

mkdir -p $PACKAGE_DIR
echo 2.0 > $PACKAGE_DIR/debian-binary
tar -cJf $PACKAGE_DIR/data.tar.xz -C $DATA_DIR .
tar -czf $PACKAGE_DIR/control.tar.gz -C $CONTROL_DIR .

ar -rsc $DEB_PACKAGE_PATH \
$PACKAGE_DIR/debian-binary \
$PACKAGE_DIR/control.tar.gz \
$PACKAGE_DIR/data.tar.xz

### Deploy pacman package

BUILD_DATE=$(date +%s)

{
echo "pkgname = $TERMUX_PKG_NAME"
echo "pkgbase = $TERMUX_PKG_NAME"
echo "pkgver = $TERMUX_PKG_FULLVERSION"
echo "pkgdesc = $(echo "$TERMUX_PKG_DESCRIPTION" | tr '\n' ' ')"
echo "url = $TERMUX_PKG_HOMEPAGE"
echo "builddate = $BUILD_DATE"
echo "packager = $TERMUX_PKG_MAINTAINER"
echo "arch = any"
echo "license = TERMUX_PKG_LICENSE"
tr ',' '\n' <<< "$TERMUX_PKG_DEPENDS" | sed 's|(||g; s|)||g; s| ||g; s|>>|>|g; s|<<|<|g' | awk '{ printf "depend = " $1; if ( ($1 ~ /</ || $1 ~ />/ || $1 ~ /=/) && $1 !~ /-/ ) printf "-0"; printf "\n" }' | sed 's/|.*//'
} > $DATA_DIR/.PKGINFO

{
echo "format = 2"
echo "pkgname = $TERMUX_PKG_NAME"
echo "pkgbase = $TERMUX_PKG_NAME"
echo "pkgver = $TERMUX_PKG_FULLVERSION"
echo "pkgarch = any"
echo "packager = $TERMUX_PKG_MAINTAINER"
echo "builddate = $BUILD_DATE"
} > $DATA_DIR/.BUILDINFO

{
echo "post_install() {"
echo " chmod -w /data/data/com.termux/files/usr/libexec/termux-display/loader.apk"
echo "}"
} > $DATA_DIR/.INSTALL

PACMAN_PACKAGE_PATH=`realpath $PACMAN_PACKAGE_PATH`

cd $DATA_DIR
shopt -s dotglob globstar
printf '%s\0' data/**/* .BUILDINFO .PKGINFO | bsdtar -cnf - --format=mtree \
--options='!all,use-set,type,uid,gid,mode,time,size,md5,sha256,link' \
--null --files-from - | gzip -c -f -n > .MTREE
printf '%s\0' data/**/* .BUILDINFO .PKGINFO .MTREE | bsdtar --no-fflags -cnf - --null --files-from - | xz > "$PACMAN_PACKAGE_PATH"
shopt -u dotglob globstar
cd -
1 change: 0 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
include ':app', ':termux-shared', ':terminal-emulator', ':terminal-view'
include ':termux-x11'
include ':shell-loader'
include ':shell-loader:stub'
include ':termux-display'
4 changes: 2 additions & 2 deletions shell-loader/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//file:noinspection UnnecessaryQualifiedReference, GrDeprecatedAPIUsage
apply plugin: 'com.android.application'

android.buildFeatures.buildConfig true
android.namespace 'com.termux.display'
android.defaultConfig.minSdkVersion 21
android.compileSdkVersion 28
Expand All @@ -15,7 +15,7 @@ def signingConfig = project(':app').android.signingConfigs.debug
def keyStore = java.security.KeyStore.getInstance(java.security.KeyStore.getDefaultType())
keyStore.load(new FileInputStream(signingConfig.storeFile), signingConfig.keyPassword.toCharArray())

android.defaultConfig.buildConfigField "String", "logTag", "\"Termux:X11 loader\""
android.defaultConfig.buildConfigField "String", "logTag", "\"Termux:display loader\""
android.defaultConfig.buildConfigField "int", "SIGNATURE", String.valueOf(Arrays.hashCode(keyStore.getCertificate(signingConfig.keyAlias).getEncoded()))
android.defaultConfig.buildConfigField "String", "CLASS_ID", "\"com.termux.display.CmdEntryPoint\""
android.defaultConfig.buildConfigField "String", "packageNotInstalledErrorText",
Expand Down
4 changes: 4 additions & 0 deletions termux-x11-display
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/data/data/com.termux/files/usr/bin/sh
export CLASSPATH=/data/data/com.termux/files/usr/libexec/termux-display/loader.apk
unset LD_LIBRARY_PATH LD_PRELOAD
exec /system/bin/app_process / com.termux.display "$@"
51 changes: 51 additions & 0 deletions termux-x11-preference
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/data/data/com.termux/files/usr/bin/bash
COMMAND=("am" "broadcast" "-a" "com.termux.x11.CHANGE_PREFERENCE" "-p" "com.termux.x11")
help() {
echo "$0 {list} {key:value}..."
exit 1
}

list() {
output="$("${COMMAND[@]}" -e list null 2>&1)"
result=$(sed -n '/result=[0-9]*/{s/.*result=\([0-9]*\).*/\1/p;q;}' <<< "$output")
if [[ "$result" == "0" ]]; then
echo "Something went wrong."
exit 1
fi
if [[ "$result" == "2" ]] || [[ "$result" == "4" ]]; then
echo "$(echo "$output" | sed -z 's/.*data="\([^"]*\)*/\1/' | sed '${s/"$//}')"
exit 0
fi
echo "list: Unexpected result $result"
echo "$output"
exit 1
}

if [ $# -eq 0 ]; then
help
fi

while [[ $# -gt 0 ]]; do
case $1 in
list) list;;
*:*) COMMAND+=("-e" "${1%%:*}" "${1#*:}");;
*) echo "Unrecognised option $1"; help
esac
shift
done

output="$("${COMMAND[@]}")"
result=$(sed -n '/result=[0-9]*/{s/.*result=\([0-9]*\).*/\1/p;q;}' <<< "$output")
if [[ "$result" == "0" ]]; then
echo "Something went wrong."
exit 1
fi

if [[ "$result" == "2" ]] || [[ "$result" == "4" ]]; then
echo "$(echo "$output" | sed -z 's/.*data="\([^"]*\)*/\1/' | sed '${s/"$//}')"
exit 0
fi

echo "set: Unexpected result $result"
echo "$output"
exit 1

0 comments on commit 85f6106

Please sign in to comment.