Apply shellcheck suggestions
This commit is contained in:
parent
b4ea850e15
commit
8cc0ef35e1
89
ghcup.sh
89
ghcup.sh
@ -6,7 +6,7 @@ set -e
|
|||||||
## global variables ##
|
## global variables ##
|
||||||
|
|
||||||
VERSION=0.0.1
|
VERSION=0.0.1
|
||||||
SCRIPT="$(basename $0)"
|
SCRIPT="$(basename "$0")"
|
||||||
VERBOSE=false
|
VERBOSE=false
|
||||||
FORCE=false
|
FORCE=false
|
||||||
INSTALL_BASE="$HOME/.ghcup"
|
INSTALL_BASE="$HOME/.ghcup"
|
||||||
@ -103,27 +103,27 @@ echov() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf_green() {
|
printf_green() {
|
||||||
printf "\033[0;32m${1}\033[0m\n"
|
printf "\\033[0;32m%s\\033[0m\\n" "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
get_distro_name() {
|
get_distro_name() {
|
||||||
if [ -f /etc/os-release ]; then
|
if [ -f /etc/os-release ]; then
|
||||||
# freedesktop.org and systemd
|
# freedesktop.org and systemd
|
||||||
. /etc/os-release
|
. /etc/os-release
|
||||||
printf "$NAME"
|
printf "%s" "$NAME"
|
||||||
elif command -V lsb_release >/dev/null 2>&1; then
|
elif command -V lsb_release >/dev/null 2>&1; then
|
||||||
# linuxbase.org
|
# linuxbase.org
|
||||||
printf "$(lsb_release -si)"
|
printf "%s" "$(lsb_release -si)"
|
||||||
elif [ -f /etc/lsb-release ]; then
|
elif [ -f /etc/lsb-release ]; then
|
||||||
# For some versions of Debian/Ubuntu without lsb_release command
|
# For some versions of Debian/Ubuntu without lsb_release command
|
||||||
. /etc/lsb-release
|
. /etc/lsb-release
|
||||||
printf "$DISTRIB_ID"
|
printf "%s" "$DISTRIB_ID"
|
||||||
elif [ -f /etc/debian_version ]; then
|
elif [ -f /etc/debian_version ]; then
|
||||||
# Older Debian/Ubuntu/etc.
|
# Older Debian/Ubuntu/etc.
|
||||||
printf "Debian"
|
printf "Debian"
|
||||||
else
|
else
|
||||||
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
|
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
|
||||||
printf "$(uname -s)"
|
printf "%s" "$(uname -s)"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,20 +131,20 @@ get_distro_ver() {
|
|||||||
if [ -f /etc/os-release ]; then
|
if [ -f /etc/os-release ]; then
|
||||||
# freedesktop.org and systemd
|
# freedesktop.org and systemd
|
||||||
. /etc/os-release
|
. /etc/os-release
|
||||||
printf "$VERSION_ID"
|
printf "%s" "$VERSION_ID"
|
||||||
elif command -V lsb_release >/dev/null 2>&1; then
|
elif command -V lsb_release >/dev/null 2>&1; then
|
||||||
# linuxbase.org
|
# linuxbase.org
|
||||||
printf "$(lsb_release -sr)"
|
printf "%s" "$(lsb_release -sr)"
|
||||||
elif [ -f /etc/lsb-release ]; then
|
elif [ -f /etc/lsb-release ]; then
|
||||||
# For some versions of Debian/Ubuntu without lsb_release command
|
# For some versions of Debian/Ubuntu without lsb_release command
|
||||||
. /etc/lsb-release
|
. /etc/lsb-release
|
||||||
printf "$DISTRIB_RELEASE"
|
printf "%s" "$DISTRIB_RELEASE"
|
||||||
elif [ -f /etc/debian_version ]; then
|
elif [ -f /etc/debian_version ]; then
|
||||||
# Older Debian/Ubuntu/etc.
|
# Older Debian/Ubuntu/etc.
|
||||||
printf "$(cat /etc/debian_version)"
|
printf "%s" "$(cat /etc/debian_version)"
|
||||||
else
|
else
|
||||||
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
|
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
|
||||||
printf "$(uname -r)"
|
printf "%s" "$(uname -r)"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,32 +177,32 @@ get_download_url() {
|
|||||||
# TODO: awkward, restructure
|
# TODO: awkward, restructure
|
||||||
case "${mydistro},${mydistrover},${myarch},${myghcver}" in
|
case "${mydistro},${mydistrover},${myarch},${myghcver}" in
|
||||||
Debian,7,i386,8.2.2)
|
Debian,7,i386,8.2.2)
|
||||||
printf "${baseurl}/${myghcver}/ghc-${myghcver}-${myarch}-deb${mydistrover}-linux.tar.xz"
|
printf "%s" "${baseurl}/${myghcver}/ghc-${myghcver}-${myarch}-deb${mydistrover}-linux.tar.xz"
|
||||||
break;;
|
;;
|
||||||
*,*,i386,*)
|
*,*,i386,*)
|
||||||
printf "${baseurl}/${myghcver}/ghc-${myghcver}-${myarch}-deb8-linux.tar.xz"
|
printf "%s" "${baseurl}/${myghcver}/ghc-${myghcver}-${myarch}-deb8-linux.tar.xz"
|
||||||
break;;
|
;;
|
||||||
Debian,*,*,8.2.2)
|
Debian,*,*,8.2.2)
|
||||||
printf "${baseurl}/${myghcver}/ghc-${myghcver}-${myarch}-deb8-linux.tar.xz"
|
printf "%s" "${baseurl}/${myghcver}/ghc-${myghcver}-${myarch}-deb8-linux.tar.xz"
|
||||||
break;;
|
;;
|
||||||
Debian,8,*,*)
|
Debian,8,*,*)
|
||||||
printf "${baseurl}/${myghcver}/ghc-${myghcver}-${myarch}-deb8-linux.tar.xz"
|
printf "%s" "${baseurl}/${myghcver}/ghc-${myghcver}-${myarch}-deb8-linux.tar.xz"
|
||||||
break;;
|
;;
|
||||||
Debian,*,*,*)
|
Debian,*,*,*)
|
||||||
printf "${baseurl}/${myghcver}/ghc-${myghcver}-${myarch}-deb9-linux.tar.xz"
|
printf "%s" "${baseurl}/${myghcver}/ghc-${myghcver}-${myarch}-deb9-linux.tar.xz"
|
||||||
break;;
|
;;
|
||||||
Ubuntu,*,*,8.2.2)
|
Ubuntu,*,*,8.2.2)
|
||||||
printf "${baseurl}/${myghcver}/ghc-${myghcver}-${myarch}-deb8-linux.tar.xz"
|
printf "%s" "${baseurl}/${myghcver}/ghc-${myghcver}-${myarch}-deb8-linux.tar.xz"
|
||||||
break;;
|
;;
|
||||||
Ubuntu,*,*,*)
|
Ubuntu,*,*,*)
|
||||||
printf "${baseurl}/${myghcver}/ghc-${myghcver}-${myarch}-deb9-linux.tar.xz"
|
printf "%s" "${baseurl}/${myghcver}/ghc-${myghcver}-${myarch}-deb9-linux.tar.xz"
|
||||||
break;;
|
;;
|
||||||
*,*,*,8.2.2)
|
*,*,*,8.2.2)
|
||||||
printf "${baseurl}/${myghcver}/ghc-${myghcver}-${myarch}-deb8-linux.tar.xz"
|
printf "%s" "${baseurl}/${myghcver}/ghc-${myghcver}-${myarch}-deb8-linux.tar.xz"
|
||||||
break;;
|
;;
|
||||||
*,*,*,*) # this is our best guess
|
*,*,*,*) # this is our best guess
|
||||||
printf "${baseurl}/${myghcver}/ghc-${myghcver}-${myarch}-fedora27-linux.tar.xz"
|
printf "%s" "${baseurl}/${myghcver}/ghc-${myghcver}-${myarch}-fedora27-linux.tar.xz"
|
||||||
break;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
unset myghcver myarch mydistro mydistrover baseurl
|
unset myghcver myarch mydistro mydistrover baseurl
|
||||||
@ -215,7 +215,6 @@ install_ghc() {
|
|||||||
myghcver=$1
|
myghcver=$1
|
||||||
downloader=curl
|
downloader=curl
|
||||||
downloader_opts="--fail -O"
|
downloader_opts="--fail -O"
|
||||||
old_pwd=${PWD}
|
|
||||||
inst_location=${INSTALL_BASE}/${myghcver}
|
inst_location=${INSTALL_BASE}/${myghcver}
|
||||||
target_location=${INSTALL_BASE}/bin
|
target_location=${INSTALL_BASE}/bin
|
||||||
|
|
||||||
@ -233,11 +232,11 @@ install_ghc() {
|
|||||||
(
|
(
|
||||||
cd "$(mktemp -d)"
|
cd "$(mktemp -d)"
|
||||||
|
|
||||||
echov "Downloading $(get_download_url ${myghcver})"
|
echov "Downloading $(get_download_url "${myghcver}")"
|
||||||
${downloader} ${downloader_opts} "$(get_download_url ${myghcver})"
|
${downloader} ${downloader_opts} "$(get_download_url "${myghcver}")"
|
||||||
|
|
||||||
tar -xf ghc-*-linux.tar.xz
|
tar -xf ghc-*-linux.tar.xz
|
||||||
cd ghc-${myghcver}
|
cd "ghc-${myghcver}"
|
||||||
|
|
||||||
echov "Installing GHC into ${inst_location}"
|
echov "Installing GHC into ${inst_location}"
|
||||||
|
|
||||||
@ -246,18 +245,18 @@ install_ghc() {
|
|||||||
|
|
||||||
# clean up
|
# clean up
|
||||||
cd ..
|
cd ..
|
||||||
rm -r ghc-*-linux.tar.xz ghc-${myghcver}
|
rm -r ghc-*-linux.tar.xz "ghc-${myghcver}"
|
||||||
)
|
)
|
||||||
|
|
||||||
for f in "${inst_location}"/bin/*-${myghcver} ; do
|
for f in "${inst_location}"/bin/*-"${myghcver}" ; do
|
||||||
fn=$(basename ${f})
|
fn=$(basename "${f}")
|
||||||
ln $(echov "-v") -s ../${myghcver}/bin/${fn} "${target_location}"/${fn}
|
ln $(echov "-v") -s ../"${myghcver}/bin/${fn}" "${target_location}/${fn}"
|
||||||
unset fn
|
unset fn
|
||||||
done
|
done
|
||||||
|
|
||||||
printf_green "Done installing, run \"ghci-${myghcver}\" or set up your current GHC via: ${SCRIPT} set-ghc ${myghcver}"
|
printf_green "Done installing, run \"ghci-${myghcver}\" or set up your current GHC via: ${SCRIPT} set-ghc ${myghcver}"
|
||||||
|
|
||||||
unset myghcver downloader downloader_opts old_pwd inst_location target_location f
|
unset myghcver downloader downloader_opts inst_location target_location f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -273,10 +272,10 @@ set_ghc() {
|
|||||||
|
|
||||||
printf_green "Setting GHC to ${myghcver}"
|
printf_green "Setting GHC to ${myghcver}"
|
||||||
|
|
||||||
for f in "${inst_location}"/bin/*-${myghcver} ; do
|
for f in "${inst_location}"/bin/*-"${myghcver}" ; do
|
||||||
source_fn=$(basename ${f})
|
source_fn=$(basename "${f}")
|
||||||
target_fn=$(echo ${source_fn} | sed "s#-${myghcver}##")
|
target_fn=$(echo "${source_fn}" | sed "s#-${myghcver}##")
|
||||||
ln $(echov "-v") -sf ../${myghcver}/bin/${source_fn} "${target_location}"/${target_fn}
|
ln $(echov "-v") -sf ../"${myghcver}/bin/${source_fn}" "${target_location}/${target_fn}"
|
||||||
unset source_fn target_fn
|
unset source_fn target_fn
|
||||||
done
|
done
|
||||||
ln $(echov "-v") -sf runghc "${target_location}"/runhaskell
|
ln $(echov "-v") -sf runghc "${target_location}"/runhaskell
|
||||||
@ -329,7 +328,7 @@ while [ $# -gt 0 ] ; do
|
|||||||
VERBOSE=true
|
VERBOSE=true
|
||||||
shift 1;;
|
shift 1;;
|
||||||
-V|--version)
|
-V|--version)
|
||||||
printf "${VERSION}"
|
printf "%s" "${VERSION}"
|
||||||
exit 0;;
|
exit 0;;
|
||||||
-h|--help)
|
-h|--help)
|
||||||
usage;;
|
usage;;
|
||||||
@ -346,7 +345,7 @@ while [ $# -gt 0 ] ; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
[ "${GHC_VER}" ] || install_usage
|
[ "${GHC_VER}" ] || install_usage
|
||||||
install_ghc ${GHC_VER}
|
install_ghc "${GHC_VER}"
|
||||||
break;;
|
break;;
|
||||||
set)
|
set)
|
||||||
shift 1
|
shift 1
|
||||||
@ -358,7 +357,7 @@ while [ $# -gt 0 ] ; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
[ "${GHC_VER}" ] || set_usage
|
[ "${GHC_VER}" ] || set_usage
|
||||||
set_ghc ${GHC_VER}
|
set_ghc "${GHC_VER}"
|
||||||
break;;
|
break;;
|
||||||
self-update)
|
self-update)
|
||||||
shift 1
|
shift 1
|
||||||
|
Loading…
Reference in New Issue
Block a user