Skip to content

Instantly share code, notes, and snippets.

@Hayao0819
Last active January 11, 2020 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hayao0819/6135651937954048fd1cb3c31f6b64b5 to your computer and use it in GitHub Desktop.
Save Hayao0819/6135651937954048fd1cb3c31f6b64b5 to your computer and use it in GitHub Desktop.
EG-Installer-Updater
#!/usr/bin/env bash
#-- 設定 --#
eg_installer="/usr/bin/eg-installer"
#-- 関数定義 --#
# ウィンドウの基本型
function window () {
zenity \
--title="EG-Installer Updater" \
$@
}
# 読み込みウィンドウ
function loading () {
window \
--progress \
--auto-close \
--pulsate \
--width="$1" \
--height="$2" \
--text="$3"
}
# エラーウィンドウ
function error () {
window \
--error \
--width="$1" \
--height="$2" \
--text="$3"
}
# 警告ウィンドウ
function warning () {
window \
--warning \
--width="$1" \
--height="$2" \
--text="$3"
}
# 情報ウィンドウ
function info () {
window \
--info \
--width="$1" \
--height="$2" \
--text="$3"
}
#-- Rootチェック --#
if [[ ! $UID = 0 ]]; then
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY $current_path $options> /dev/null
exit 0
fi
#-- 変数の確認 --#
if [[ ! -f $eg_installer ]]; then
error 600 100 "EG-Installerへのパスが間違っています。\nアップデートしたいEG-Installerを選択してください。"
eg_installer=$(window --file-selection)
fi
#-- 現在の情報を取得 --#
current_ver=v$($eg_installer -e | awk '{print $1}')
configs=$($eg_installer -e | awk '{print $2}')
#-- バージョン確認 --#
if [[ -z $current_ver ]]; then
error 600 100 "アップデートする前のEG-Installerがv1.6以上でないとアップデートできません。"
exit 1
fi
#-- 最新のバージョンを取得 --#
latest_ver=$(curl -s https://api.github.com/repos/hayao0819/EG-Installer/releases/latest | jq '.tag_name' )
latest_ver=${latest_ver::-1}
latest_ver=${latest_ver:1}
#-- バージョン比較 --#
if [[ $current_ver = $latest_ver ]]; then
echo "既に最新です。"
exit 0
fi
#-- アップデート変数 --#
download_temp=/tmp/eg-installer-${latest_ver}.tar.gz
expend_dir=/tmp/EG-Installer-${latest_ver:1}
#-- ファイル取得 --#
set -eu
window \
--question \
--text="EG-Installerを${current_ver}から${latest_ver}にアップデートします。よろしいですか?" \
--ok-label="続行する" \
--cancel-label="中断する" \
--width="600" \
--height="100"
set +eu
curl -sL -o $download_temp https://github.com/Hayao0819/EG-Installer/archive/${latest_ver}.tar.gz
tar -zxvf $download_temp -C /tmp/ > /dev/null
#-- ファイル移動 --#
set -eu
if [[ -f $eg_installer ]]; then
rm $eg_installer
fi
mv $expend_dir/eg-installer $eg_installer
current_dir=$(dirname $eg_installer)
version=${current_ver}
source $configs
if [[ -d $script_dir ]]; then
rm -rf $script_dir
fi
mv $expend_dir/softwares $script_dir
if [[ -f $pacman ]]; then
rm -f $pacman
fi
mv $expend_dir/pacapt $pacman
set +eu
#-- 削除 --#
rm -f $download_temp
rm -rf $expend_dir
#-- 終了 --#
info 600 100 "アップデートが終了しました。"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment