Refactor __package_update_index explorers
* add an type explorer to unify detecting of package type. * update currage use the type explorer, so if os and passed in type does not match, it behaves correctly.
This commit is contained in:
		
					parent
					
						
							
								2f89d8a514
							
						
					
				
			
			
				commit
				
					
						b12c02138d
					
				
			
		
					 3 changed files with 39 additions and 21 deletions
				
			
		| 
						 | 
					@ -17,17 +17,17 @@
 | 
				
			||||||
# You should have received a copy of the GNU General Public License
 | 
					# You should have received a copy of the GNU General Public License
 | 
				
			||||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
 | 
					# along with cdist. If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
os="$("$__explorer/os")"
 | 
					type="$($__type_explorer/type)"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
case "$os" in
 | 
					case "$type" in
 | 
				
			||||||
    debian|ubuntu|devuan)
 | 
					    apt)
 | 
				
			||||||
        if [ -f "/var/cache/apt/pkgcache.bin" ]; then
 | 
					        if [ -f "/var/cache/apt/pkgcache.bin" ]; then
 | 
				
			||||||
            echo $(($(date +"%s")-$(stat --format '%Y' /var/cache/apt/pkgcache.bin)))
 | 
					            echo $(($(date +"%s")-$(stat --format '%Y' /var/cache/apt/pkgcache.bin)))
 | 
				
			||||||
        else
 | 
					        else
 | 
				
			||||||
            echo 0
 | 
					            echo 0
 | 
				
			||||||
        fi
 | 
					        fi
 | 
				
			||||||
        ;;
 | 
					        ;;
 | 
				
			||||||
    *)  echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2
 | 
					    *)  echo "Your specified type ($type) is currently not supported." >&2
 | 
				
			||||||
        echo "Please contribute an implementation for it if you can." >&2
 | 
					        echo "Please contribute an implementation for it if you can." >&2
 | 
				
			||||||
        ;;
 | 
					        ;;
 | 
				
			||||||
esac
 | 
					esac
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										34
									
								
								cdist/conf/type/__package_update_index/explorer/type
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								cdist/conf/type/__package_update_index/explorer/type
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,34 @@
 | 
				
			||||||
 | 
					#!/bin/sh
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# 2018 Stu Zhao (z12y12l12 at gmail.com)
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# This file is part of cdist.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# cdist is free software: you can redistribute it and/or modify
 | 
				
			||||||
 | 
					# it under the terms of the GNU General Public License as published by
 | 
				
			||||||
 | 
					# the Free Software Foundation, either version 3 of the License, or
 | 
				
			||||||
 | 
					# (at your option) any later version.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# cdist is distributed in the hope that it will be useful,
 | 
				
			||||||
 | 
					# but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
				
			||||||
 | 
					# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
				
			||||||
 | 
					# GNU General Public License for more details.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# You should have received a copy of the GNU General Public License
 | 
				
			||||||
 | 
					# along with cdist. If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [ -f "$__object/parameter/type" ]; then
 | 
				
			||||||
 | 
					    cat "$__object/parameter/type"
 | 
				
			||||||
 | 
					else
 | 
				
			||||||
 | 
					    # By default determine package manager based on operating system
 | 
				
			||||||
 | 
					    os="$($__explorer/os)"
 | 
				
			||||||
 | 
					    case "$os" in
 | 
				
			||||||
 | 
					        amazon|scientific|centos|fedora|redhat) echo "yum" ;;
 | 
				
			||||||
 | 
					        debian|ubuntu|devuan) echo "apt" ;;
 | 
				
			||||||
 | 
					        archlinux) echo "pacman" ;;
 | 
				
			||||||
 | 
					        *)
 | 
				
			||||||
 | 
					            echo "Don't know how to manage packages on: $os" >&2
 | 
				
			||||||
 | 
					            exit 1
 | 
				
			||||||
 | 
					            ;;
 | 
				
			||||||
 | 
					    esac
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
| 
						 | 
					@ -21,28 +21,12 @@
 | 
				
			||||||
# Update the package index with the appropriate package manager
 | 
					# Update the package index with the appropriate package manager
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type="$__object/parameter/type"
 | 
					type=$(cat "$__object/explorer/type")
 | 
				
			||||||
if [ -f "$__object/parameter/maxage" ]; then
 | 
					if [ -f "$__object/parameter/maxage" ]; then
 | 
				
			||||||
    maxage="$(cat "$__object/parameter/maxage")"
 | 
					    maxage="$(cat "$__object/parameter/maxage")"
 | 
				
			||||||
    currage="$(cat "$__object/explorer/currage")"
 | 
					    currage="$(cat "$__object/explorer/currage")"
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [ -f "$type" ]; then
 | 
					 | 
				
			||||||
    type="$(cat "$type")"
 | 
					 | 
				
			||||||
else
 | 
					 | 
				
			||||||
    # By default determine package manager based on operating system
 | 
					 | 
				
			||||||
    os="$(cat "$__global/explorer/os")"
 | 
					 | 
				
			||||||
    case "$os" in
 | 
					 | 
				
			||||||
        amazon|scientific|centos|fedora|redhat) type="yum" ;;
 | 
					 | 
				
			||||||
        debian|ubuntu|devuan) type="apt" ;;
 | 
					 | 
				
			||||||
        archlinux) type="pacman" ;;
 | 
					 | 
				
			||||||
        *)
 | 
					 | 
				
			||||||
            echo "Don't know how to manage packages on: $os" >&2
 | 
					 | 
				
			||||||
            exit 1
 | 
					 | 
				
			||||||
            ;;
 | 
					 | 
				
			||||||
    esac
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if [ -n "$maxage" ] && [ "$type" != "apt" ]; then
 | 
					if [ -n "$maxage" ] && [ "$type" != "apt" ]; then
 | 
				
			||||||
    echo "ERROR: \"--maxage\" only supported for \"apt\" pkg-manager." >&2
 | 
					    echo "ERROR: \"--maxage\" only supported for \"apt\" pkg-manager." >&2
 | 
				
			||||||
    exit 1
 | 
					    exit 1
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue