Skip to content

Commit

Permalink
*: polish the trust key notice (#2475)
Browse files Browse the repository at this point in the history
* *: polish the trust key notice

Signed-off-by: Wish <[email protected]>

* Polish install script

Signed-off-by: Wish <[email protected]>

---------

Signed-off-by: Wish <[email protected]>
  • Loading branch information
breezewish authored Nov 15, 2024
1 parent dcb557a commit 9771000
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 32 deletions.
12 changes: 8 additions & 4 deletions cmd/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ func newMirrorShowCmd() *cobra.Command {
// the `mirror set` sub command
func newMirrorSetCmd() *cobra.Command {
var (
root string
reset bool
root string
reset bool
silent bool
)
cmd := &cobra.Command{
Use: "set <mirror-addr>",
Expand Down Expand Up @@ -198,12 +199,15 @@ The root manifest in $TIUP_HOME will be replaced with the one in given repositor
log.Errorf("Failed to set mirror: %s\n", err.Error())
return err
}
fmt.Printf("Successfully set mirror to %s\n", addr)
if !silent {
fmt.Printf("Successfully set mirror to %s\n", addr)
}
return nil
},
}
cmd.Flags().StringVarP(&root, "root", "r", root, "Specify the path of `root.json`")
cmd.Flags().BoolVar(&reset, "reset", false, "Reset mirror to use the default address.")
cmd.Flags().BoolVar(&silent, "silent", false, "Skip non-warning messages.")

return cmd
}
Expand Down Expand Up @@ -955,7 +959,7 @@ func newMirrorCloneCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "clone <target-dir> [global version]",
Example: ` tiup mirror clone /path/to/local --arch amd64,arm64 --os linux,darwin # Specify the architectures and OSs
tiup mirror clone /path/to/local --os linux v6.1.0 v5.4.0 # Specify multiple versions
tiup mirror clone /path/to/local --os linux v6.1.0 v5.4.0 # Specify multiple versions
tiup mirror clone /path/to/local --full # Build a full local mirror
tiup mirror clone /path/to/local --tikv v4 --prefix # Specify the version via prefix
tiup mirror clone /path/to/local --tidb all --pd all # Download all version for specific component`,
Expand Down
29 changes: 19 additions & 10 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,15 @@ fi

chmod 755 "$bin_dir/tiup"

"$bin_dir/tiup" mirror set $repo
"$bin_dir/tiup" mirror set $repo --silent

bold=$(tput bold 2>/dev/null)
green=$(tput setaf 2 2>/dev/null)
cyan=$(tput setaf 6 2>/dev/null)
sgr0=$(tput sgr0 2>/dev/null)

echo

# Refrence: https://stackoverflow.com/questions/14637979/how-to-permanently-set-path-on-linux-unix
shell=$(echo $SHELL | awk 'BEGIN {FS="/";} { print $NF }')
echo "Detected shell: ${bold}$shell${sgr0}"
Expand All @@ -82,16 +86,21 @@ else
PROFILE=${HOME}/.profile
fi
echo "Shell profile: ${bold}$PROFILE${sgr0}"

echo
echo "${bold}${green}${sgr0}Installed in ${bold}$bin_dir/tiup${sgr0}"
case :$PATH: in
*:$bin_dir:*) echo "PATH already contains $bin_dir" ;;
*:$bin_dir:*) echo "${bold}${green}${sgr0}tiup PATH is already set, skip" ;;
*) printf '\nexport PATH=%s:$PATH\n' "$bin_dir" >> "$PROFILE"
echo "$PROFILE has been modified to add tiup to PATH"
echo "open a new terminal or ${bold}source ${PROFILE}${sgr0} to use it"
echo "${bold}${green}${sgr0}Added tiup PATH into ${bold}${shell}${sgr0} profile"
;;
esac

