HEX
Server: nginx/1.22.0
System: Linux iZuf6jdxbygmf6cco977lcZ 5.10.84-10.4.al8.x86_64 #1 SMP Tue Apr 12 12:31:07 CST 2022 x86_64
User: root (0)
PHP: 7.4.29
Disabled: passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,readlink,symlink,popepassthru,stream_socket_server,fsocket,popen
Upload Files
File: //usr/local/share/aliyun-assist/2.2.4.965/update_install
#!/bin/sh
if [ -f /opt/local/share/aliyun-assist/version ]; then
    # This requires aliyun assist agent MUST be installed in /opt/local/share/
    assist_version=$(cat /opt/local/share/aliyun-assist/version)
    script_dir="/opt/local/share/aliyun-assist/$assist_version"
elif [ -f /data/vendor/aliyun/version ];then
    # In cloud phone aliyun assist agent is installed in /data/vendor/aliyun/
    assist_version=$(cat /data/vendor/aliyun/version)
    script_dir="/data/vendor/aliyun/$assist_version"
else
    assist_version=$(cat /usr/local/share/aliyun-assist/version)
    script_dir="/usr/local/share/aliyun-assist/$assist_version"
fi
aliyun_service_name='aliyun-service'
aliyun_service_bin="/usr/sbin/$aliyun_service_name"

is_freebsd(){
	distro=$(uname)
	if [ "$distro" = 'FreeBSD' ] ; then
		return 0
	fi
	return 1
}

is_cloudphone(){
    if [ -f /default.prop ] && [ -f /system/bin/app_process64 ]; then
        return 0
    fi
    return 1
}

stop_service() {
    # For SUSE
    if [ -e /etc/inittab ]; then
        result=`cat /etc/inittab | grep "$aliyun_service_name"`
        if [ $? -eq 0 ]; then
            sed -i /$aliyun_service_name/d /etc/inittab
            # This file will be occupied by aliyun-service on SUSE 11
            if [ -e /var/tmp/aliyun_assist_update.lock ]; then
                rm -f /var/tmp/aliyun_assist_update.lock
            fi
            kill -HUP 1
            return
        fi
    fi
   
    if [ -e "/usr/lib/systemd/system/aliyun.service" ] || [ -e "/etc/systemd/system/aliyun.service" ];then
        # If there is no KillMode=process in aliyun.service, 
        # add it into /run/systemd/system/aliyun.service.d/killmode.conf
        if [ -e "/etc/systemd/system/aliyun.service" ];then
            if ! grep -q "KillMode=process" "/etc/systemd/system/aliyun.service";then
                mkdir -p /run/systemd/system/aliyun.service.d
                echo -e "[Service]\nKillMode=process" > /run/systemd/system/aliyun.service.d/killmode.conf
                systemctl daemon-reload
            fi
        fi
        systemctl stop aliyun.service
    fi
	[ -e "/etc/init.d/aliyun-service" ] && service aliyun-service stop
	[ -e "/etc/init/aliyun-service.conf" ] && /sbin/initctl stop aliyun-service

    # Force kill process once stopping service failed
    # coreos, binary file is not in path: $aliyun_service_bin
	for service_pid in `ps -C "$aliyun_service_name" -o pid= -o comm= | awk {'print $1'}`; do
        executable_path="$(readlink /proc/${service_pid}/exe)"
        if [ "${executable_path#/usr/local/share/aliyun-assist/}" != "$executable_path" ] \
            || [ "${executable_path#/opt/local/share/aliyun-assist/}" != "$executable_path" ]; then
            kill -9 $service_pid
            sleep 2
            if ps --pid $service_pid; then
                kill -9 $service_pid
                sleep 3
            fi
        fi
    done
}

