ec2_post_init
Populate STScI EC2 instances with ease
system.inc.sh File Reference

System functions. More...

Go to the source code of this file.

Functions

 sys_check_admin ()
 Determine if the current user is root. More...
 
 sys_user_push (name)
 Lazily "become" another user. More...
 
 sys_user_pop ()
 Restore caller environment after sys_user_push() More...
 
 sys_platform ()
 Get system platform (Linux, Darwin, etc) More...
 
 sys_arch ()
 Get system architecture (i386, x86_64, etc) More...
 
 sys_user_home (user)
 Get account home directory. More...
 
 sys_reset_home_ownership (user)
 Resets ownership of a user (after sys_user_push()/sys_user_pop()) More...
 
 sys_pkg_get_manager ()
 Get the system package manager. More...
 
 sys_pkg_install (...)
 Install a system package. More...
 
 sys_pkg_update_all ()
 Update all system packages. More...
 
 sys_pkg_installed (name)
 Test if a system package is installed. More...
 
 sys_pkg_clean ()
 Clean the system package manager's cache(s) More...
 
 sys_initialize ()
 Install dependencies required by ec2_post_init More...
 

Variables

Exported String HAVE_DNF = 0
 System uses DNF package manager. More...
 
Exported String HAVE_YUM = 0
 System uses YUM package manager. More...
 
Exported String HAVE_APT = 0
 System uses APT package manager. More...
 
Exported String HAVE_REDHAT = 0
 System is based on Red Hat. More...
 
Exported String HAVE_DEBIAN = 0
 System is based on Debian. More...
 
Exported String HAVE_UBUNTU = 0
 System is based on Ubuntu. More...
 
Exported String HAVE_ARCH = 0
 System is based on Arch. More...
 
Exported String HAVE_SUPPORT = 1
 System is supported. More...
 
Exported String USER = $name
 
Exported String _sys_user_home_old = ''
 
Exported String _sys_user_old = ''
 

Detailed Description

System functions.

Definition in file system.inc.sh.

Function Documentation

◆ sys_arch()

sys_arch ( )

Get system architecture (i386, x86_64, etc)

Return values
architecturestring

Definition at line 93 of file system.inc.sh.

◆ sys_check_admin()

sys_check_admin ( )

Determine if the current user is root.

Return values
trueif root
1if not root

Definition at line 39 of file system.inc.sh.

◆ sys_initialize()

sys_initialize ( )

Install dependencies required by ec2_post_init

Return values
exit_codevalue of sys_pkg_install()
if ! sys_pkg_initialize; then
io_error "Initialization failed!"
else
io_info "Initialization succeeded!"
fi
io_info(...)
Print a message.
Definition: io.inc.sh:29
io_error(...)
Print an error message.
Definition: io.inc.sh:59

Definition at line 325 of file system.inc.sh.

◆ sys_pkg_clean()

sys_pkg_clean ( )

Clean the system package manager's cache(s)

Definition at line 305 of file system.inc.sh.

◆ sys_pkg_get_manager()

sys_pkg_get_manager ( )

Get the system package manager.

Return values
resultthe path to the package manager

Definition at line 148 of file system.inc.sh.

◆ sys_pkg_install()

sys_pkg_install (   ...)

Install a system package.

Parameters
...a variable length list of packages to install
Return values
1if not supported
exit_codeof system package manager
# Install vim and nano
if (( $HAVE_REDHAT )); then
elif (( $HAVE_DEBIAN )); then
sys_pkg_install vim-common
fi
# Alternative method using an array to dynamically set dependencies
deps=(nano)
(( $HAVE_REDHAT )) && deps+=(vim)
(( $HAVE_DEBIAN )) && deps+=(vim-common)
sys_pkg_install "${deps[@]}"
sys_pkg_install(...)
Install a system package.
Definition: system.inc.sh:244

Definition at line 244 of file system.inc.sh.

◆ sys_pkg_installed()

sys_pkg_installed ( name  )

Test if a system package is installed.

Parameters
nameof a system package
Return values
1if not supported
1if package is NOT installed
0if package is installed

Definition at line 276 of file system.inc.sh.

◆ sys_pkg_update_all()

sys_pkg_update_all ( )

Update all system packages.

Return values
1if not supported
exit_codeof system package manager

Definition at line 261 of file system.inc.sh.

◆ sys_platform()

sys_platform ( )

Get system platform (Linux, Darwin, etc)

Return values
platformstring

Definition at line 80 of file system.inc.sh.

◆ sys_reset_home_ownership()

sys_reset_home_ownership ( user  )

Resets ownership of a user (after sys_user_push()/sys_user_pop())

Parameters
useraccount to modify

Definition at line 126 of file system.inc.sh.

◆ sys_user_home()

sys_user_home ( user  )

Get account home directory.

This function returns the home directory defined in /etc/passwd unless name is the caller's account; in which case it will use the value of $HOME.

Parameters
useraccount to inspect
Return values
homedirectory path

Definition at line 108 of file system.inc.sh.

◆ sys_user_pop()

sys_user_pop ( )

Restore caller environment after sys_user_push()

Definition at line 69 of file system.inc.sh.

◆ sys_user_push()

sys_user_push ( name  )

Lazily "become" another user.

This sidesteps sudo's environment limitations allowing one to execute scripts on behalf of the named user. Anything modified while sys_user_push() is active will need to have its ownership and/or octal permissions normalized. If name does not exist it will be created.

Parameters
namethe user to become

Definition at line 53 of file system.inc.sh.

Variable Documentation

◆ _sys_user_home_old

Exported String _sys_user_home_old = ''

Definition at line 72 of file system.inc.sh.

◆ _sys_user_old

Exported String _sys_user_old = ''

Definition at line 73 of file system.inc.sh.

◆ HAVE_APT

Exported String HAVE_APT = 0

System uses APT package manager.

Definition at line 18 of file system.inc.sh.

◆ HAVE_ARCH

Exported String HAVE_ARCH = 0

System is based on Arch.

Definition at line 30 of file system.inc.sh.

◆ HAVE_DEBIAN

Exported String HAVE_DEBIAN = 0

System is based on Debian.

Definition at line 24 of file system.inc.sh.

◆ HAVE_DNF

Exported String HAVE_DNF = 0

System uses DNF package manager.

Definition at line 12 of file system.inc.sh.

◆ HAVE_REDHAT

Exported String HAVE_REDHAT = 0

System is based on Red Hat.

Definition at line 21 of file system.inc.sh.

◆ HAVE_SUPPORT

Exported String HAVE_SUPPORT = 1

System is supported.

Definition at line 33 of file system.inc.sh.

◆ HAVE_UBUNTU

Exported String HAVE_UBUNTU = 0

System is based on Ubuntu.

Definition at line 27 of file system.inc.sh.

◆ HAVE_YUM

Exported String HAVE_YUM = 0

System uses YUM package manager.

Definition at line 15 of file system.inc.sh.

◆ USER

Exported String USER = $name

Definition at line 63 of file system.inc.sh.