#!/bin/bash

SCRIPT_NAME=${0##*/}
CFG_CMDS="help version"
CFG_BUILD_TIME=${CFG_BUILD_TIME:-`date +%Y%m%d%H%M%S`}
CFG_PKG_DATE="${CFG_BUILD_TIME:0:4}-${CFG_BUILD_TIME:4:2}-${CFG_BUILD_TIME:6:2}T${CFG_BUILD_TIME:8:2}:${CFG_BUILD_TIME:10:2}:${CFG_BUILD_TIME:12:2}"

CFG_PKG_INFO="version=1.0.0
release_date=$CFG_PKG_DATE
package_type=SERVICE_TOOL
compatibility_level=1"

usage () {
  help
  exit $1
}

version_help() {
    cat <<EOF

SYNOPSIS
  Report metadata information about the package:
    $SCRIPT_NAME --version

DESCRIPTION

  Report version and other metadata information about the package.
  For example package_type, version, release_date, etc.

EOF
}

version() {
  echo "$CFG_PKG_INFO"
}

help_help() {
  cat <<EOF

  usage: $SCRIPT_NAME [--help [<command>]]
  Valid commands are: $CFG_CMDS
  type:
    Internal
  description:
    shows the list of available commands and other options, or more
    detailed help for a single command
  example:
    help
    help version
EOF
}

help() {
cat <<EOF

$SCRIPT_NAME

    Operations:
        --version
        --help

    Additional Usage and Individual Command Help:
        --help <operation name>
EOF
}

if [ $1 = "--version" ];
then
    version
elif [ $1 = "--help" ]; then
    if [[ ! -z "$2" ]]; then
        for cmd in $CFG_CMDS; do
        if [ "$cmd" = "${2##--}" ]; then
            eval "${cmd}_help"
            exit 0
        fi
        done

        echo "ERROR: Unknown command." >&2
        usage 1
    else
        help
    fi
else
    echo "ERROR: Unknown command." >&2
    usage 1
fi

exit 0

#----- start rpm boundary -----#
í«îÛ    svc_sanitize_mfg_content-1.0.0-trident_service_tool_expires_10.06                   Ž­è         ´   >     ¤                       )     è      l     ì      p     ï      €     ð      „   89ecdf58e0a2bc057742b0340248feb24e914029 33202a1f7f2a0ec350f7425d6468f349f2ea7478c3a43707890dca4df780faa9     Ü6Î
HËÙY�³r±   |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   >   ÿÿÿ�       Ž­è       '  è   ?     Ø      d            è           é           ê      !     ì   	   I     í   	   Œ     î      ü     ï           ñ           ó     $     ö     -     ÷     9     ø   	  O     ý     e     þ     k           r          û          	J          	„          	           
     (     
:     =     
A     >     
I     @     
Q     F     
Y     X     
„     Y     
Œ     b     
è     d     Z     e     _     f     b     l     d     z     v     “     ˆ     Æ     Œ     ä     ’     å     Ô   C svc_sanitize_mfg_content 1.0.0 trident_service_tool_expires_10.06.2028 svc_sanitize_mfg_content tool for cleaning up mfg specific content This utility is for sanitizing the manufacturing-specific content, which resides on the secondary m2/namespace  jÅp]drm-balin30.xiodrm.lab.emc.com      DELL EMC Proprietary https://www.suse.com/ DELL_EMC/servicetools linux x86_64 
########################################
# Do all the work in this .*spec file.
# Both nodes need this sanitization.
########################################

CSU=/var/lib/coreos-install/utility/cyc_setup_utility
CYC_ENV_FILE=cyc_environment
LOCAL_DIR=/var/tmp
LOCAL_FILE="${LOCAL_DIR}/${CYC_ENV_FILE}"
SSH_CMD="ssh -o StrictHostKeyChecking=no -p22 core@localhost"

###########################################################
# Step 1: Fetch cyc_environment from the secondary m2
###########################################################
echo "Fetching ${CYC_ENV_FILE} from recovery partition..."
$SSH_CMD "sudo ${CSU} --get_file ${CYC_ENV_FILE} ${LOCAL_DIR}"
if [[ $? -ne 0 ]]; then
  echo "ERROR: Failed to fetch ${CYC_ENV_FILE} from recovery partition" >&2
  exit 1
fi

if [[ $($SSH_CMD "stat -c %n \"$LOCAL_FILE\"") == "" ]]; then
  echo "ERROR: ${LOCAL_FILE} is empty after fetch" >&2
  exit 1
