diff --git a/README.md b/README.md index 569fcb6..1521b47 100644 --- a/README.md +++ b/README.md @@ -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 +usage: shortcut.sh Creates a shortcut for APK file @@ -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. ``` diff --git a/extract_icon.sh b/extract_icon.sh new file mode 100755 index 0000000..dc58073 --- /dev/null +++ b/extract_icon.sh @@ -0,0 +1,82 @@ +#!/bin/sh +# +# Extracts icon from APK +# +# Usage +# ./extract_icon.sh +# +# 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 " + 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 diff --git a/package_name.sh b/package_name.sh index 44f27e2..62e937e 100755 --- a/package_name.sh +++ b/package_name.sh @@ -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 @@ -31,6 +31,9 @@ # SOFTWARE. # +# abort if any command fails +set -e + # display usage instructions usage() { @@ -48,13 +51,13 @@ 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 @@ -62,8 +65,6 @@ 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 \ No newline at end of file +exit 0 diff --git a/shortcut.sh b/shortcut.sh index 30438cd..df33e56 100755 --- a/shortcut.sh +++ b/shortcut.sh @@ -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() @@ -45,8 +46,8 @@ 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 "" @@ -54,7 +55,6 @@ usage() 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 @@ -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 } @@ -84,6 +86,7 @@ fi if [ -z "$1" ]; then echo "Missing package name" usage + exit 1 else PACKAGE_NAME=$1 fi @@ -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 @@ -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 @@ -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 @@ -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 \ No newline at end of file diff --git a/temi-launcher-shortcut-template b/temi-launcher-shortcut-template index 263c547..2d1a802 160000 --- a/temi-launcher-shortcut-template +++ b/temi-launcher-shortcut-template @@ -1 +1 @@ -Subproject commit 263c547eea4bae3add429cda7ecde4a586bf2f58 +Subproject commit 2d1a80220b9847884f262011b03dad18412eb808