#!/usr/bin/env bash EPKG_TARS_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 mk_home(){ echo "Attention: we will mkdir dir in /tmp for saving $EPKG_MANAGER_TAR and $EPKG_ROOTFS_TAR" echo "sure to continue? (y: continue, others: exit)" read choice if [ "$choice" != "y" ]; then return fi mkdir -p $EPKG_TARS_PATH echo "Make /tmp/$HOME end" } download_tar(){ tar_1= url=$3 echo "Attention: we will download $EPKG_MANAGER_TAR and $EPKG_ROOTFS_TAR to $EPKG_TARS_PATH", which needs 150M space echo "sure to continue? (y: continue, others: exit)" read choice if [ "$choice" != "y" ]; then return 1 fi if [ ! -f $EPKG_TARS_PATH/$EPKG_MANAGER_TAR ]; then curl -o $EPKG_TARS_PATH/$EPKG_MANAGER_TAR $URL/$EPKG_MANAGER_TAR if [ $? -ne 0 ]; then echo "Download $EPKG_MANAGER_TAR failed" return 1 fi fi if [ ! -f $EPKG_TARS_PATH/$EPKG_ROOTFS_TAR ]; then curl -o $EPKG_TARS_PATH/$EPKG_ROOTFS_TAR $URL/$EPKG_ROOTFS_TAR if [ $? -ne 0 ]; then echo "Download $EPKG_ROOTFS_TAR failed" return 1 fi fi return 0 } install_needed_tools() { local package_name="util-linux fakeroot" local max_retries=3 local retry_interval=5 local download_timeout=60 local retry_count=0 echo "Attention: we will install needed tools [$package_name] for epkg initialization" echo "sure to continue? (y: continue, others: exit)" read choice if [ "$choice" != "y" ]; then return 1 fi 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 } execute_epkg_init(){ echo "Attention: we will tar -xvf $EPKG_MANAGER_TAR to $EPKG_TARS_PATH for epkg initialization" echo "sure to continue? (y: continue, others: exit)" read choice if [ "$choice" != "y" ]; then return 1 fi tar -xvf $EPKG_TARS_PATH/$EPKG_MANAGER_TAR -C $EPKG_TARS_PATH > /dev/null export PATH=$PATH:$EPKG_TARS_PATH/epkg_manager/bin # cd $EPKG_TARS_PATH/epkg_manager/bin echo "Attention: we will execute epkg initialization." echo "These dirs will be maked: OPT_EPKG=/opt/epkg HOME_EPKG=$HOME/.epkg export PROJECT_DIR=$HOME/epkg_manager EPKG_CONFIG_DIR=$HOME_EPKG/config EPKG_ENVS_ROOT=$HOME_EPKG/envs EPKG_STORE_ROOT=$HOME_EPKG/store EPKG_PKG_CACHE_DIR=$HOME/.cache/epkg/packages COMMON_PROFILE_LINK=$EPKG_ENVS_ROOT/common/profile-current" echo "sure to continue? (y: continue, others: exit)" read choice if [ "$choice" != "y" ]; then return 1 fi epkg init echo "For changes to take effect, close and re-open your current shell." bash } echo "Execute user: $USER" # step 1. mk path to save tar files mk_home # step 2. install needed tools install_needed_tools # step 3. download epkg_manager.tar.gz and epkg_rootfs.tar.gz download_tar if [ $? -ne 0 ]; then exit 1 fi # step 4. init epkg rootfs env execute_epkg_init