Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some shell script formatting #4559

Merged
merged 4 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions .docker/android_dev/tools/android-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,43 @@ export ANDROID_SDK=${ANDROID_HOME}
export PATH=${PATH}:${ANDROID_HOME}/cmdline-tools/latest/bin:${ANDROID_HOME}/platform-tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/emulator:${ANDROID_HOME}/bin:

if [[ ! -z "$http_proxy" ]] || [[ ! -z "$https_proxy" ]]; then
export JAVA_OPTS="-Djava.net.useSystemProxies=true $JAVA_OPTS -Dhttp.noProxyHosts=${no_proxy}"
# This only works if there is a proxy listening on docker host machine and
# container is started with --net=host. No other options for now. Thanks
# google....
export SDKMNGR_OPTS=" --proxy=http --proxy_host=127.0.0.1 --proxy_port=3128 --no_https "
export JAVA_OPTS="-Djava.net.useSystemProxies=true $JAVA_OPTS -Dhttp.noProxyHosts=${no_proxy}"
# This only works if there is a proxy listening on docker host machine and
# container is started with --net=host. No other options for now. Thanks
# google....
export SDKMNGR_OPTS=" --proxy=http --proxy_host=127.0.0.1 --proxy_port=3128 --no_https "
fi

function print_header() {
figlet SBB CFF FFS
figlet welcome to
figlet andep
echo ''
echo ''
echo ''
figlet SBB CFF FFS
figlet welcome to
figlet andep
echo ''
echo ''
echo ''
}

function help() {
figlet "usage:"
echo "update_sdk: Updates the SDK"
echo "andep: Installs one or more android Packets."
echo " -Example: anddep \"platforms;android-26\""
echo "help: Shows this help"
echo ''
echo ''
echo ''
figlet "usage:"
echo "update_sdk: Updates the SDK"
echo "andep: Installs one or more android Packets."
echo " -Example: anddep \"platforms;android-26\""
echo "help: Shows this help"
echo ''
echo ''
echo ''
}

function update_sdk() {
android-accept-licenses.sh "sdkmanager ${SDKMNGR_OPTS} --update"
android-accept-licenses.sh "sdkmanager ${SDKMNGR_OPTS} --update"
}

function andep() {
if [ -z ${1} ]; then
help
return 1
fi
android-accept-licenses.sh "sdkmanager ${SDKMNGR_OPTS} ${1}"
if [ -z ${1} ]; then
help
return 1
fi
android-accept-licenses.sh "sdkmanager ${SDKMNGR_OPTS} ${1}"
}

export -f help
Expand Down
60 changes: 27 additions & 33 deletions .docker/android_dev/tools/android-sdk-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,29 @@ source /opt/android-sdk-linux/bin/android-env.sh

built_in_sdk=1