clean() {   
    [ -e "/var/lock/agentwatch" ] && rm -f "/var/lock/agentwatch"

    # This file will be occupied by aliyun-service on some other case
    # just rm it, next update process will create it
    if [ -e /var/tmp/aliyun_assist_update.lock ]; then
        rm -f /var/tmp/aliyun_assist_update.lock
    fi
    
    #remove old agentwatch first
    if [ -e /etc/init.d/agentwatch ]; then
        CHK=$(which chkconfig)
        if [ ! -x "${CHK}" ]; then
            echo "No find chkconfig"
            URC=$(which update-rc.d)
            if [ -x "${URC}" ]; then
                echo "Find update-rc.d"
                update-rc.d -f agentwatch remove
            fi
        else
            echo "Find chkconfig"
            chkconfig --del agentwatch
        fi
        
        rm -rf /etc/init.d/agentwatch
    fi

    # Remove autostart configuration of compatibility with old chkconfig/update-rc.d
    # or different rc.d position
    if [ -f /etc/init.d/aliyun-service ]; then
        CHK=$(which chkconfig)
        if [ ! -x "${CHK}" ]; then
            echo "No find chkconfig"
            URC=$(which update-rc.d)
            if [ -x "${URC}" ]; then
                echo "Find update-rc.d"
                update-rc.d -f aliyun-service remove
            fi
        else
            echo "Find chkconfig"
            chkconfig --del aliyun-service
            chkconfig aliyun-service off
        fi
    fi
	
	[ -e "/usr/sbin/aliyun-service" ] && rm -rf /usr/sbin/aliyun-service
	[ -e "/usr/sbin/aliyun_installer" ] && rm -rf /usr/sbin/aliyun_installer
    [ -e "/run/systemd/system/aliyun.service.d" ]  && rm -rf /run/systemd/system/aliyun.service.d
	[ -e "/etc/systemd/system/aliyun.service" ] && rm -rf /etc/systemd/system/aliyun.service && systemctl daemon-reload
	[ -e "/etc/init.d/aliyun-service" ] && rm -rf /etc/init.d/aliyun-service
	[ -e "/etc/init/aliyun-service.conf" ] && rm -rf /etc/init/aliyun-service.conf
	[ -e "/usr/lib/systemd/system/aliyun.service" ] && rm -rf /usr/lib/systemd/system/aliyun.service && systemctl daemon-reload
}



install_assist_daemon(){
    if [ "${script_dir#/usr/local/share/aliyun-assist/}" != "$script_dir" ]; then
        daemon_dir='/usr/local/share/assist-daemon'
    elif [ "${script_dir#/opt/local/share/aliyun-assist/}" != "$script_dir" ]; then
        daemon_dir='/opt/local/share/assist-daemon'
    else
        return 1
    fi
	
	if [ -e $script_dir/assist_daemon ];
	then 
		echo "need to install assist_daemon"
	else
		echo "no need to install assist_daemon"
        disable_assist_daemon
		return
	fi
	
	if [ -e $daemon_dir/assist_daemon ]; then
		$daemon_dir/assist_daemon --stop
		$daemon_dir/assist_daemon --delete
		rm -rf "$daemon_dir"
	fi
	
	if [ -d $daemon_dir ];
	then 
		echo "assist-daemon exist"
	else
		mkdir "$daemon_dir"
	fi
	 
	cp -f $script_dir/assist_daemon $daemon_dir/assist_daemon
	chmod a+x $daemon_dir/assist_daemon
	$daemon_dir/assist_daemon --create
    # Do not start assist_daemon. Let Agent start assist_daemon according 
    # to the configuration. And disable assist_daemon to prevent systemd from 
    # starting assist_daemon at boot.
	# $daemon_dir/assist_daemon --start
    disable_assist_daemon
}

disable_assist_daemon(){
    if [ -d "/run/systemd/system/" ]; then
        systemctl disable AssistDaemon.service
        echo "disabled AssistDaemon.service"
    else
        echo "not systemd env"
    fi
}

check_arch(){
    os_arch=`uname -m`
    case $os_arch in
        "i386"|"i686"|"x86_64"|"amd64")
            os_arch="x86"
            ;;
        "arm"|"aarch64_be"|"aarch64"|"armv8b"|"armv8l")
            os_arch="arm"
            ;;
        *)
            echo "Unknown os arch: $os_arch"
            return 1
    esac

    if is_freebsd; then
        os_arch="${os_arch}_freebsd"
    elif is_cloudphone; then
        os_arch="android"
    else
        os_arch="${os_arch}_linux"
    fi
    # assist_version: 2.3.4.5, pkg_arch is expected to be 3
    pkg_arch=${assist_version#*.} # pkg_arch: 3.4.5
    pkg_arch=${pkg_arch%.*} # pkg_arch: 3.4
    pkg_arch=${pkg_arch%.*} # pkg_arch: 3
    if [ "$pkg_arch" = "" ];then
        echo "Unknown format assist version: $assist_version"
        return 1
    fi
    if [ "$pkg_arch" = "2" ];then
        pkg_arch="x86_linux"
    elif [ "$pkg_arch" = "3" ];then
        pkg_arch="x86_freebsd"
    elif [ "$pkg_arch" = "4" ];then
        pkg_arch="arm_linux"
    elif [ "$pkg_arch" = "5" ];then
        pkg_arch="arm_freebsd"
    elif [ "$pkg_arch" = "6" ];then
        pkg_arch="android"
    else
        echo "Unknown pkg_arch, pkg_arch code: $pkg_arch, assist version: $assist_version"
        return 1
    fi

    if [ "$os_arch" = "android" ] && [ "$pkg_arch" = "arm_linux" ];then
        # The installation package of arm linux in the transition phase is still applicable to the android environment
        return 0
    elif [ "$os_arch" != "$pkg_arch" ];then
        echo "Arch not match, os arch is $os_arch, package arch is $pkg_arch, version: $assist_version"
        return 1
    fi
    return 0
}

