#!/usr/bin/env bash EPKG_ROOTFS_TAR_PATH=/tmp/$USER URL=https://eulermaker.compass-ci.openeuler.openatom.cn/api/ems1/repositories/epkg/ EPKG_MANAGER_TAR=epkg_manager.tar.gz EPKG_ROOTFS_TAR=epkg_rootfs.tar.gz clear_env(){ rm -rf $HOME/{.epkg, .cache} rm -rf /tmp/$HOME/epkg_rootfs/ rm -rf $HOME/epkg_manager/ keyword="epkg" sed -i "/$keyword/d" $HOME/.bashrc export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' echo "clean $HOME env end" } mk_home(){ mkdir -p $EPKG_ROOTFS_TAR_PATH echo "mk /tmp/$HOME end" } download_file(){ source_file=$1 target_dir=$2 url=$3 target_file="$target_dir/$(basename "$source_file")" if [ -f "$target_file" ]; then return 0 fi curl -o $target_dir/$source_file $url/$source_file if [ $? -ne 0 ]; then echo "Download $source_file failed" return 1 fi return 0 } install_needed_tools() { local package_name="patchelf findutils tar fakeroot file" local max_retries=3 local retry_interval=5 local download_timeout=60 local retry_count=0 while ((retry_count < max_retries)); do if timeout ${download_timeout}s yum install -y $package_name; then echo "Package $package_name installed successfully on attempt $((retry_count+1))" return 0 else echo "Installation failed on attempt $((retry_count+1)). Retrying after $retry_interval seconds..." ((retry_count++)) sleep $retry_interval fi done echo "Failed to install package $package_name after $max_retries attempts." return 1 } excute_epkg_init(){ tar -xvf $EPKG_ROOTFS_TAR_PATH/$EPKG_MANAGER_TAR -C $HOME export PATH=$PATH:$HOME/epkg_manager/bin cd $HOME/epkg_manager/bin epkg init bash } echo "Excute user: $HOME" # step 1. clear history operation related info clear_env mk_home # step 2. install needed tools # install_needed_tools # step 3. download epkg_manager.tar.gz and epkg_rootfs.tar.gz download_file $EPKG_MANAGER_TAR $EPKG_ROOTFS_TAR_PATH $URL if [ $? -ne 0 ]; then echo "Download epkg_manager.tar.gz failed" exit 1 fi download_file $EPKG_ROOTFS_TAR $EPKG_ROOTFS_TAR_PATH $URL if [ $? -ne 0 ]; then echo "Download epkg_rootfs.tar.gz failed" exit 1 fi # step 4. init epkg rootfs env excute_epkg_init