if [ $# -ge 0 ] && [ "$1" == "lazy-dl" ]
then
echo "Using Lazy Download Flavour"
built_in_sdk=0
elif [ $# -ge 0 ] && [ "$1" == "built-in" ]
then
echo "Using Built-In SDK Flavour"
built_in_sdk=1
if [ $# -ge 0 ] && [ "$1" == "lazy-dl" ]; then
echo "Using Lazy Download Flavour"
built_in_sdk=0
elif [ $# -ge 0 ] && [ "$1" == "built-in" ]; then
echo "Using Built-In SDK Flavour"
built_in_sdk=1
else
echo "Please use either built-in or lazy-dl as parameter"
exit 1
echo "Please use either built-in or lazy-dl as parameter"
exit 1
fi

cd ${ANDROID_HOME}
echo "Set ANDROID_HOME to ${ANDROID_HOME}"

if [ -f .bootstrapped ]
then
echo "SDK Tools already bootstrapped. Skipping initial setup"
if [ -f .bootstrapped ]; then
echo "SDK Tools already bootstrapped. Skipping initial setup"
else
echo "Bootstrapping SDK-Tools"
mkdir -p cmdline-tools/latest/ \
&& curl -sSL http://dl.google.com/android/repository/commandlinetools-linux-7583922_latest.zip -o sdk-tools-linux.zip \
&& bsdtar xvf sdk-tools-linux.zip --strip-components=1 -C cmdline-tools/latest \
&& rm sdk-tools-linux.zip \
&& touch .bootstrapped
echo "Bootstrapping SDK-Tools"
mkdir -p cmdline-tools/latest/ &&
curl -sSL http://dl.google.com/android/repository/commandlinetools-linux-7583922_latest.zip -o sdk-tools-linux.zip &&
bsdtar xvf sdk-tools-linux.zip --strip-components=1 -C cmdline-tools/latest &&
rm sdk-tools-linux.zip &&
touch .bootstrapped
fi

echo "Make sure repositories.cfg exists"
Expand All @@ -48,17 +45,15 @@ cp -v /opt/tools/*.sh ${ANDROID_HOME}/bin
echo "Print sdkmanager version"
sdkmanager --version


echo "Installing packages"
if [ $built_in_sdk -eq 1 ]
then
while read p; do
android-accept-licenses.sh "sdkmanager ${SDKMNGR_OPTS} ${p}"
done < /opt/tools/package-list-minimal.txt
if [ $built_in_sdk -eq 1 ]; then
while read p; do
android-accept-licenses.sh "sdkmanager ${SDKMNGR_OPTS} ${p}"
done </opt/tools/package-list-minimal.txt
else
while read p; do
android-accept-licenses.sh "sdkmanager ${SDKMNGR_OPTS} ${p}"
done < /opt/tools/package-list.txt
while read p; do
android-accept-licenses.sh "sdkmanager ${SDKMNGR_OPTS} ${p}"
done </opt/tools/package-list.txt
fi

echo "Updating SDK"
Expand All @@ -68,9 +63,8 @@ echo "Accepting Licenses"
android-accept-licenses.sh "sdkmanager ${SDKMNGR_OPTS} --licenses"

# https://stackoverflow.com/questions/35128229/error-no-toolchains-found-in-the-ndk-toolchains-folder-for-abi-with-prefix-llv
if [ -d /opt/android-sdk-linux/ndk-bundle/toolchains ]
then
( cd /opt/android-sdk-linux/ndk-bundle/toolchains \
&& ln -sf aarch64-linux-android-4.9 mips64el-linux-android \
&& ln -sf arm-linux-androideabi-4.9 mipsel-linux-android )
if [ -d /opt/android-sdk-linux/ndk-bundle/toolchains ]; then
(cd /opt/android-sdk-linux/ndk-bundle/toolchains &&
ln -sf aarch64-linux-android-4.9 mips64el-linux-android &&
ln -sf arm-linux-androideabi-4.9 mipsel-linux-android)
fi
32 changes: 16 additions & 16 deletions .docker/android_dev/tools/android-wait-for-emulator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ sleeptime=10
maxfail=$((timeout / sleeptime))

until [[ "${bootcomplete}" =~ "1" ]]; do
bootcomplete=`adb -e shell getprop dev.bootcomplete 2>&1 &`
if [[ "${bootcomplete}" =~ "" ]]; then
((failcounter += 1))
echo "Waiting for emulator to start"
if [[ ${failcounter} -gt ${maxfail} ]]; then
echo "Timeout ($timeout seconds) reached; failed to start emulator"
while pkill -9 "emulator" >/dev/null 2>&1; do
echo "Killing emulator process...."
pgrep "emulator"
done
echo "Process terminated"
pgrep "emulator"
exit 1
fi
fi
sleep ${sleeptime}
bootcomplete=$(adb -e shell getprop dev.bootcomplete 2>&1 &)
if [[ "${bootcomplete}" =~ "" ]]; then
((failcounter += 1))
echo "Waiting for emulator to start"
if [[ ${failcounter} -gt ${maxfail} ]]; then
echo "Timeout ($timeout seconds) reached; failed to start emulator"
while pkill -9 "emulator" >/dev/null 2>&1; do
echo "Killing emulator process...."
pgrep "emulator"
done
echo "Process terminated"
pgrep "emulator"
exit 1
fi
fi
sleep ${sleeptime}
done

echo "Emulator is ready"
15 changes: 4 additions & 11 deletions .docker/android_dev/tools/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
#!/bin/bash

function checkbin() {
type -P su-exec
type -P su-exec
}

function su_mt_user() {
su android -c '"$0" "$@"' -- "$@"
su android -c '"$0" "$@"' -- "$@"
}

chown android:android /opt/android-sdk-linux

printenv

if checkbin; then
exec su-exec android:android /opt/tools/android-sdk-update.sh "$@"
exec su-exec android:android /opt/tools/android-sdk-update.sh "$@"
else
su_mt_user /opt/tools/android-sdk-update.sh ${1}
su_mt_user /opt/tools/android-sdk-update.sh ${1}
fi







5 changes: 4 additions & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ on:

jobs:
pre-commit:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Install dependencies
run: sudo apt install -y shfmt

- uses: actions/github-script@v6
if: ${{ github.event.issue.pull_request }}
id: get-pr
Expand Down
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ repos:
- id: check-added-large-files
args: ['--maxkb=8000']

- repo: local
hooks:
# - id: qmllint
# name: Run qmllint
# description: QML linter
# entry: qmllint
# language: system
# files: .*\.qml

- id: shfmt
name: Run shfmt
description: shfmt Shell code formatter.
entry: shfmt -w
language: system
types: [file, shell]
exclude: .docker/android_dev/tools/android-accept-licenses.sh

# Shellcheck
- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 2.1.5
Expand Down
Loading
Loading