if ! check_arch; then
    exit 1
fi

if is_freebsd ; then
	echo "install freebsd aliyun-assist at $script_dir ..."
	if [ -e /usr/local/etc/rc.d/aliyun ];then
        service aliyun stop
        rm -rf /usr/local/etc/rc.d/aliyun
    fi

	chmod +x $script_dir/aliyun-service
	chmod +x $script_dir/aliyun_assist_update
    [ -e "$script_dir/acs-plugin-manager" ] && chmod +x $script_dir/acs-plugin-manager
	echo 'aliyun_enable="YES"' >> /etc/rc.conf
	$script_dir/aliyun-service --install
    # aliyun service need started manually after installation by pkg
	$script_dir/aliyun-service --start
    ln -sf $script_dir/aliyun-service /usr/sbin/aliyun-service
    [ -e "$script_dir/acs-plugin-manager" ] && ln -sf $script_dir/acs-plugin-manager /usr/sbin/acs-plugin-manager
elif is_cloudphone;then
    echo "install cloudphone aliyun-assist at $script_dir ..."
    chmod +x $script_dir/aliyun-service
    chmod +x $script_dir/aliyun_assist_update
    [ -e "$script_dir/acs-plugin-manager" ] && chmod +x $script_dir/acs-plugin-manager
    setprop ctl.restart aliyun-service
else
    echo "try to install assist daemon"
    install_assist_daemon
	
    echo "install linux aliyun-assist at $script_dir ..."

	stop_service
	clean

	chmod +x $script_dir/aliyun-service
	chmod +x $script_dir/aliyun_assist_update
    [ -e "$script_dir/acs-plugin-manager" ] && chmod +x $script_dir/acs-plugin-manager
    [ -e "$script_dir/aliyun_installer" ] && chmod +x $script_dir/aliyun_installer
    [ -e "$script_dir/aliyun_assist_netcheck" ] && chmod +x $script_dir/aliyun_assist_netcheck

	$script_dir/aliyun-service --install
	$script_dir/aliyun-service --start
    # Fix compatibility with old chkconfig/update-rc.d or different rc.d position
    if [ -f /etc/init.d/aliyun-service ]; then
        CHK=$(which chkconfig)
        if [ ! -x "${CHK}" ]; then
            echo "No find chkconfig"
            URC=$(which update-rc.d)
            if [ -x "${URC}" ]; then
                echo "Find update-rc.d"
                update-rc.d aliyun-service defaults
            fi
        else
            echo "Find chkconfig"
            chkconfig --add aliyun-service
            chkconfig aliyun-service on
        fi
    fi

    if [ "${script_dir#/usr/local/share/aliyun-assist/}" != "$script_dir" ]; then
        ln -sf $script_dir/aliyun-service /usr/sbin/aliyun-service
        [ -e "$script_dir/acs-plugin-manager" ] && ln -sf $script_dir/acs-plugin-manager /usr/sbin/acs-plugin-manager
        [ -e "$script_dir/aliyun_installer" ] && ln -sf $script_dir/aliyun_installer /usr/sbin/aliyun_installer
    elif [ "${script_dir#/opt/local/share/aliyun-assist/}" != "$script_dir" ]; then
        ln -sf $script_dir/aliyun-service /opt/sbin/aliyun-service
        [ -e "$script_dir/acs-plugin-manager" ] && ln -sf $script_dir/acs-plugin-manager /opt/sbin/acs-plugin-manager
        [ -e "$script_dir/aliyun_installer" ] && ln -sf $script_dir/aliyun_installer /opt/sbin/aliyun_installer
    fi
fi
# After the installation steps are completed correctly, the exit code should be 0
exit 0