Introduce kickstart.stream.contains and kickstart.file.contains
The kickstart.stream.contains and kickstart.file.contains wraps the code for checking for a string.
This commit is contained in:
		
							
								
								
									
										11
									
								
								docs/kickstart/file/contains.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								docs/kickstart/file/contains.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
# kickstart.file.contains file_name string_to_search
 | 
			
		||||
Searchs for `string_to_search` on `file_name`.
 | 
			
		||||
Returns 0 if there the file contains the string, and 1 otherwise.
 | 
			
		||||
 | 
			
		||||
### Example
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
$ kickstart.file.contains /etc/groups wheel && echo yup
 | 
			
		||||
$ kickstart.file.contains /etc/groups banana || echo nope
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										11
									
								
								docs/kickstart/stream/contains.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								docs/kickstart/stream/contains.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
# kickstart.stream.contains string_to_search
 | 
			
		||||
Searchs for `string_to_search` on STDIN
 | 
			
		||||
Returns 0 if there the stream contains the string, and 1 otherwise.
 | 
			
		||||
 | 
			
		||||
### Example
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
$ echo weee | kickstart.stream.contains wee && echo yup
 | 
			
		||||
$ echo weee | kickstart.stream.contains ahh || echo nope
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
@@ -2,3 +2,7 @@ kickstart.file.link() {
 | 
			
		||||
  rm -rf $2 2>/dev/null
 | 
			
		||||
  ln -s $1 $2
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
kickstart.file.contains() {
 | 
			
		||||
  grep -q $2 $1 2>/dev/null
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
kickstart.group.create() {
 | 
			
		||||
  kickstart.info "Creating group $1"
 | 
			
		||||
  grep -q $1 /etc/group || groupadd $1
 | 
			
		||||
  kickstart.file.contains /etc/group $1 || groupadd $1
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,7 @@ kickstart.module.apply_recipe() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
kickstart.module.apply_() {
 | 
			
		||||
  local cur_dir=`pwd`;
 | 
			
		||||
  local cur_dir=`pwd`
 | 
			
		||||
  cd modules/$1
 | 
			
		||||
  source $3/$2.sh
 | 
			
		||||
  cd $cur_dir
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
kickstart.os() {
 | 
			
		||||
  ( uname -a | grep -q Ubuntu ) && echo "Ubuntu"
 | 
			
		||||
  ( uname -a | grep -q Darwin ) && echo "Mac"
 | 
			
		||||
  uname -a | kickstart.stream.contains Ubuntu && echo "Ubuntu"
 | 
			
		||||
  uname -a | kickstart.stream.contains Darwin && echo "Mac"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
kickstart.os.is() {
 | 
			
		||||
 
 | 
			
		||||
@@ -6,8 +6,8 @@ kickstart.package.manager() {
 | 
			
		||||
 | 
			
		||||
kickstart.package.installed() {
 | 
			
		||||
  local pkg_manager=`kickstart.package.manager`
 | 
			
		||||
  [ $pkg_manager = 'apt-get' ] && dpkg -s $@ >/dev/null 2>&1 && return $?
 | 
			
		||||
  [ $pkg_manager = 'brew' ] && ! $(brew info $@ | grep -q "Not installed") && return $?
 | 
			
		||||
  [ $pkg_manager = 'apt-get' ] && dpkg -s "$@" >/dev/null 2>&1 && return $?
 | 
			
		||||
  [ $pkg_manager = 'brew' ] && ! $(brew info "$@" | kickstart.stream.contains "Not installed") && return $?
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
kickstart.package.install() {
 | 
			
		||||
 
 | 
			
		||||
@@ -15,7 +15,7 @@ kickstart.profile.source_on_configuration_file() {
 | 
			
		||||
  local file=$1
 | 
			
		||||
  local profile_d=$2
 | 
			
		||||
  local configuration=$3
 | 
			
		||||
  grep -q $file $configuration 2>/dev/null || ( echo "[[ -f $profile_d/$file ]] && source $profile_d/$file" >> $configuration )
 | 
			
		||||
  kickstart.file.contains $configuration $file || ( echo "[[ -f $profile_d/$file ]] && source $profile_d/$file" >> $configuration )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
kickstart.profile.location.profile_d() {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										3
									
								
								kickstart/recipes/kickstart/stream.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								kickstart/recipes/kickstart/stream.sh
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
kickstart.stream.contains() {
 | 
			
		||||
  grep -q $1 2>/dev/null
 | 
			
		||||
}
 | 
			
		||||
@@ -3,7 +3,7 @@ kickstart.user.create() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
kickstart.user.is_on_group() {
 | 
			
		||||
  grep -q $2 <(id -nG $1)
 | 
			
		||||
  id -nG $1 | kickstart.stream.contains $2
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
kickstart.user.add_group() {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user