mirror of
https://github.com/actions/runner-images.git
synced 2025-12-12 03:57:32 +00:00
[ubuntu] Unify approach to /etc/environment (#8904)
* [ubuntu] Unify approach to /etc/environment * [ubuntu] fix typo in XDG_CONFIG_HOME name
This commit is contained in:
committed by
GitHub
parent
da1c04b81a
commit
435ba67550
@@ -4,6 +4,9 @@
|
||||
## Desc: Configure dpkg
|
||||
################################################################################
|
||||
|
||||
# Source the helpers for use with the script
|
||||
source $HELPER_SCRIPTS/etc-environment.sh
|
||||
|
||||
# This is the anti-frontend. It never interacts with you at all,
|
||||
# and makes the default answers be used for all questions. It
|
||||
# might mail error messages to root, but that's it; otherwise it
|
||||
@@ -11,7 +14,7 @@
|
||||
# automatic installs. If you are using this front-end, and require
|
||||
# non-default answers to questions, you will need to preseed the
|
||||
# debconf database
|
||||
echo 'DEBIAN_FRONTEND=noninteractive' | tee -a /etc/environment
|
||||
setEtcEnvironmentVariable "DEBIAN_FRONTEND" "noninteractive"
|
||||
|
||||
# dpkg can be instructed not to ask for confirmation
|
||||
# when replacing a configuration file (with the --force-confdef --force-confold options)
|
||||
|
||||
@@ -6,17 +6,18 @@
|
||||
|
||||
# Source the helpers for use with the script
|
||||
source $HELPER_SCRIPTS/os.sh
|
||||
source $HELPER_SCRIPTS/etc-environment.sh
|
||||
|
||||
# Set ImageVersion and ImageOS env variables
|
||||
echo ImageVersion=$IMAGE_VERSION | tee -a /etc/environment
|
||||
echo ImageOS=$IMAGE_OS | tee -a /etc/environment
|
||||
setEtcEnvironmentVariable "ImageVersion" "${IMAGE_VERSION}"
|
||||
setEtcEnvironmentVariable "ImageOS" "${IMAGE_OS}"
|
||||
|
||||
# Set the ACCEPT_EULA variable to Y value to confirm your acceptance of the End-User Licensing Agreement
|
||||
echo ACCEPT_EULA=Y | tee -a /etc/environment
|
||||
setEtcEnvironmentVariable "ACCEPT_EULA" "Y"
|
||||
|
||||
# This directory is supposed to be created in $HOME and owned by user(https://github.com/actions/runner-images/issues/491)
|
||||
mkdir -p /etc/skel/.config/configstore
|
||||
echo 'XDG_CONFIG_HOME=$HOME/.config' | tee -a /etc/environment
|
||||
setEtcEnvironmentVariable "XDG_CONFIG_HOME" '$HOME/.config'
|
||||
|
||||
# Change waagent entries to use /mnt for swapfile
|
||||
sed -i 's/ResourceDisk.Format=n/ResourceDisk.Format=y/g' /etc/waagent.conf
|
||||
@@ -29,7 +30,7 @@ sed -i 's/::1 ip6-localhost ip6-loopback/::1 localhost ip6-localhost ip6-loo
|
||||
# Prepare directory and env variable for toolcache
|
||||
AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache
|
||||
mkdir $AGENT_TOOLSDIRECTORY
|
||||
echo "AGENT_TOOLSDIRECTORY=$AGENT_TOOLSDIRECTORY" | tee -a /etc/environment
|
||||
setEtcEnvironmentVariable "AGENT_TOOLSDIRECTORY" "${AGENT_TOOLSDIRECTORY}"
|
||||
chmod -R 777 $AGENT_TOOLSDIRECTORY
|
||||
|
||||
# https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
## Desc: Post deployment system configuration actions
|
||||
################################################################################
|
||||
|
||||
# Source the helpers for use with the script
|
||||
source $HELPER_SCRIPT_FOLDER/etc-environment.sh
|
||||
|
||||
mv -f /imagegeneration/post-generation /opt
|
||||
|
||||
echo "chmod -R 777 /opt"
|
||||
@@ -17,7 +20,7 @@ chmod 755 $IMAGE_FOLDER
|
||||
ENVPATH=$(grep 'PATH=' /etc/environment | head -n 1 | sed -z 's/^PATH=*//')
|
||||
ENVPATH=${ENVPATH#"\""}
|
||||
ENVPATH=${ENVPATH%"\""}
|
||||
echo "PATH=$ENVPATH" | sudo tee -a /etc/environment
|
||||
addEtcEnvironmentVariable "PATH" "${ENVPATH}"
|
||||
echo "Updated /etc/environment: $(cat /etc/environment)"
|
||||
|
||||
# Сlean yarn and npm cache
|
||||
|
||||
@@ -14,7 +14,7 @@ ACTION_ARCHIVE_CACHE_DIR=/opt/actionarchivecache
|
||||
mkdir -p $ACTION_ARCHIVE_CACHE_DIR
|
||||
chmod -R 777 $ACTION_ARCHIVE_CACHE_DIR
|
||||
echo "Setting up ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE variable to ${ACTION_ARCHIVE_CACHE_DIR}"
|
||||
addEtcEnvironmentVariable ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE ${ACTION_ARCHIVE_CACHE_DIR}
|
||||
setEtcEnvironmentVariable "ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE" "${ACTION_ARCHIVE_CACHE_DIR}"
|
||||
|
||||
# Download latest release from github.com/actions/action-versions and untar to /opt/actionarchivecache
|
||||
downloadUrl=$(get_github_package_download_url "actions/action-versions" "contains(\"action-versions.tar.gz\")")
|
||||
|
||||
@@ -35,10 +35,10 @@ function get_full_ndk_version {
|
||||
ANDROID_ROOT=/usr/local/lib/android
|
||||
ANDROID_SDK_ROOT=${ANDROID_ROOT}/sdk
|
||||
SDKMANAGER=${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager
|
||||
echo "ANDROID_SDK_ROOT=${ANDROID_SDK_ROOT}" | tee -a /etc/environment
|
||||
setEtcEnvironmentVariable "ANDROID_SDK_ROOT" "${ANDROID_SDK_ROOT}"
|
||||
|
||||
# ANDROID_HOME is deprecated, but older versions of Gradle rely on it
|
||||
echo "ANDROID_HOME=${ANDROID_SDK_ROOT}" | tee -a /etc/environment
|
||||
setEtcEnvironmentVariable "ANDROID_HOME" "${ANDROID_SDK_ROOT}"
|
||||
|
||||
# Create android sdk directory
|
||||
mkdir -p ${ANDROID_SDK_ROOT}
|
||||
@@ -100,10 +100,10 @@ ndkDefaultFullVersion=$(get_full_ndk_version $ANDROID_NDK_MAJOR_DEFAULT)
|
||||
ndkLatestFullVersion=$(get_full_ndk_version $ANDROID_NDK_MAJOR_LATEST)
|
||||
ANDROID_NDK="$ANDROID_SDK_ROOT/ndk/$ndkDefaultFullVersion"
|
||||
# ANDROID_NDK, ANDROID_NDK_HOME, and ANDROID_NDK_ROOT variables should be set as many customer builds depend on them https://github.com/actions/runner-images/issues/5879
|
||||
echo "ANDROID_NDK=${ANDROID_NDK}" | tee -a /etc/environment
|
||||
echo "ANDROID_NDK_HOME=${ANDROID_NDK}" | tee -a /etc/environment
|
||||
echo "ANDROID_NDK_ROOT=${ANDROID_NDK}" | tee -a /etc/environment
|
||||
echo "ANDROID_NDK_LATEST_HOME=$ANDROID_SDK_ROOT/ndk/$ndkLatestFullVersion" | tee -a /etc/environment
|
||||
setEtcEnvironmentVariable "ANDROID_NDK" "${ANDROID_NDK}"
|
||||
setEtcEnvironmentVariable "ANDROID_NDK_HOME" "${ANDROID_NDK}"
|
||||
setEtcEnvironmentVariable "ANDROID_NDK_ROOT" "${ANDROID_NDK}"
|
||||
setEtcEnvironmentVariable "ANDROID_NDK_LATEST_HOME" "${ANDROID_SDK_ROOT}/ndk/${ndkLatestFullVersion}"
|
||||
|
||||
availablePlatforms=($($SDKMANAGER --list | sed -n '/Available Packages:/,/^$/p' | grep "platforms;android-[0-9]" | cut -d"|" -f 1))
|
||||
allBuildTools=($($SDKMANAGER --list | grep "build-tools;" | cut -d"|" -f 1 | sort -u))
|
||||
|
||||
@@ -4,10 +4,13 @@
|
||||
## Desc: Install Azure DevOps CLI (az devops)
|
||||
################################################################################
|
||||
|
||||
# Source the helpers for use with the script
|
||||
source $HELPER_SCRIPTS/etc-environment.sh
|
||||
|
||||
# AZURE_EXTENSION_DIR shell variable defines where modules are installed
|
||||
# https://docs.microsoft.com/en-us/cli/azure/azure-cli-extensions-overview
|
||||
export AZURE_EXTENSION_DIR=/opt/az/azcliextensions
|
||||
echo "AZURE_EXTENSION_DIR=$AZURE_EXTENSION_DIR" | tee -a /etc/environment
|
||||
setEtcEnvironmentVariable "AZURE_EXTENSION_DIR" "${AZURE_EXTENSION_DIR}"
|
||||
|
||||
# install azure devops Cli extension
|
||||
az extension add -n azure-devops
|
||||
|
||||
@@ -5,10 +5,9 @@
|
||||
################################################################################
|
||||
|
||||
# Source the helpers for use with the script
|
||||
# shellcheck source=../helpers/install.sh
|
||||
source "$HELPER_SCRIPTS/install.sh"
|
||||
# shellcheck source=../helpers/os.sh
|
||||
source "$HELPER_SCRIPTS/os.sh"
|
||||
source $HELPER_SCRIPTS/etc-environment.sh
|
||||
|
||||
# Mozillateam PPA is added manually because sometimes
|
||||
# lanuchad portal sends empty answer when trying to add it automatically
|
||||
@@ -45,6 +44,6 @@ tar -xzf /tmp/geckodriver.tar.gz -C $GECKODRIVER_DIR
|
||||
|
||||
chmod +x $GECKODRIVER_BIN
|
||||
ln -s "$GECKODRIVER_BIN" /usr/bin/
|
||||
echo "GECKOWEBDRIVER=$GECKODRIVER_DIR" | tee -a /etc/environment
|
||||
setEtcEnvironmentVariable "GECKOWEBDRIVER" "${GECKODRIVER_DIR}"
|
||||
|
||||
invoke_tests "Browsers" "Firefox"
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
# Source the helpers for use with the script
|
||||
source $HELPER_SCRIPTS/install.sh
|
||||
source $HELPER_SCRIPTS/etc-environment.sh
|
||||
|
||||
function GetChromiumRevision {
|
||||
CHROME_REVISION=$1
|
||||
@@ -36,7 +37,7 @@ CHROME_DEB_URL="https://dl.google.com/linux/direct/google-chrome-stable_current_
|
||||
CHROME_DEB_NAME="google-chrome-stable_current_amd64.deb"
|
||||
download_with_retries $CHROME_DEB_URL "/tmp" "${CHROME_DEB_NAME}"
|
||||
apt install "/tmp/${CHROME_DEB_NAME}" -f
|
||||
echo "CHROME_BIN=/usr/bin/google-chrome" | tee -a /etc/environment
|
||||
setEtcEnvironmentVariable "CHROME_BIN" "/usr/bin/google-chrome"
|
||||
|
||||
# Remove Google Chrome repo
|
||||
rm -f /etc/cron.daily/google-chrome /etc/apt/sources.list.d/google-chrome.list /etc/apt/sources.list.d/google-chrome.list.save
|
||||
@@ -64,7 +65,7 @@ unzip -qq /tmp/$CHROMEDRIVER_ARCHIVE -d /usr/local/share
|
||||
|
||||
chmod +x $CHROMEDRIVER_BIN
|
||||
ln -s "$CHROMEDRIVER_BIN" /usr/bin/
|
||||
echo "CHROMEWEBDRIVER=$CHROMEDRIVER_DIR" | tee -a /etc/environment
|
||||
setEtcEnvironmentVariable "CHROMEWEBDRIVER" "${CHROMEDRIVER_DIR}"
|
||||
|
||||
# Download and unpack Chromium
|
||||
CHROME_REVISION=$(echo "${CHROME_VERSIONS_JSON}" | jq -r '.builds["'"$CHROME_VERSION"'"].revision')
|
||||
|
||||
@@ -16,13 +16,13 @@ createJavaEnvironmentalVariable() {
|
||||
|
||||
if [[ ${DEFAULT} == "True" ]]; then
|
||||
echo "Setting up JAVA_HOME variable to ${INSTALL_PATH_PATTERN}"
|
||||
addEtcEnvironmentVariable JAVA_HOME ${INSTALL_PATH_PATTERN}
|
||||
setEtcEnvironmentVariable "JAVA_HOME" "${INSTALL_PATH_PATTERN}"
|
||||
echo "Setting up default symlink"
|
||||
update-java-alternatives -s ${INSTALL_PATH_PATTERN}
|
||||
fi
|
||||
|
||||
echo "Setting up JAVA_HOME_${JAVA_VERSION}_X64 variable to ${INSTALL_PATH_PATTERN}"
|
||||
addEtcEnvironmentVariable JAVA_HOME_${JAVA_VERSION}_X64 ${INSTALL_PATH_PATTERN}
|
||||
setEtcEnvironmentVariable "JAVA_HOME_${JAVA_VERSION}_X64" "${INSTALL_PATH_PATTERN}"
|
||||
}
|
||||
|
||||
enableRepositories() {
|
||||
@@ -56,7 +56,7 @@ installOpenJDK() {
|
||||
# When version string is too short, add extra ".0" to make it valid semver
|
||||
[[ ${fullJavaVersion} =~ ^[0-9]+- ]] && fullJavaVersion=$(echo $fullJavaVersion | sed -E 's/-/.0-/')
|
||||
[[ ${fullJavaVersion} =~ ^[0-9]+\.[0-9]+- ]] && fullJavaVersion=$(echo $fullJavaVersion | sed -E 's/-/.0-/')
|
||||
|
||||
|
||||
javaToolcacheVersionPath="${JAVA_TOOLCACHE_PATH}/${fullJavaVersion}"
|
||||
echo "Java ${JAVA_VERSION} Toolcache Version Path: ${javaToolcacheVersionPath}"
|
||||
mkdir -p "${javaToolcacheVersionPath}"
|
||||
@@ -93,7 +93,7 @@ done
|
||||
|
||||
# Install Ant
|
||||
apt-get install -y --no-install-recommends ant ant-optional
|
||||
echo "ANT_HOME=/usr/share/ant" | tee -a /etc/environment
|
||||
setEtcEnvironmentVariable "ANT_HOME" "/usr/share/ant"
|
||||
|
||||
# Install Maven
|
||||
mavenVersion=$(get_toolset_value '.java.maven')
|
||||
@@ -113,7 +113,8 @@ echo "gradleVersion=${gradleLatestVersion}"
|
||||
download_with_retries ${gradleDownloadUrl} "/tmp" "gradleLatest.zip"
|
||||
unzip -qq -d /usr/share /tmp/gradleLatest.zip
|
||||
ln -s /usr/share/gradle-"${gradleLatestVersion}"/bin/gradle /usr/bin/gradle
|
||||
echo "GRADLE_HOME=$(find /usr/share -depth -maxdepth 1 -name "gradle*")" | tee -a /etc/environment
|
||||
gradle_home_dir=$(find /usr/share -depth -maxdepth 1 -name "gradle*")
|
||||
setEtcEnvironmentVariable "GRADLE_HOME" "${gradle_home_dir}"
|
||||
|
||||
# Delete java repositories and keys
|
||||
rm -f /etc/apt/sources.list.d/adoptium.list
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
## Desc: Install Leiningen
|
||||
################################################################################
|
||||
|
||||
# Source the helpers for use with the script
|
||||
source $HELPER_SCRIPTS/etc-environment.sh
|
||||
|
||||
LEIN_BIN=/usr/local/bin/lein
|
||||
curl -fsSL https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein > $LEIN_BIN
|
||||
chmod 0755 $LEIN_BIN
|
||||
@@ -13,7 +16,7 @@ export LEIN_HOME=/usr/local/lib/lein
|
||||
lein
|
||||
|
||||
LEIN_JAR=$(find $LEIN_HOME -name "leiningen-*-standalone.jar")
|
||||
echo "LEIN_JAR=$LEIN_JAR" | tee -a /etc/environment
|
||||
echo "LEIN_HOME=$LEIN_HOME" | tee -a /etc/environment
|
||||
setEtcEnvironmentVariable "LEIN_JAR" "${LEIN_JAR}"
|
||||
setEtcEnvironmentVariable "LEIN_HOME" "${LEIN_HOME}"
|
||||
|
||||
invoke_tests "Tools" "Leiningen"
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
## Desc: Install Microsoft Edge and WebDriver
|
||||
################################################################################
|
||||
|
||||
# Source the helpers for use with the script
|
||||
source $HELPER_SCRIPTS/install.sh
|
||||
source $HELPER_SCRIPTS/etc-environment.sh
|
||||
|
||||
REPO_URL="https://packages.microsoft.com/repos/edge"
|
||||
gpg_key="/usr/share/keyrings/microsoft-edge.gpg"
|
||||
@@ -44,6 +46,6 @@ unzip -qq /tmp/edgedriver_linux64.zip -d $EDGEDRIVER_DIR
|
||||
chmod +x $EDGEDRIVER_BIN
|
||||
ln -s $EDGEDRIVER_BIN /usr/bin
|
||||
|
||||
echo "EDGEWEBDRIVER=$EDGEDRIVER_DIR" | tee -a /etc/environment
|
||||
setEtcEnvironmentVariable "EDGEWEBDRIVER" "${EDGEDRIVER_DIR}"
|
||||
|
||||
invoke_tests "Browsers" "Edge"
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
## Desc: Install miniconda
|
||||
################################################################################
|
||||
|
||||
# Source the helpers for use with the script
|
||||
source $HELPER_SCRIPTS/etc-environment.sh
|
||||
|
||||
# Install Miniconda
|
||||
curl -fsSL https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -o miniconda.sh \
|
||||
&& chmod +x miniconda.sh \
|
||||
@@ -11,7 +14,7 @@ curl -fsSL https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
|
||||
&& rm miniconda.sh
|
||||
|
||||
CONDA=/usr/share/miniconda
|
||||
echo "CONDA=$CONDA" | tee -a /etc/environment
|
||||
setEtcEnvironmentVariable "CONDA" "${CONDA}"
|
||||
|
||||
ln -s $CONDA/bin/conda /usr/bin/conda
|
||||
|
||||
|
||||
@@ -4,11 +4,14 @@
|
||||
## Desc: Install Nvm
|
||||
################################################################################
|
||||
|
||||
# Source the helpers for use with the script
|
||||
source $HELPER_SCRIPTS/etc-environment.sh
|
||||
|
||||
export NVM_DIR="/etc/skel/.nvm"
|
||||
mkdir $NVM_DIR
|
||||
VERSION=$(curl -fsSL https://api.github.com/repos/nvm-sh/nvm/releases/latest | jq -r '.tag_name')
|
||||
curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/$VERSION/install.sh | bash
|
||||
echo 'NVM_DIR=$HOME/.nvm' | tee -a /etc/environment
|
||||
setEtcEnvironmentVariable "NVM_DIR" '$HOME/.nvm'
|
||||
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm' | tee -a /etc/skel/.bash_profile
|
||||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
# Source the helpers for use with the script
|
||||
source $HELPER_SCRIPTS/install.sh
|
||||
source $HELPER_SCRIPTS/etc-environment.sh
|
||||
|
||||
# Download Selenium server
|
||||
SELENIUM_MAJOR_VERSION=$(get_toolset_value '.selenium.version')
|
||||
@@ -20,6 +21,6 @@ SELENIUM_FULL_VERSION=$(echo $SELENIUM_DOWNLOAD_URL | awk -F"${SELENIUM_BINARY_N
|
||||
touch "$SELENIUM_JAR_PATH/$SELENIUM_BINARY_NAME-$SELENIUM_FULL_VERSION"
|
||||
|
||||
# Add SELENIUM_JAR_PATH environment variable
|
||||
echo "SELENIUM_JAR_PATH=$SELENIUM_JAR_PATH/$SELENIUM_JAR_NAME" | tee -a /etc/environment
|
||||
setEtcEnvironmentVariable "SELENIUM_JAR_PATH" "${SELENIUM_JAR_PATH}/${SELENIUM_JAR_NAME}"
|
||||
|
||||
invoke_tests "Tools" "Selenium"
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
# Source the helpers for use with the script
|
||||
source $HELPER_SCRIPTS/install.sh
|
||||
source $HELPER_SCRIPTS/etc-environment.sh
|
||||
|
||||
# Install
|
||||
image_label="$(lsb_release -rs)"
|
||||
@@ -41,6 +42,6 @@ ln -s "$SWIFT_BIN_ROOT/swift" /usr/local/bin/swift
|
||||
ln -s "$SWIFT_BIN_ROOT/swiftc" /usr/local/bin/swiftc
|
||||
ln -s "$SWIFT_LIB_ROOT/libsourcekitdInProc.so" /usr/local/lib/libsourcekitdInProc.so
|
||||
|
||||
echo "SWIFT_PATH=$SWIFT_BIN_ROOT" | tee -a /etc/environment
|
||||
setEtcEnvironmentVariable "SWIFT_PATH" "${SWIFT_BIN_ROOT}"
|
||||
|
||||
invoke_tests "Common" "Swift"
|
||||
|
||||
@@ -4,9 +4,12 @@
|
||||
## Desc: Install vcpkg
|
||||
################################################################################
|
||||
|
||||
# Source the helpers for use with the script
|
||||
source $HELPER_SCRIPTS/etc-environment.sh
|
||||
|
||||
# Set env variable for vcpkg
|
||||
VCPKG_INSTALLATION_ROOT=/usr/local/share/vcpkg
|
||||
echo "VCPKG_INSTALLATION_ROOT=${VCPKG_INSTALLATION_ROOT}" | tee -a /etc/environment
|
||||
setEtcEnvironmentVariable "VCPKG_INSTALLATION_ROOT" "${VCPKG_INSTALLATION_ROOT}"
|
||||
|
||||
# Install vcpkg
|
||||
git clone https://github.com/Microsoft/vcpkg $VCPKG_INSTALLATION_ROOT
|
||||
|
||||
@@ -8,20 +8,21 @@
|
||||
# values containg slashes (i.e. directory path)
|
||||
# The values containing '%' will break the functions
|
||||
|
||||
function getEtcEnvironmentVariable {
|
||||
getEtcEnvironmentVariable () {
|
||||
variable_name="$1"
|
||||
|
||||
# remove `variable_name=` and possible quotes from the line
|
||||
grep "^${variable_name}=" /etc/environment |sed -E "s%^${variable_name}=\"?([^\"]+)\"?.*$%\1%"
|
||||
grep "^${variable_name}=" /etc/environment | sed -E "s%^${variable_name}=\"?([^\"]+)\"?.*$%\1%"
|
||||
}
|
||||
|
||||
function addEtcEnvironmentVariable {
|
||||
addEtcEnvironmentVariable () {
|
||||
variable_name="$1"
|
||||
variable_value="$2"
|
||||
|
||||
echo "$variable_name=$variable_value" | sudo tee -a /etc/environment
|
||||
echo "${variable_name}=${variable_value}" | sudo tee -a /etc/environment
|
||||
}
|
||||
|
||||
function replaceEtcEnvironmentVariable {
|
||||
replaceEtcEnvironmentVariable () {
|
||||
variable_name="$1"
|
||||
variable_value="$2"
|
||||
|
||||
@@ -29,40 +30,45 @@ function replaceEtcEnvironmentVariable {
|
||||
sudo sed -i -e "s%^${variable_name}=.*$%${variable_name}=\"${variable_value}\"%" /etc/environment
|
||||
}
|
||||
|
||||
function setEtcEnvironmentVariable {
|
||||
setEtcEnvironmentVariable () {
|
||||
variable_name="$1"
|
||||
variable_value="$2"
|
||||
|
||||
if grep "$variable_name" /etc/environment > /dev/null; then
|
||||
if grep "^${variable_name}=" /etc/environment > /dev/null
|
||||
then
|
||||
replaceEtcEnvironmentVariable $variable_name $variable_value
|
||||
else
|
||||
addEtcEnvironmentVariable $variable_name $variable_value
|
||||
fi
|
||||
}
|
||||
|
||||
function prependEtcEnvironmentVariable {
|
||||
prependEtcEnvironmentVariable () {
|
||||
variable_name="$1"
|
||||
element="$2"
|
||||
|
||||
# TODO: handle the case if the variable does not exist
|
||||
existing_value=$(getEtcEnvironmentVariable "${variable_name}")
|
||||
setEtcEnvironmentVariable "${variable_name}" "${element}:${existing_value}"
|
||||
}
|
||||
|
||||
function appendEtcEnvironmentVariable {
|
||||
appendEtcEnvironmentVariable () {
|
||||
variable_name="$1"
|
||||
element="$2"
|
||||
|
||||
# TODO: handle the case if the variable does not exist
|
||||
existing_value=$(getEtcEnvironmentVariable "${variable_name}")
|
||||
setEtcEnvironmentVariable "${variable_name}" "${existing_value}:${element}"
|
||||
}
|
||||
|
||||
function prependEtcEnvironmentPath {
|
||||
prependEtcEnvironmentPath () {
|
||||
element="$1"
|
||||
|
||||
prependEtcEnvironmentVariable PATH "${element}"
|
||||
}
|
||||
|
||||
function appendEtcEnvironmentPath {
|
||||
appendEtcEnvironmentPath () {
|
||||
element="$1"
|
||||
|
||||
appendEtcEnvironmentVariable PATH "${element}"
|
||||
}
|
||||
|
||||
@@ -75,11 +81,10 @@ function appendEtcEnvironmentPath {
|
||||
# TODO: there might be the others variables to be processed in the same way as "PATH" variable
|
||||
# ie MANPATH, INFOPATH, LD_*, etc. In the current implementation the values from /etc/evironments
|
||||
# replace the values of the current environment
|
||||
function reloadEtcEnvironment {
|
||||
reloadEtcEnvironment () {
|
||||
# add `export ` to every variable of /etc/environemnt except PATH and eval the result shell script
|
||||
eval $(grep -v '^PATH=' /etc/environment | sed -e 's%^%export %')
|
||||
# handle PATH specially
|
||||
etc_path=$(getEtcEnvironmentVariable PATH)
|
||||
export PATH="$PATH:$etc_path"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user