feat: opt installer function
This commit is contained in:
parent
0e54e4f2d0
commit
abe42bed0c
2 changed files with 39 additions and 8 deletions
|
@ -6,7 +6,11 @@ DOWNLOAD_URL="https://github.com/MatsuriDayo/nekoray/releases/download/3.26/neko
|
||||||
FILE_NAME="nekoray.zip"
|
FILE_NAME="nekoray.zip"
|
||||||
|
|
||||||
install_nekoray() {
|
install_nekoray() {
|
||||||
download_file $DOWNLOAD_URL $FILE_NAME
|
download_file "$DOWNLOAD_URL" "$FILE_NAME"
|
||||||
|
|
||||||
|
opt_installer "/tmp/$FILE_NAME"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_sudo
|
||||||
|
|
||||||
install_nekoray
|
install_nekoray
|
||||||
|
|
|
@ -40,6 +40,33 @@ ask_prompt() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
opt_installer() {
|
||||||
|
check_command unzip
|
||||||
|
|
||||||
|
local file_path="$1"
|
||||||
|
local filename=$(basename "$file_path")
|
||||||
|
local opt_dir="/opt"
|
||||||
|
local target_file="$opt_dir/$filename"
|
||||||
|
|
||||||
|
if [ ! -e $file_path ]; then
|
||||||
|
log "File $file_path not found."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -e $target_file ]; then
|
||||||
|
cp $file_path "$opt_dir/$filename"
|
||||||
|
fi
|
||||||
|
|
||||||
|
unzip -o $target_file -d $opt_dir
|
||||||
|
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
log "File moved to $opt_dir successfully."
|
||||||
|
else
|
||||||
|
log "Failed to move file to $opt_dir."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
download_file() {
|
download_file() {
|
||||||
check_command wget
|
check_command wget
|
||||||
|
|
||||||
|
@ -50,19 +77,19 @@ download_file() {
|
||||||
|
|
||||||
if [ -e "$file_path" ]; then
|
if [ -e "$file_path" ]; then
|
||||||
if ask_prompt "File $file_path already exists. Do you want to continue ?"; then
|
if ask_prompt "File $file_path already exists. Do you want to continue ?"; then
|
||||||
echo "Continuing with existing file: $file_path"
|
log "Continuing with existing file: $file_path"
|
||||||
wget -c -O "$tmp_dir/$filename" "$url"
|
wget -q --show-progress -c -O "$tmp_dir/$filename" "$url"
|
||||||
else
|
else
|
||||||
echo "Deleted existing file: $file_path"
|
log "Deleted existing file: $file_path"
|
||||||
wget -O "$tmp_dir/$filename" "$url"
|
wget -q --show-progress -O "$tmp_dir/$filename" "$url"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
wget -O "$tmp_dir/$filename" "$url"
|
wget -q --show-progress -O "$tmp_dir/$filename" "$url"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "File downloaded successfully: $tmp_dir/$filename"
|
log "File downloaded successfully: $tmp_dir/$filename"
|
||||||
else
|
else
|
||||||
echo "Failed to download file from $url"
|
log "Failed to download file from $url"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue