Skip to content

Commit

Permalink
Merge pull request #2 from ray-hrst/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
r-oung authored Mar 27, 2020
2 parents fb4dff4 + 72cd732 commit 9d635d7
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 30 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ positional arguments:
### shortcut.sh
Creates an APK (visible on temi's Launcher) that launches another APK. This can be used to run APKs that are hidden from temi's Launcher.
```
usage: shortcut.sh <package-name> <shortcut_name>
usage: shortcut.sh <package-name> <shortcut-name>
Creates a shortcut for APK file
Expand All @@ -75,7 +75,7 @@ dependencies:
positional arguments:
package-name Android application package name
shortcut_name Shortcut name. Use double-quotes to encapsulate
shortcut-name Shortcut name. Use double-quotes to encapsulate
a name with whitespace.
```

82 changes: 82 additions & 0 deletions extract_icon.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/sh
#
# Extracts icon from APK
#
# Usage
# ./extract_icon.sh <apk>
#
# Dependencies
# - Android SDK, see: https://www.androidcentral.com/installing-android-sdk-windows-mac-and-linux-tutorial
#
# MIT License
#
# Copyright (c) 2020 Raymond Oung
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#

# abort if any command fails
set -e

# constants
THIS_DIR="$PWD"

# display usage instructions
usage()
{
echo ""
echo "usage: extract_icon.sh <apk>"
echo ""
echo "Extracts icon from APK"
echo ""
echo "dependencies:"
echo ""
echo " This script depends on having the Android-SDK installed and having the"
echo " the ANDROID_HOME environment variable set appropriately."
echo ""
echo "positional arguments:"
echo ""
echo " apk APK filename (.apk)"
echo ""
}

# check for APK file
if [ -z "$1" ]; then
echo "Missing APK file"
usage
exit 1
else
APK_FILENAME=$1
fi

# get icon path
ICON_PATH="$(aapt dump badging "${APK_FILENAME}" | awk -F "[='|' ]" '/application: / {print $8}')"

# check that icon exists
FILE_EXTENSION="$(echo "${ICON_PATH}" | awk -F . '{print $NF}')"
if [ "${FILE_EXTENSION}" != "png" ]; then
echo "[Error] Icon not found"
exit 1
else
rm -fr "/tmp/apk"
unzip -q "${APK_FILENAME}" -d "/tmp/apk"
cp "/tmp/apk/${ICON_PATH}" "${THIS_DIR}/icon.png"
echo "${THIS_DIR}/icon.png"
exit 0
fi
13 changes: 7 additions & 6 deletions package_name.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# MIT License
#
# Copyright (c) 2019 Raymond Oung
# Copyright (c) 2020 Raymond Oung
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -31,6 +31,9 @@
# SOFTWARE.
#

# abort if any command fails
set -e

# display usage instructions
usage()
{
Expand All @@ -48,22 +51,20 @@ usage()
echo ""
echo " apk APK filename (.apk)"
echo ""
exit 1
}

# check for APK file
if [ -z "$1" ]; then
echo "Missing APK file"
usage
exit 1
else
APK_FILENAME=$1
fi

# get package name
PACKAGE_NAME="$(aapt dump badging "${APK_FILENAME}" | awk -F "[='|' ]" '/package: / {print $4}')"

# get package name (alternative)
# PACKAGE_NAME="$(aapt dump badging "${APK}" | grep "package" | sed -r "s/package: name='(.+)' versionCode.*/\1/")"

# output package name
echo "${PACKAGE_NAME}"
exit 0
exit 0
38 changes: 17 additions & 21 deletions shortcut.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ set -e
# constants
DEFAULT_ANDROID_HOME=~/Android/Sdk # default location on Linux
TEMPLATE_DIR="temi-launcher-shortcut-template"
THIS_DIR="$PWD"

# display usage instructions
usage()
Expand All @@ -45,16 +46,15 @@ usage()
echo ""
echo "dependencies:"
echo ""
echo " - Android-SDK with the ANDROID_HOME environment variable"
echo " set appropriately."
echo " Android SDK with the ANDROID_HOME environment variable"
echo " set appropriately."
echo ""
echo "positional arguments:"
echo ""
echo " package-name Android application package name"
echo " shortcut-name Shortcut name. Use double-quotes to encapsulate"
echo " a name with whitespace."
echo ""
exit 1
}

# attempt to automatically set ANDROID_HOME environment variable
Expand All @@ -65,7 +65,9 @@ set_android_home()
export ANDROID_HOME=${DEFAULT_ANDROID_HOME}
echo "export ANDROID_HOME=${ANDROID_HOME}"
else
echo "[Error] Android SDK cannot be found. Please set the ANDROID_HOME environment variable to your Android-SDK's (Android/Sdk) path."
echo "[Error] Android SDK cannot be found. Set the ANDROID_HOME environment variable to your Android SDK's path, i.e. Android/Sdk/"
# echo "[Error] Android SDK cannot be found. Set the ANDROID_SDK_ROOT environment variable to your Android SDK's path, i.e. Android/Sdk/"
exit 1
fi
}

