Last active
January 26, 2024 09:42
-
-
Save Abhinav1217/4046e533dbb9c20a19bef77129108487 to your computer and use it in GitHub Desktop.
Install or Update Dart Sass in linux system.
This file contains 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
#!/usr/bin/env bash | |
# Script to update dart-sass from official github release. | |
# Copyright (C) 2021 Abhinav Kulshreshtha | |
# Changelog | |
# 26th january 2024 fix for new URL format and recommended binary path practice. | |
# 05th october 2021 "updated with proper url" | |
# Permission to copy and modify is granted under the terms of WTFPL-2 license. | |
# | |
# 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. | |
# -------------------------------------------- | |
# This script currently works with github api version 2 | |
# use of 'jq' has been removed for more portability. | |
# | |
# This script will install latest dart-sass globally without user interaction. | |
# -------------------------------------------- | |
# SUDO check | |
if [ "$(id -u)" -ne 0 ]; then | |
echo 'This script must be run by root' >&2 | |
exec sudo bash $(pwd)/"$0" $(pwd)/"$@" | |
fi | |
# some common variables | |
GITHUB_RELEASES_URL="https://api.github.com/repos/sass/dart-sass/releases/latest" | |
URL="" | |
KERNEL=$(uname -m) | |
case "$KERNEL" in | |
"x86_64") KERNEL_VERSION="x64" ;; | |
*) KERNEL_VERSION="ia32" ;; | |
esac | |
# Get the latest release version of dart. | |
function checkUpdate { | |
LATEST_VERSION=$(curl -s $GITHUB_RELEASES_URL | grep -i tag_name | awk '{ print $2; }' | head -n 1 | sed 's/\"//g'| sed 's/,//g') | |
echo "Latest version found is $LATEST_VERSION" | |
} | |
function installLatest { | |
URL=$(curl -s $GITHUB_RELEASES_URL | grep -i browser_download_url | grep -i linux-$KERNEL_VERSION.tar.gz | awk '{ print $2; }' | head -n 1 | sed 's/\"//g') | |
FILE=${URL##*/} | |
CACHEDIR="/tmp/dart-sass" | |
DESTINATION="/usr/bin/sass" | |
mkdir -p "$CACHEDIR" && cd "$CACHEDIR" | |
echo "Downloading file in $CACHEDIR" | |
wget -c "$URL" -O "$FILE" | |
if [[ ! -f "$FILE" ]]; then | |
exit 1 | |
fi | |
# tar -xf "$FILE" --strip 1 | |
echo "Extracting file in $CACHEDIR" | |
tar -xf -- "$FILE" # new binaries need to be at top level | |
# sudo mv sass $DESTINATION | |
echo "Moving folder dart-sass to /usr/bin" | |
sudo mv -- dart-sass /usr/bin | |
echo "linking /usr/bin/dart-sass/sass to /usr/bin/sass" | |
sudo ln -s -- /usr/bin/dart-sass/sass $DESTINATION | |
echo "applying execute permission to /usr/bin/sass" | |
sudo chmod +x $DESTINATION | |
echo "--------------------------" | |
echo "Update completed..." | |
} | |
if command -v sass &> /dev/null; then | |
CURRENT_VERSION=$(sass --version) | |
echo "dart-sass installation is found, current version is $CURRENT_VERSION" | |
checkUpdate | |
if [[ "$CURRENT_VERSION" != "$LATEST_VERSION" ]]; then | |
echo "update is available" | |
installLatest | |
exit | |
else | |
echo "Nothing to do"; exit | |
fi | |
else | |
echo "dart sass not found" | |
echo "dart-sass will be installed at /usr/bin/sass" | |
echo "--------------------------" | |
echo "" | |
checkUpdate | |
installLatest | |
exit | |
fi | |
# TODO: Add command line parameters for more control of behaviour. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment