Created
June 25, 2024 05:26
-
-
Save xeron56/cbc091837a27752764f8add3a8a9b867 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Update and install necessary packages | |
apt-get update | |
apt-get install -y sudo jq curl git tar xz-utils libarchive-tools \ | |
openjdk-17-jdk | |
# Install ZeroTier | |
curl -s https://install.zerotier.com | bash | |
# Create vscode user with sudo privileges | |
useradd -m -s /bin/bash -G sudo vscode | |
echo "vscode ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/vscode | |
# Function to download Flutter | |
function download_flutter { | |
if [[ -f '/tmp/flutter.tar.xz' ]]; then | |
echo 'Flutter is already downloaded.' | |
return | |
fi | |
infra_channel='stable' | |
infra='https://storage.googleapis.com/flutter_infra_release/releases' | |
infra_json="$(curl -s "${infra}/releases_linux.json")" | |
infra_hash="$(echo ${infra_json} | \ | |
jq -r ".current_release.${infra_channel}")" | |
infra_release="$(echo ${infra_json} | \ | |
jq -r ".releases[] | select(.hash == \"${infra_hash}\")")" | |
flutter_version="$(echo ${infra_release} | jq -r '.version')" | |
dart_version="$(echo ${infra_release} | jq -r '.dart_sdk_version')" | |
flutter_archive="${infra}/$(echo ${infra_release} | jq -r '.archive')" | |
echo 'Downloading Flutter...' | |
echo "Flutter Channel : ${infra_channel}" | |
echo "Flutter Version : ${flutter_version}" | |
echo "Dart Version : ${dart_version}" | |
curl "${flutter_archive}" -o '/tmp/flutter.tar.xz' | |
} | |
# Function to extract Flutter | |
function extract_flutter { | |
echo 'Extracting Flutter...' | |
mkdir -p '/opt' | |
tar -xf '/tmp/flutter.tar.xz' -C '/opt' | |
echo 'Change ownership of Flutter folder...' | |
chown -R 'vscode:vscode' '/opt/flutter' | |
} | |
# Function to download Android Command Line Tools | |
function download_android_cmd { | |
if [[ -f '/tmp/cmdline.zip' ]]; then | |
echo 'Android Command Line Tools is already downloaded.' | |
return | |
fi | |
cmdline_archive="$(curl -s 'https://developer.android.com/studio' | \ | |
grep 'https' | grep 'commandlinetools-linux' | \ | |
sed -E 's/^\s+href=\"(.+)\"\s*$/\1/')" | |
echo 'Downloading Android Command Line Tools...' | |
curl "${cmdline_archive}" -o '/tmp/cmdline.zip' | |
} | |
# Function to extract Android Command Line Tools | |
function extract_android_cmd { | |
echo 'Extracting Android Command Line Tools...' | |
mkdir -p '/opt/android/sdk/cmdline-tools/latest' | |
bsdtar -xf '/tmp/cmdline.zip' -s '|[^/]*/||' \ | |
-C '/opt/android/sdk/cmdline-tools/latest' | |
echo 'Change ownership of Android SDK folder...' | |
chown -R 'vscode:vscode' '/opt/android' | |
} | |
# Function to download Android NDK | |
function download_ndk { | |
if [[ -f '/tmp/android-ndk-r26c-linux.zip' ]]; then | |
echo 'Android NDK is already downloaded.' | |
return | |
fi | |
ndk_archive='https://dl.google.com/android/repository/android-ndk-r26c-linux.zip' | |
echo 'Downloading Android NDK...' | |
curl "${ndk_archive}" -o '/tmp/android-ndk-r26c-linux.zip' | |
} | |
# Function to extract Android NDK | |
function extract_ndk { | |
echo 'Extracting Android NDK...' | |
mkdir -p '/opt/android/ndk/r26c' | |
bsdtar -xf '/tmp/android-ndk-r26c-linux.zip' --strip-components=1 \ | |
-C '/opt/android/ndk/r26c' | |
echo 'Change ownership of Android NDK folder...' | |
chown -R 'vscode:vscode' '/opt/android' | |
} | |
# Function to clear temporary files | |
function clear_temp { | |
rm '/tmp/flutter.tar.xz' | |
rm '/tmp/cmdline.zip' | |
rm '/tmp/android-ndk-r26c-linux.zip' | |
} | |
#instal utilities | |
function install_utilities { | |
echo "Installing utilities..." | |
sudo apt-get update | |
sudo apt-get install -y build-essential libgtk-3-dev ffmpeg libavcodec-dev cmake \ | |
ninja-build libavformat-dev libavutil-dev libswscale-dev \ | |
libgflags-dev libjpeg-dev libpng-dev libtiff-dev | |
# Check if python3 is installed, if not, install it | |
# if ! command -v python3 &> /dev/null; then | |
# echo "Python3 is not installed. Installing Python3..." | |
# sudo apt-get install -y python3 python3-pip | |
# else | |
# echo "Python3 is already installed." | |
# fi | |
# sudo apt install python3 | |
# sudo apt install python3-pip | |
# python3 -m pip config set global.break-system-packages true | |
# echo 'export PATH="$PATH:$HOME/.local/bin"' >> ~/.bashrc | |
#/root/.local/lib/python3.8/site-packages | |
echo 'export PATH="/root/.local/lib/python3.8/site-packages:$PATH""' >> ~/.bashrc | |
source ~/.bashrc | |
pip install conan --user | |
# Install Conan | |
# python3 -m pip install conan | |
} | |
#install fvm curl -fsSL https://fvm.app/install.sh | bash | |
function install_fvm { | |
echo "Installing FVM..." | |
curl -fsSL https://fvm.app/install.sh | bash | |
} | |
function postInstall { | |
#!/bin/bash | |
cat >> '/home/vscode/.environment' << EOF | |
# global environment | |
export ANDROID_HOME="/opt/android/sdk" | |
export ANDROID_NDK_HOME="/opt/android/ndk/r26c" | |
export PATH="\$PATH:/opt/flutter/bin" | |
export PATH="\$PATH:/opt/android/sdk/cmdline-tools/latest/bin" | |
export PATH="\$PATH:/opt/android/sdk/platform-tools" | |
export PATH="\$PATH:/opt/android/sdk/build-tools/34.0.0" | |
export PATH="\$PATH:/home/vscode/.pub-cache/bin" | |
EOF | |
echo 'Add environment to ~/.profile...' | |
echo "source '/home/vscode/.environment'" >> '/home/vscode/.profile' | |
echo 'Add environment to ~/.zprofile...' | |
echo "source '/home/vscode/.environment'" >> '/home/vscode/.zprofile' | |
source '/home/vscode/.environment' | |
echo 'Installing Android Platform 33...' | |
yes | sdkmanager 'platform-tools' 'platforms;android-33' 'build-tools;34.0.0' | |
flutter config --android-sdk '/opt/android/sdk' | |
yes | flutter doctor --android-licenses | |
# # Install FVM | |
# echo 'Installing FVM...' | |
# dart pub global activate fvm | |
# echo 'Configuring FVM...' | |
# fvm install stable | |
# fvm global stable | |
fvm install 3.19.6 | |
# Disable telemetry | |
echo 'Disabling analytics...' | |
flutter --disable-analytics | |
dart --disable-analytics | |
git config --global --add safe.directory /opt/flutter | |
echo 'export OPENCV_DART_LIB_PATH=$(pwd)/linux/libopencv_dart.so' >> ~/.bashrc | |
source ~/.bashrc | |
} | |
download_flutter | |
extract_flutter | |
download_android_cmd | |
extract_android_cmd | |
download_ndk | |
extract_ndk | |
install_utilities | |
install_fvm | |
clear_temp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment