@@ -21,6 +21,8 @@ export DEBIAN_FRONTEND=noninteractive
2121
2222ADJUSTED_ID=" None"
2323
24+ NON_ROOT_USER=$( logname 2> /dev/null || echo " nobody" )
25+
2426# ##################################################################################################
2527# Functions
2628# ##################################################################################################
@@ -217,6 +219,24 @@ update_brew() {
217219 brew doctor && brew missing
218220}
219221
222+ # Function: update_vscode_ext
223+ # Description: Updates Visual Studio Code extensions if `VSCode` is installed.
224+ update_vscode_ext () {
225+ println " Updating VSCode Extensions"
226+
227+ if ! check_command code; then
228+ return
229+ fi
230+
231+ # Ensure `NON_ROOT_USER` is defined and valid
232+ if [ -z " ${NON_ROOT_USER} " ] || ! id " ${NON_ROOT_USER} " > /dev/null 2>&1 ; then
233+ print_err " Error: Non-root user '${NON_ROOT_USER} ' is invalid or not found."
234+ return
235+ fi
236+
237+ su - " ${NON_ROOT_USER} " -c " code --update-extensions"
238+ }
239+
220240# Function: update_gem
221241# Description: Updates RubyGems if the 'gem' command is installed.
222242update_gem () {
348368
349369# Check if the script is running as root
350370if [ " $( id -u) " -ne 0 ]; then
351- print_err " Error: Script must be run as root. Use sudo, su, or add " USER root" to your Dockerfile before running this script.."
371+ print_err " Error: Script must be run as root. Use sudo, su, or add " USER root" to your Dockerfile before running this script... "
352372 exit 1
353373fi
354374
@@ -414,6 +434,7 @@ if check_internet; then
414434 clean_up
415435 update_os_pkg
416436 update_brew
437+ update_vscode_ext
417438 update_gem
418439 update_npm
419440 update_yarn
0 commit comments