fi

###########################################################
# Step 2: Modify cyc_environment
###########################################################

# Delete the entire CYC_MFGARGS line
# Remove MFG_AUTOINSTALL (with optional =value) from the CYC_ARGS comma list
$SSH_CMD /bin/bash <<'REMOTE_SED'
sudo sed -Ei '/^CYC_MFGARGS=/d' /var/tmp/cyc_environment
sudo sed -Ei '/^CYC_ARGS=/{
  s/,MFG_AUTOINSTALL(=[^,]*)?//g
  s/MFG_AUTOINSTALL(=[^,]*)?,//g
  s/=MFG_AUTOINSTALL(=[^,]*)?$//
}' /var/tmp/cyc_environment
REMOTE_SED

echo "Modified ${CYC_ENV_FILE} contents:"

###########################################################
# Step 3: Write the modified file back to the secondary m2
###########################################################
echo "Writing ${CYC_ENV_FILE} back to recovery partition..."
$SSH_CMD "sudo ${CSU} --write_file ${LOCAL_FILE} ."
if [[ $? -ne 0 ]]; then
  echo "ERROR: Failed to write ${CYC_ENV_FILE} back to recovery partition" >&2
  exit 1
fi

echo "Successfully sanitized ${CYC_ENV_FILE}" svc_sanitize_mfg_content-1.0.0-trident_service_tool_expires_10.06.2028.src.rpm svc_sanitize_mfg_content svc_sanitize_mfg_content(x86-64)            
  
  
  
/bin/sh /bin/sh /bin/sh rpmlib(CompressedFileNames) rpmlib(FileDigests) rpmlib(PayloadFilesHavePrefix) rpmlib(PayloadIsXz)    3.0.4-1 4.6.0-1 4.0-1 5.2-1 4.14.3 /bin/sh /bin/sh /bin/sh drm-balin30.xiodrm.lab.emc.com 1791324253        1.0.0-trident_service_tool_expires_10.06.2028 1.0.0-trident_service_tool_expires_10.06.2028 -O2 -g -m64 -fmessage-length=0 -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables cpio xz 5 x86_64-suse-linux “<Ó–Ÿ�wAÌM
ê�     utf-8 6632dfb6e78fd3346baa860da339acdedf6f019fb1b5448ba1baa6cef67de795        ?   ÿÿý�   ý7zXZ  
áû¡ !   t/å£à { ] Ýc�ŠXëÒçË„âx[ë°dšrµ„      #ÐB+Oê(÷qèrt³py<ÐSŽ¯´a#>‚„µz. Q|)ä•Ú›Kš    
YZ
#----- end rpm boundary -----#
‰3  !ÏÒß¾´‰œ—CA‚´OŸ˜ójÅp_ 
	A‚´OŸ˜óÁ“ �w4"n¶·©²À””‘#£´{Ý >I	µº8O¡EÛ`e³çƒì¼�9áºZj	@¨LÌ]ìç
O\¥ç¾ EjQåH4™(e_8ÊõI„(:®ÿâQß7÷*ÎŸiýFþ_«.™õúIºÑRžkv© øŒÓ{ÿßIHäœ™Šªi_m‡; ‘@ÓG:3ÑZ®Óg¥ÀÕé´±Q¤¢‰à�jRO½ª!}¤™çýB' =Ç°Ï½}MmöjÃÀs´ø¼sŽœ �Ý”ß·Žš´)¬%&äàœù®g!âúX©?os/£BÔt¢üïæ½Åd­þ�KnVâÞ½ŒdÂ-›"=€m:oüJÍýf`[|Cl$†à‘±~f	JjI*¥³¬T©Ög�·tñ|BœrŠ1æ�âIøŒVøŽ£õ]Õ;€ôÎ~ÌÀJ”Æ¼¼Õ’5ÑiÐˆ`«Ž¹6+êÛýÉc²3]Í˜ JÆ}ÿ°dÁ*\ƒ>k<�z=Y`ˆ"ÔÔå$³cD�xÁÚ=`-Ë|ð3©Zºíz×>l•íca0ˆåíM±xú«H³}w¼[V‘~‹/ã‹]^;ç!7{tä‹ìýZÀ¼Üþ{F
ó -Ÿë±&l±ßÞøË†bqoA±ý6 NœëÜD2ígæÂ1‡à¾	“ó
#----- gpg sig boundary -----#