Expand All @@ -84,6 +86,7 @@ fi
if [ -z "$1" ]; then
echo "Missing package name"
usage
exit 1
else
PACKAGE_NAME=$1
fi
Expand All @@ -92,15 +95,19 @@ fi
if [ -z "$2" ]; then
echo "Missing shortcut name"
usage
exit 1
else
SHORTCUT_NAME=$2
fi

# remove existing directory if any
rm -fr "/tmp/${SHORTCUT_NAME}"

# make a copy of the template
cp -avr "${TEMPLATE_DIR}" tmp
cp -avr "${TEMPLATE_DIR}" "/tmp/${SHORTCUT_NAME}"

# enter shortcut-template source code root directory
cd tmp
cd "/tmp/${SHORTCUT_NAME}"

# rename package
# - lower case letters
Expand All @@ -123,8 +130,6 @@ if [ ${MACHINE} = "Linux" ]; then
sed -i "s/shortcut_template/shortcut_${SHORTCUT_NAME_UNDERSCORE}/" app/build.gradle
sed -i "s/shortcut_template/shortcut_${SHORTCUT_NAME_UNDERSCORE}/" app/src/main/AndroidManifest.xml
sed -i "s/shortcut_template/shortcut_${SHORTCUT_NAME_UNDERSCORE}/" app/src/main/java/com/hapirobo/shortcut_template/MainActivity.java
sed -i "s/shortcut_template/shortcut_${SHORTCUT_NAME_UNDERSCORE}/" app/src/androidTest/java/com/hapirobo/shortcut_template/ExampleInstrumentedTest.java
sed -i "s/shortcut_template/shortcut_${SHORTCUT_NAME_UNDERSCORE}/" app/src/test/java/com/hapirobo/shortcut_template/ExampleUnitTest.java
sed -i "s/shortcut_name/${SHORTCUT_NAME}/" app/src/main/res/values/strings.xml
sed -i "s/com.hapirobo.package_name/${PACKAGE_NAME}/" app/src/main/res/values/strings.xml
elif [ ${MACHINE} = "Darwin" ]; then
Expand All @@ -133,8 +138,6 @@ elif [ ${MACHINE} = "Darwin" ]; then
sed -i .bak "s/shortcut_template/shortcut_${SHORTCUT_NAME_UNDERSCORE}/" app/build.gradle
sed -i .bak "s/shortcut_template/shortcut_${SHORTCUT_NAME_UNDERSCORE}/" app/src/main/AndroidManifest.xml
sed -i .bak "s/shortcut_template/shortcut_${SHORTCUT_NAME_UNDERSCORE}/" app/src/main/java/com/hapirobo/shortcut_template/MainActivity.java
sed -i .bak "s/shortcut_template/shortcut_${SHORTCUT_NAME_UNDERSCORE}/" app/src/androidTest/java/com/hapirobo/shortcut_template/ExampleInstrumentedTest.java
sed -i .bak "s/shortcut_template/shortcut_${SHORTCUT_NAME_UNDERSCORE}/" app/src/test/java/com/hapirobo/shortcut_template/ExampleUnitTest.java
sed -i .bak "s/shortcut_name/${SHORTCUT_NAME}/" app/src/main/res/values/strings.xml
sed -i .bak "s/com.hapirobo.package_name/${PACKAGE_NAME}/" app/src/main/res/values/strings.xml
else
Expand All @@ -144,23 +147,16 @@ fi

# rename directories
mv -v app/src/main/java/com/hapirobo/shortcut_template "app/src/main/java/com/hapirobo/shortcut_${SHORTCUT_NAME_UNDERSCORE}"
mv -v app/src/androidTest/java/com/hapirobo/shortcut_template "app/src/androidTest/java/com/hapirobo/shortcut_${SHORTCUT_NAME_UNDERSCORE}"
mv -v app/src/test/java/com/hapirobo/shortcut_template "app/src/test/java/com/hapirobo/shortcut_${SHORTCUT_NAME_UNDERSCORE}"

# build shortcut-APK
./gradlew clean
./gradlew build

# move shortcut-APK to root directory
cp -v app/build/outputs/apk/debug/app-debug.apk "../${SHORTCUT_NAME_UNDERSCORE}_shortcut.apk"

# clean up
echo "Cleaning up..."
cd ../
rm -fr tmp
echo "Done"
echo ""
cp app/build/outputs/apk/debug/app-debug.apk "${THIS_DIR}/${SHORTCUT_NAME_UNDERSCORE}_shortcut.apk"

# installation instructions
echo "Remember to install both the package and package-shortcut."
echo ""
echo "${THIS_DIR}/${SHORTCUT_NAME_UNDERSCORE}_shortcut.apk"
echo "Remember to install both the App and App-shortcut."
exit 0
2 changes: 1 addition & 1 deletion temi-launcher-shortcut-template

0 comments on commit 9d635d7

Please sign in to comment.