From c2f14734f7a0696e6db908e877d16458b6bed128 Mon Sep 17 00:00:00 2001 From: LAN-TW Date: Sun, 28 Jul 2013 14:51:36 +0800 Subject: =?UTF-8?q?bash=5Finclude:=20=E8=87=AA=E5=8B=95=E4=B8=8B=E8=BC=89?= =?UTF-8?q?=E8=A8=AD=E5=AE=9A=E6=AA=94=20|=20vimrc:=20neocomplete=20?= =?UTF-8?q?=E5=A4=96=E6=8E=9B=E3=80=81GTK+=20=E8=AA=9E=E6=B3=95=E6=A8=99?= =?UTF-8?q?=E8=A8=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bash_include | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) (limited to 'bash_include') diff --git a/bash_include b/bash_include index 36cb8a8..1fc6a6f 100644 --- a/bash_include +++ b/bash_include @@ -922,6 +922,74 @@ function path_editor () ########## New PATH Editor End ########## +########## Configuration File ########## + +function configfile_fetch () +{ + local mirror_list=" + http://www.tfcis.org/~lantw44/configfile/ + http://phantom.tfcis.org/~lantw44/mirror/forum_tfcis_org/configfile/ + http://master.lant.com.tw/~lantw44/configfile/ + http://www.csie.ntu.edu.tw/~b01902062/configfile/" + local url_append + local file_name + local file_version + + if [ "$3" ]; then + url_append="$3" + else + url_append="Unix-like/" + fi + if [ "$1" ]; then + file_name="$1" + else + file_name="bash_include vimrc screenrc" + fi + if [ "$2" ]; then + file_version="-$2" + else + url_append="${url_append}latest/" + fi + + for file in $file_name + do + for site in $mirror_list + do + if fetch_remote_file "$HOME/.${file}.new" \ + "${site}${url_append}${file}${file_version}" + then + mv -vf "$HOME/.${file}.new" "$HOME/.${file}" + break + fi + done + done +} + +function configfile_initial_setup () +{ + cat >> ~/.bashrc << EOF +if [ -f ~/.bash_include ]; then + . ~/.bash_include +fi +EOF + if [ "`uname`" = "FreeBSD" ]; then + cat >> ~/.bash_login << EOF +GET_TTY_NAME=`tty | cut -c 9` +[ "$GET_TTY_NAME" = 'v' ] && echo "Login from local virtual terminal: `tty`" +[ "$GET_TTY_NAME" = 'p' ] && echo "Login from pseudo terminal: `tty`" +[ "$GET_TTY_NAME" = '/' ] && echo "Login from pseudo terminal: `tty`" +unset GET_TTY_NAME +EOF + fi + cat >> ~/.bash_login << EOF +if [ -f ~/.bash_include ]; then + . ~/.bashrc +fi +EOF +} + +########## Configuration File End ########## + function varset () { local varoldvalue @@ -1176,6 +1244,37 @@ function unzip_nomac () return $? } +function check_command_existent () +{ + which "$1" &> /dev/null + return $? +} + +function fetch_remote_file () +{ + local rval + printf "==> Fetch remote file \e[1;33m$2\e[m as \e[1;35m$1\e[m ...\n" + if check_command_existent curl; then + curl -f -o "$1" "$2" + rval=$? + elif check_command_existent fetch; then + fetch -o "$1" "$2" + rval=$? + elif check_command_existent wget; then + wget --progress=dot -O "$1" "$2" + rval=$? + else + echo "<== Sorry, I don't know how to fetch remote files on your system" + return 1 + fi + if [ "$rval" = "0" ]; then + printf "<== \e[1;32mDone\e[m\n" + else + printf "<== \e[1;31mFailed\e[m\n" + fi + return $rval +} + ########## Help ########## alias helpf='help_function' @@ -1243,6 +1342,10 @@ function help_function () ldpath_editor x newpath_init x newpath_gen + <<< Group: Configuration File >>> + configfile_fetch [file_name_list [file_version [system_type]]] + configfile_initial_setup + x fetch_remote_file local_file_name remote_url <<< Other >>> backup_file filename ... [-- sudo_prefix ...] check_dmesg seconds -- cgit v1.2.3