OSDN Git Service

[change] : 2020 to 2021
[alterlinux/fascode-live-tools.git] / alterlinux-live-info / alterlinux-live-info
1 #!/usr/bin/env bash
2 # Yamada Hayao
3 # Twitter: @Hayao0819
4 # Email  : hayao@fascode.net
5 #
6 # (c) 2019-2021 Fascode Network.
7 #
8
9 set -e
10
11 #infofile="/run/archiso/bootmnt/alteriso-info"
12 infofile="${HOME}/Desktop/alteriso-info"
13 shellmode=false
14
15 _help() {
16     echo "usage ${0} [options]"
17     echo
18     echo " General options:"
19     echo "    -f | --file [path]  Specify the file to read"
20     echo "    -s | --shell        Enable shell mode"
21     echo "    -h | --help         This help message and exit."
22 }
23
24 # Argument analysis and processing
25 options="${@}"
26 opt_short="hf:s"
27 opt_long="help,file:,shell"
28 OPT=$(getopt -o ${opt_short} -l ${opt_long} -- "${@}")
29 if [[ ${?} != 0 ]]; then
30     exit 1
31 fi
32
33 eval set -- "${OPT}"
34 unset OPT opt_short opt_long
35
36 while true; do
37     case "${1}" in
38         -s | --shell)
39             shellmode=true
40             shift 1
41             ;;
42         -f | --file)
43             infofile="${2}"
44             shift 2
45             ;;
46         -h | --help)
47             _help
48             shift 1
49             exit 0
50             ;;
51         --)
52             shift
53             break
54             ;;
55         *)
56             echo "Invalid argument '${1}'" >&2
57             _help
58             exit 1
59             ;;
60     esac
61 done
62
63
64 if [[ ! -f "${infofile}" ]]; then
65     echo "${infofile} was not found." >&2
66     exit 1
67 fi
68
69
70 if [[ "${shellmode}" = false ]]; then
71     cat "${infofile}"
72 else
73     # 項目を取得する
74     items=()
75     for _item in $(cat "${infofile}" | cut -d ':' -f 1 | sed 's/ *$//' |sed 's| \+|_|g' | tr '[:upper:]' '[:lower:]'); do
76         items+=("$(echo "${_item}")")
77     done
78     unset _item
79
80     # 値を取得する
81     values=()
82     PREV_IFS="${IFS}"
83     IFS="
84 "
85     values=($(cat "${infofile}" | cut -d ':' -f 2- | sed "s|^ ||g" | grep -v ^$))
86     line_number=$(( "$(cat "${infofile}" 2> /dev/null | wc -l)" - 1 ))
87     IFS="${PREV_IFS}"
88
89     for line in $(seq 0 "${line_number}"); do
90         echo "${items[${line}]}=\"${values[${line}]}\""
91     done
92 fi