سؤال

i have downloaded a script file which downloads steam engine, dependencies and then install them. i am trying to understand what code is exactly doing. i have understood some part of it, but could not understand some functions. can someone explain me what these functions doing?

download() {
    local url="$1"
    local filename="$(basename "$url")"

    if [ ! -f "$filename" ]; then
        wget -c "$url" -O "$filename.part"
        mv "$filename.part" "$filename"
    fi
}

package() {
    local url="$1"
    local target="$2"

    download "$url"

    mkdir -p "$target"
    ar p "$(basename "$url")" data.tar.gz | tar xz -C "$target"
}

STEAM_DEB_URL="http://media.steampowered.com/client/installer/steam.deb"
UBUNTU_DEB_URL="http://security.ubuntu.com/ubuntu/pool/main/e/eglibc/libc6_2.15-0ubuntu10.2_i386.deb"
هل كانت مفيدة؟

المحلول

The download function takes a URL as its argument and stores it as a variable named url. The $(basename "$url") executes the command basename with the url variable as its argument and the value is return and stored into filename. Essentially it is trying to determine the filename portion of the url. So if your URL was www.example.com/foo.txt filename would only be equal to foo.txt The if block tries to see if the file already exists in your current working directory. If it does not then it uses curl to download it.

The package function takes two arguments a url and a target. The url passed to the download function already described. After the file is downloaded it creates the target directory and extracts the contents of what was downloaded.

As the file that was downloaded is in a .deb format it first has to use the "ar" command. The .deb file format always a file inside it called data.tar.gz which is the "meat" of the package. As the data.tar.gz file is also compressed it needs to be extracted as well. Tar handles that but first it changes to the target directory so that the files end up in the right spot.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top