Last active
March 12, 2019 12:01
-
-
Save sid226/604921514a5335d0cb12547b236b4fd6 to your computer and use it in GitHub Desktop.
final_s390x.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Need handling for RHEL 6.10 as it doesn't have os-release file | |
if [ -f "/etc/os-release" ]; then | |
source "/etc/os-release" | |
else | |
cat /etc/redhat-release >>"${LOG_FILE}" | |
export ID="rhel" | |
export VERSION_ID="6.x" | |
export PRETTY_NAME="Red Hat Enterprise Linux 6.x" | |
fi | |
DISTRO="$ID-$VERSION_ID" | |
VERSION="$ID" | |
CURDIR="$(pwd)" | |
#Check if directory exists | |
if [ ! -d "$CURDIR/logs/" ]; then | |
mkdir -p "$CURDIR/logs/" | |
fi | |
PACKAGE_LIST="$CURDIR/logs/${DISTRO}-$(date +"%F-%T").list" | |
DATA_FILE="$CURDIR/logs/${DISTRO}-$(date +"%F-%T").json" | |
case "$VERSION" in | |
"ubuntu") | |
# Commands for UBUNTU | |
printf -- " Get package data for %s \n" "$DISTRO" | |
apt update && apt install sudo vim | |
#Update repo for Docker | |
sudo apt-get update | |
sudo apt-get install -y \ | |
apt-transport-https \ | |
ca-certificates \ | |
curl \ | |
gnupg-agent \ | |
software-properties-common | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - | |
printf -- " Adding docker repo for s390x.\n" | |
sudo add-apt-repository \ | |
"deb [arch=s390x] https://download.docker.com/linux/ubuntu \ | |
$(lsb_release -cs) \ | |
stable" | |
apt update | |
apt list > aptlist.txt | |
sed '1,1d' aptlist.txt > "${DISTRO}"_temp.txt | |
awk '{printf("{\"packageName\":\"%s\", \"version\":\"%s\"},\n",$1,$2)}' "${DISTRO}"_temp.txt | sed -e '1s/^/[/' -e '$s/$/\]/' | sed '$ s/\,]/]/g' > Ubuntu_${VERSION_ID}_Package_List.json | |
;; | |
"rhel") | |
# Commands for RHEL | |
printf -- " Generate package data for %s \n" "$DISTRO" | |
/opt/ibm-yum.sh info | grep -e "^Name :" -e "^Version :" | sed 's/Name : /"packageName" : "/g' | sed 's/Version : /"version" : "/g' | sed '/^\"packageName\" :/{N;s/\n/", /;}' | sed 's/$/\"},/g' | sed 's/^/{/g' | LC_ALL=C sort | uniq | sed '1s/^/[/' | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' | sed -e '$s/,$/]/' > RHEL_${VERSION_ID}_Package_List.json | |
;; | |
"sles") | |
# Commands for SLES | |
printf -- " Get package data for %s \n" "$DISTRO" | |
zypper refresh -s | |
zypper pa -u > one_un.txt | |
zypper pa -i > one_in.txt | |
awk '{$1=$2=$3=$4=$6=$8=$9=""; print $0}' one_in.txt > temp_in.txt | |
awk '{$1=$2=$3=$5=$7=$8=""; print $0}' one_un.txt > temp_un.txt | |
awk '{printf("{\"packageName\":\"%s\", \"version\":\"%s\"},\n",$1,$2)}' temp_in.txt | sed -e '1s/^/[/' -e '$s/$/\]/' > temp_in2.txt | |
awk '{printf("{\"packageName\":\"%s\", \"version\":\"%s\"},\n",$1,$2)}' temp_un.txt | sed -e '1s/^/[/' -e '$s/$/\]/' > temp_un2.txt | |
sed '1,6d' temp_in2.txt | sed '1s/^/[/' | sed '$ s/\,]/,/g' > final_in.txt | |
sed '1,6d' temp_un2.txt | sed '$ s/\,]/]/g' > final_un.txt | |
cat final_in.txt final_un.txt > Suse_Linux_Enterprise_Server_${VERSION_ID}_Package_List.json | |
;; | |
"alpine") | |
# Commands for Alpine | |
printf -- " Get package data for %s \n" "$DISTRO" | |
apk update && apk search -a | sed 's/\(-[0-9]\)/ \1/g' | sed 's/ -/ \1/g' | sed '1 i\\n' | sed '1,1d' > "${DISTRO}"_packagelist.txt | |
awk -F ' ' 'BEGIN {printf("[")} NR > 1 {printf("{\"packageName\":\"%s\", \"version\":\"%s\"},\n",$1,$2)}' "${DISTRO}"_packagelist.txt | sed -e '$s/$/\]/' | sed '$ s/\,]/]/g' > Alpine_${VERSION_ID}_Package_List.json | |
;; | |
"fedora") | |
# Commands for fedora | |
printf -- " Get package data for %s \n" "$DISTRO" | |
dnf list > "${DISTRO}"_packagelist.txt; | |
awk 'BEGIN {printf("[")} NF==3 { printf("{\"packageName\":\"%s\",\"version\":\"%s\"},",$1,$2)} END {printf("]")}' "${DISTRO}"_packagelist.txt | sed 's/,]$/]/' | sed 's/},/},\n/g' > Fedora_${VERSION_ID}_Package_List.json | |
;; | |
"debian") | |
# Commands for debian | |
printf -- " Get package data for %s \n" "$DISTRO" | |
apt-get update && apt list > aptlist.txt | |
sed '1,1d' aptlist.txt > "${DISTRO}"_temp.txt | |
awk '{$3=""; print $0}' "${DISTRO}"_temp.txt > "${DISTRO}"_temp2.txt | |
awk '{printf("{\"packageName\":\"%s\", \"version\":\"%s\"},\n",$1,$2)}' "${DISTRO}"_temp2.txt > "${DISTRO}"_temp3.txt | |
sed -e '1s/^/[/' -e '$s/$/\]/' "${DISTRO}"_temp3.txt > "${DISTRO}"_temp4.txt | |
sed '$ s/\,]/]/g' "${DISTRO}"_temp4.txt > Debian_${VERSION_ID}_Package_List.json | |
;; | |
*) | |
printf -- "%s not supported \n" "$DISTRO" | tee -a "$LOG_FILE" | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment