diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml index 7ba50010..e10d5014 100644 --- a/.github/workflows/shellcheck.yml +++ b/.github/workflows/shellcheck.yml @@ -3,9 +3,9 @@ name: ShellCheck scripts jobs: shellCheck: name: ShellCheck - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - name: Run shellcheck. run: | while read -r script; do shellcheck --exclude=SC1090,SC1091 $script; done < files diff --git a/aliases b/aliases index 568b1ed2..a89e2c2a 100755 --- a/aliases +++ b/aliases @@ -19,3 +19,6 @@ export EDITOR="nano" # Set timezone export TZ="Asia/Kolkata" + +alias camera_off="echo '\_SB.ATKD.WMNB 0x00 0x53564544 0x0000000000060078' | sudo tee /proc/acpi/call" +alias camera_on="echo '\_SB.ATKD.WMNB 0x00 0x53564544 0x0000000100060078' | sudo tee /proc/acpi/call" diff --git a/files b/files index 980f25ea..e9d6c1f0 100644 --- a/files +++ b/files @@ -29,6 +29,7 @@ rr/channel.sh rr/crowdin.sh rr/copy_ftp.sh rr/push_json.sh +setup/acpi_call.sh setup/android_build_env.sh setup/arch-manjaro.sh setup/ccache.sh diff --git a/functions b/functions index 055f1cdb..6c1fced1 100755 --- a/functions +++ b/functions @@ -222,3 +222,19 @@ GDrive ID: \`${GDRIVE_UPLOAD_ID}\` tgm "${UPLOAD_INFO}" echo "Get the file with ${GDRIVE_UPLOAD_ID}" } + +# Paste content to katb.in +function katbin() { + local content + if [[ -z "$1" ]]; then + if [[ -t 0 ]]; then + echo "Error: No content provided. Provide as argument or pipe in." + return 1 + else + content=$(cat) + fi + else + content="$1" + fi + curl -sL 'https://katb.in/api/paste' --json '{"paste":{"content":"'"$content"'"}}' | jq -r '"https://katb.in/\(.id)"' +} diff --git a/github/push-all-repos-git.sh b/github/push-all-repos-git.sh new file mode 100644 index 00000000..fffb5827 --- /dev/null +++ b/github/push-all-repos-git.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +# A github script to push all repositories from a manifest + +# This again, will have to be adapted based on your setup. + +cwd=$PWD +PROJECTS="$(grep 'aosip' .repo/manifests/aosip.xml | awk '{print $2}' | awk -F'"' '{print $2}' | uniq | grep -v caf)" +for project in ${PROJECTS}; do + cd "$project" || exit + git push git@github.com:AOSIP/"$(git remote -v | head -n1 | awk '{print $2}' | sed 's/.*\///' | sed 's/\.git//')".git HEAD:refs/heads/nougat-mr2 + cd - || exit +done +cd "$cwd" || exit diff --git a/random-py/apn-copy-entries.py b/random-py/apn-copy-entries.py new file mode 100755 index 00000000..d397461f --- /dev/null +++ b/random-py/apn-copy-entries.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python + +import sys +from pathlib import Path +from xml.etree import ElementTree + +# ./apn-copy-entries.py source.xml destination.xml +# If no arguments are provided, the user will be prompted to enter the file paths + +if len(sys.argv) < 3: + source = input("Enter the source XML path: ") + destination = input("Enter the destination XML path: ") +else: + source = sys.argv[1] + destination = sys.argv[2] + +source_path = Path(source) +destination_path = Path(destination) + +if not source_path.exists() or not destination_path.exists(): + print("Please ensure that both the files exist") + sys.exit(1) + +source_apn_xml = ElementTree.parse(source_path) +destination_apn_xml = ElementTree.parse(destination_path) + +tags_to_match = ("mcc", "mnc") +tags_to_copy = ("apn") + +destination_root = destination_apn_xml.getroot() + +combinations = set() + +# Define a function to check if a child element is already in the destination root +def is_in_destination(child, destination_root): + for dest_child in destination_root: + if child.attrib == dest_child.attrib: + return True + return False + +# Modify the loop that appends children from the source to the destination +for child in source_apn_xml.getroot(): + # Only consider children with apn='ims' + if child.attrib.get('apn') == 'ims': + # Only append the child if it is not already in the destination + if not is_in_destination(child, destination_root): + destination_root.append(child) + +destination_apn_xml.write(destination, encoding="utf-8") diff --git a/random-py/apn-copy-tag.py b/random-py/apn-copy-tag.py new file mode 100755 index 00000000..1cfdf981 --- /dev/null +++ b/random-py/apn-copy-tag.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python + +import sys +from pathlib import Path +from xml.etree import ElementTree + +# ./apn.py source.xml destination.xml +# If no arguments are provided, the user will be prompted to enter the file paths + +if len(sys.argv) < 3: + source = input("Enter the source XML path: ") + destination = input("Enter the destination XML path: ") +else: + source = sys.argv[1] + destination = sys.argv[2] + +source_path = Path(source) +destination_path = Path(destination) + +if not source_path.exists() or not destination_path.exists(): + print("Please ensure that both the files exist") + sys.exit(1) + +source_apn_xml = ElementTree.parse(source_path) +destination_apn_xml = ElementTree.parse(destination_path) + +tags_to_match = ("apn", "mcc", "mnc") +tags_to_copy = ("network_type_bitmask", "type") +required_tags = tags_to_match + tags_to_copy + +mapping = {} + +for child in source_apn_xml.getroot(): + if not all(tag in child.attrib for tag in required_tags): + continue + mapping["|".join([child.attrib[tag] for tag in tags_to_match])] = { + tag: child.attrib[tag] for tag in tags_to_copy + } + + +for child in destination_apn_xml.getroot(): + if not all(tag in child.attrib for tag in tags_to_match): + continue + key = "|".join([child.attrib[tag] for tag in tags_to_match]) + if key in mapping: + for tag in tags_to_copy: + child.attrib[tag] = mapping[key][tag] + +destination_apn_xml.write(destination, encoding="utf-8") diff --git a/random-py/sort_apn.py b/random-py/sort_apn.py new file mode 100755 index 00000000..f52df7b1 --- /dev/null +++ b/random-py/sort_apn.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python + +import sys +from pathlib import Path +from xml.etree import ElementTree + +# ./sort_apn.py apns-conf.xml +# If no arguments are provided, the user will be prompted to enter the file paths + +if len(sys.argv) < 2: + apns = input("Enter the apns-conf XML path: ") +else: + apns = sys.argv[1] + +apns_path = Path(apns) + +if not apns_path.exists(): + print("Please ensure that the files exist") + sys.exit(1) + +def sort_apns(apns_path): + # Parse the XML file into an ElementTree + tree = ElementTree.parse(apns_path) + root = tree.getroot() + + # Sort the children of the root by 'mcc' and 'mnc' + root[:] = sorted(root, key=lambda child: (child.attrib.get('mcc', ''), child.attrib.get('mnc', ''))) + + # Write the sorted ElementTree back into the XML file + with open(apns_path, 'wb') as f: + f.write(ElementTree.tostring(root, encoding='utf-8')) + +# Call the function with the XML file path +sort_apns(apns_path) diff --git a/setup/acpi_call.sh b/setup/acpi_call.sh new file mode 100755 index 00000000..1cfed88f --- /dev/null +++ b/setup/acpi_call.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + + +lsmod | rg -q acpi_call && { + echo "acpi_call already installed"; + exit 0; +} + +git clone https://github.com/nix-community/acpi_call /tmp/acpi_call +make -C /tmp/acpi_call +sudo make -C /tmp/acpi_call install +sudo depmod -a +sudo modprobe acpi_call +rm -rf /tmp/acpi_call/ diff --git a/setup/android-sdk-minimal.txt b/setup/android-sdk-minimal.txt index 6d0a5f5f..9b1ce6eb 100644 --- a/setup/android-sdk-minimal.txt +++ b/setup/android-sdk-minimal.txt @@ -1,8 +1,8 @@ -build-tools;30.0.3 -build-tools;31.0.0-rc2 -cmake;3.10.2.4988404 -ndk;22.1.7171670 +build-tools;31.0.0 +build-tools;32.0.0 +cmake;3.18.1 +ndk;23.1.7779620 platform-tools tools -platforms;android-30 -platforms;android-S +platforms;android-31 +platforms;android-32 diff --git a/setup/android_build_env.sh b/setup/android_build_env.sh index 55f81d33..c07331bd 100755 --- a/setup/android_build_env.sh +++ b/setup/android_build_env.sh @@ -13,10 +13,7 @@ DEBIAN_10_PACKAGES="libncurses5" DEBIAN_11_PACKAGES="libncurses5" PACKAGES="" -echo "Adding GitHub apt key and repository!" -sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key C99B11DEB97541F0 -sudo apt-add-repository https://cli.github.com/packages - +sudo apt install software-properties-common -y sudo apt update # Install lsb-core packages @@ -26,7 +23,7 @@ LSB_RELEASE="$(lsb_release -d | cut -d ':' -f 2 | sed -e 's/^[[:space:]]*//')" if [[ ${LSB_RELEASE} =~ "Mint 18" || ${LSB_RELEASE} =~ "Ubuntu 16" ]]; then PACKAGES="${UBUNTU_16_PACKAGES}" -elif [[ ${LSB_RELEASE} =~ "Ubuntu 20" || ${LSB_RELEASE} =~ "Ubuntu 21" ]]; then +elif [[ ${LSB_RELEASE} =~ "Ubuntu 20" || ${LSB_RELEASE} =~ "Ubuntu 21" || ${LSB_RELEASE} =~ "Ubuntu 22" || ${LSB_RELEASE} =~ 'Pop!_OS 2' ]]; then PACKAGES="${UBUNTU_20_PACKAGES}" elif [[ ${LSB_RELEASE} =~ "Debian GNU/Linux 10" ]]; then PACKAGES="${DEBIAN_10_PACKAGES}" @@ -37,17 +34,24 @@ fi sudo DEBIAN_FRONTEND=noninteractive \ apt install \ adb autoconf automake axel bc bison build-essential \ - ccache clang cmake expat fastboot flex g++ \ - g++-multilib gawk gcc gcc-multilib git gnupg gperf \ + ccache clang cmake curl expat fastboot flex g++ \ + g++-multilib gawk gcc gcc-multilib git git-lfs gnupg gperf \ htop imagemagick lib32ncurses5-dev lib32z1-dev libtinfo5 libc6-dev libcap-dev \ libexpat1-dev libgmp-dev '^liblz4-.*' '^liblzma.*' libmpc-dev libmpfr-dev libncurses5-dev \ libsdl1.2-dev libssl-dev libtool libxml2 libxml2-utils '^lzma.*' lzop \ maven ncftp ncurses-dev patch patchelf pkg-config pngcrush \ - pngquant python2.7 python-all-dev re2c schedtool squashfs-tools subversion \ + pngquant python2.7 python3-pyelftools python-all-dev re2c schedtool squashfs-tools subversion \ texinfo unzip w3m xsltproc zip zlib1g-dev lzip \ - libxml-simple-perl apt-utils gh \ + libxml-simple-perl libswitch-perl apt-utils rsync \ ${PACKAGES} -y +echo -e "Installing GitHub CLI" +curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg +sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg +echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null +sudo apt update +sudo apt install -y gh + echo -e "Setting up udev rules for adb!" sudo curl --create-dirs -L -o /etc/udev/rules.d/51-android.rules -O -L https://raw.githubusercontent.com/M0Rf30/android-udev-rules/master/51-android.rules sudo chmod 644 /etc/udev/rules.d/51-android.rules diff --git a/setup/arch-manjaro.sh b/setup/arch-manjaro.sh index f01b0ea3..0a742f48 100755 --- a/setup/arch-manjaro.sh +++ b/setup/arch-manjaro.sh @@ -9,19 +9,26 @@ echo '[1/4] Enabling multilib repo' sudo sed -i "/\[multilib\]/,/Include/"'s/^#//' /etc/pacman.conf # Sync, update, and prepare system echo '[2/4] Syncing repositories and updating system packages' -sudo pacman -Syyu --noconfirm --needed multilib-devel +sudo pacman -Syyu --noconfirm --needed git git-lfs multilib-devel fontconfig ttf-droid python-pyelftools # Install android build prerequisites echo '[3/4] Installing Android building prerequisites' packages="ncurses5-compat-libs lib32-ncurses5-compat-libs aosp-devel xml2 lineageos-devel" -for package in $packages; do - echo "Installing $package" - git clone https://aur.archlinux.org/"$package" - cd "$package" || exit - makepkg -si --skippgpcheck --noconfirm --needed - cd - || exit - rm -rf "$package" -done - +if command -v paru 2>&1 >/dev/null +then + paru -S --noconfirm --needed $packages +elif command -v yay 2>&1 >/dev/null +then + yay -S --noconfirm --needed $packages +else + for package in $packages; do + echo "Installing $package" + git clone https://aur.archlinux.org/"$package" + cd "$package" || exit + makepkg -si --skippgpcheck --noconfirm --needed + cd - || exit + rm -rf "$package" + done +fi # Install adb and associated udev rules echo '[4/4] Installing adb convenience tools' sudo pacman -S --noconfirm --needed android-tools android-udev diff --git a/setup/ccache.sh b/setup/ccache.sh index 6f16cf43..db026f1e 100755 --- a/setup/ccache.sh +++ b/setup/ccache.sh @@ -1,10 +1,10 @@ #!/usr/bin/env bash cd /tmp || exit 1 -git clone git://github.com/ccache/ccache.git +git clone https://github.com/ccache/ccache.git cd ccache || exit 1 -./autogen.sh -./configure --disable-man --with-libzstd-from-internet --with-libb2-from-internet +mkdir -p build && cd build || exit 1 +cmake -DHIREDIS_FROM_INTERNET=ON -DZSTD_FROM_INTERNET=ON -DCMAKE_BUILD_TYPE=Release .. make -j"$(nproc)" sudo make install rm -rf "${PWD}" diff --git a/setup/crowdin-cli.sh b/setup/crowdin-cli.sh index 0460b2f9..216d0930 100755 --- a/setup/crowdin-cli.sh +++ b/setup/crowdin-cli.sh @@ -3,6 +3,12 @@ # Script to setup environment for crowdin # shellcheck disable=SC1010 -sudo apt install python-git -curl -sSL https://get.rvm.io | bash -s stable --ruby -rvm all do gem install crowdin-cli +# Install crowdin-cli +wget https://artifacts.crowdin.com/repo/deb/crowdin3.deb -O crowdin.deb +sudo dpkg -i crowdin.deb +echo "crowdin-cli installed" +echo "" + +# Test crowdin-cli +echo "Your crowdin version:" +crowdin --version \ No newline at end of file diff --git a/setup/fedora.sh b/setup/fedora.sh index e357786c..15504368 100755 --- a/setup/fedora.sh +++ b/setup/fedora.sh @@ -2,8 +2,8 @@ # # SPDX-License-Identifier: GPL-3.0-only # -# Script to setup an Android 10 build -# environment for Fedora 31 / Rawhide. +# Script to setup an Android 10+ build +# environment for Fedora 37 / Rawhide. # Packages sudo dnf install \ @@ -12,11 +12,13 @@ sudo dnf install \ bison \ bzip2 \ ccache \ + clang \ curl \ flex \ gawk \ gcc-c++ \ git \ + git-lfs \ glibc-devel \ glibc-static \ libstdc++-static \ @@ -38,20 +40,24 @@ sudo dnf install \ zip \ perl-Digest-SHA \ python2 \ + python3-pyelftools \ wget \ lzop \ openssl-devel \ + openssl-devel-engine \ java-1.8.0-openjdk-devel \ ImageMagick \ - ncurses-compat-libs \ schedtool \ lzip \ vboot-utils \ - vim + vim \ + libxcrypt-compat # The package libncurses5 is not available, so we need to hack our way by symlinking the required library. sudo ln -s /usr/lib/libncurses.so.6 /usr/lib/libncurses.so.5 sudo ln -s /usr/lib/libncurses.so.6 /usr/lib/libtinfo.so.5 +sudo ln -s /usr/lib64/libncurses.so.6 /usr/lib64/libncurses.so.5 +sudo ln -s /usr/lib64/libncurses.so.6 /usr/lib64/libtinfo.so.5 # Repo echo "Installing Git Repository Tool" diff --git a/setup/install_android_sdk.sh b/setup/install_android_sdk.sh index be83344e..8a85cdb8 100755 --- a/setup/install_android_sdk.sh +++ b/setup/install_android_sdk.sh @@ -7,7 +7,7 @@ trap 'rm -rf /tmp/tools.zip 2>/dev/null' INT TERM EXIT CUR_DIR="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd)" CUR_DIR="${CUR_DIR/setup/}" -SDK_TOOLS=commandlinetools-linux-6858069_latest.zip +SDK_TOOLS=commandlinetools-linux-7583922_latest.zip function setup_android_sdk() { echo "Installing Android SDK" diff --git a/setup/opensuse.sh b/setup/opensuse.sh new file mode 100644 index 00000000..b4b92af1 --- /dev/null +++ b/setup/opensuse.sh @@ -0,0 +1,95 @@ +#!/usr/bin/env bash + +# Script to setup an android build environment for openSUSE. + +# openSUSE Mirrors (https://github.com/Firstyear/mirrorsorcerer) +sudo zypper in mirrorsorcerer +sudo systemctl enable --now mirrorsorcerer + +# Packages +sudo zypper install \ + android-tools \ + autoconf213 \ + bc \ + bison \ + bzip2 \ + ccache \ + clang \ + curl \ + flex \ + gawk \ + gpg2 \ + gperf \ + gcc-c++ \ + git \ + git-lfs \ + glibc-devel \ + ImageMagick \ + java-11-openjdk \ + java-1_8_0-openjdk \ + java-1_8_0-openjdk-devel \ + liblz4-1 \ + libncurses5 \ + libncurses6 \ + libpopt0 \ + libressl-devel \ + libstdc++6\ + libX11-6 \ + libxml2-tools \ + libxslt1 \ + libX11-devel \ + libXrandr2 \ + lzip \ + lzop \ + kernel-devel \ + maven \ + make \ + megatools \ + Mesa-libGL1 \ + Mesa-libGL-devel \ + mokutil \ + nano \ + neofetch \ + ncurses5-devel \ + ncurses-devel \ + openssl \ + opi \ + patch \ + perl-Digest-SHA1 \ + python \ + python-rpm-generators \ + python3-pyelftools \ + readline-devel \ + schedtool \ + screenfetch \ + sha3sum \ + squashfs \ + vim \ + wget \ + wireguard-tools \ + xf86-video-intel \ + zip \ + zlib-devel + +# Devel Basis on OpenSUSE (https://darryldias.me/2020/devel-basis-on-opensuse-sle/) +sudo zypper install -t pattern devel_basis + +# The package libncurses5 is not available, so we need to hack our way by symlinking the required library. +sudo ln -s /usr/lib/libncurses.so.6 /usr/lib/libncurses.so.5 +sudo ln -s /usr/lib/libncurses.so.6 /usr/lib/libtinfo.so.5 +sudo ln -s /usr/lib64/libncurses.so.6 /usr/lib64/libncurses.so.5 +sudo ln -s /usr/lib64/libncurses.so.6 /usr/lib64/libtinfo.so.5 + +# Repo +echo "Installing Git Repository Tool" +sudo curl --create-dirs -L -o /usr/local/bin/repo -O -L https://storage.googleapis.com/git-repo-downloads/repo +sudo chmod a+rx /usr/local/bin/repo + +echo -e "Setting up udev rules for ADB!" +sudo curl --create-dirs -L -o /etc/udev/rules.d/51-android.rules -O -L https://raw.githubusercontent.com/M0Rf30/android-udev-rules/master/51-android.rules +sudo chmod 644 /etc/udev/rules.d/51-android.rules +sudo chown root /etc/udev/rules.d/51-android.rules +sudo udevadm control --reload-rules + +# Set default editor +git config --global core.editor "nano"