echo "Installed path: ${bold}$bin_dir/tiup${sgr0}"
echo "==============================================="
echo "Have a try: ${bold}tiup playground${sgr0}"
echo "==============================================="
echo
echo "${bold}tiup is installed now${sgr0} 🎉"
echo
echo Next step:
echo
echo " 1: To make PATH change effective, restart your shell or execute:"
echo " ${bold}${cyan}source ${PROFILE}${sgr0}"
echo
echo " 2: Start a local TiDB for development:"
echo " ${bold}${cyan}tiup playground${sgr0}"
36 changes: 21 additions & 15 deletions pkg/cluster/template/install/local_install.sh.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,17 @@ fi
chmod 755 "$bin_dir/tiup"
# telemetry is not needed for offline installations
"$bin_dir/tiup" telemetry disable
# set mirror to the local path
"$bin_dir/tiup" mirror set ${script_dir}
"$bin_dir/tiup" mirror set ${script_dir} --silent
bold=$(tput bold 2>/dev/null)
green=$(tput setaf 2 2>/dev/null)
cyan=$(tput setaf 6 2>/dev/null)
sgr0=$(tput sgr0 2>/dev/null)
# Reference: https://stackoverflow.com/questions/14637979/how-to-permanently-set-path-on-linux-unix
echo
# Refrence: https://stackoverflow.com/questions/14637979/how-to-permanently-set-path-on-linux-unix
shell=$(echo $SHELL | awk 'BEGIN {FS="/";} { print $NF }')
echo "Detected shell: ${bold}$shell${sgr0}"
if [ -f "${HOME}/.${shell}_profile" ]; then
Expand All @@ -103,18 +104,23 @@ else
PROFILE=${HOME}/.profile
fi
echo "Shell profile: ${bold}$PROFILE${sgr0}"
echo
echo "${bold}${green}✔ ${sgr0}Installed in ${bold}$bin_dir/tiup${sgr0}"
case :$PATH: in
*:$bin_dir:*) : "PATH already contains $bin_dir" ;;
*) printf 'export PATH=%s:$PATH\n' "$bin_dir" >> "$PROFILE"
echo "$PROFILE has been modified to to add tiup to PATH"
echo "open a new terminal or ${bold}source ${PROFILE}${sgr0} to use it"
*:$bin_dir:*) echo "${bold}${green}✔ ${sgr0}tiup PATH is already set, skip" ;;
*) printf '\nexport PATH=%s:$PATH\n' "$bin_dir" >> "$PROFILE"
echo "${bold}${green}✔ ${sgr0}Added tiup PATH into ${bold}${shell}${sgr0} profile"
;;
esac
echo
echo "${bold}tiup is installed now${sgr0} 🎉"
echo
echo Next step:
echo
echo " 1: To make PATH change effective, restart your shell or execute:"
echo " ${bold}${cyan}source ${PROFILE}${sgr0}"
echo
echo " 2: Start a local TiDB for development:"
echo " ${bold}${cyan}tiup playground${sgr0}"
echo "Installed path: ${bold}$bin_dir/tiup${sgr0}"
echo "==============================================="
echo "1. ${bold}source ${PROFILE}${sgr0}"
echo "2. Have a try: ${bold}tiup playground${sgr0}"
echo "==============================================="
`
6 changes: 3 additions & 3 deletions pkg/localdata/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ func (p *Profile) ResetMirror(addr, root string) error {

// Only cache remote mirror
if strings.HasPrefix(addr, "http") && root != localRoot {
if strings.HasPrefix(root, "http") {
fmt.Printf("WARN: adding root certificate via internet: %s\n", root)
fmt.Printf("You can revoke this by remove %s\n", localRoot)
if strings.HasPrefix(root, "http") && !strings.HasPrefix(root, "https") {
fmt.Printf("WARN: Trusting component distribution key via insecure Internet: %s\n", root)
fmt.Printf(" To revoke TiUP's trust, remove this file: %s\n", localRoot)
}
_ = utils.Copy(p.Path("bin", "root.json"), localRoot)
}
Expand Down

0 comments on commit 9771000

Please sign in to comment.