diff --git a/.gitignore b/.gitignore index 9f847ba97..1b885b05a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,8 @@ reports/* test.txt test-report.xml -*rice-box.go -.vscode/* \ No newline at end of file +.vscode/* +dist/ +vendor/ +bats-core/ +.DS_Store diff --git a/.goreleaser-iofogctl-dev.yml b/.goreleaser-iofogctl-dev.yml new file mode 100644 index 000000000..97d520ee1 --- /dev/null +++ b/.goreleaser-iofogctl-dev.yml @@ -0,0 +1,203 @@ +# goreleaser config for iofogctl. See: https://goreleaser.com +# +# To execute goreleaser, use the mage targets: +# +# $ mage iofogctl:snapshot +# $ mage iofogctl:release +# +# The snapshot target builds the installation packages (brew, rpm, +# deb, etc), into the dist dir. +# The release target does the same, but also publishes the packages. +# +# See README.md for more. +project_name: iofogctl +env: + - GO111MODULE=on + - CGO_ENABLED=0 +before: + hooks: + - go version + +builds: + - id: build_macos + binary: iofogctl + env: + main: ./cmd/iofogctl/main.go + goos: + - darwin + goarch: + - amd64 + - arm64 + ldflags: + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.versionNumber=v{{.Version}}" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.commit={{ .ShortCommit }}" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.date={{.Date}}" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.platform={{.Os}}/{{.Arch }}" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.portManagerTag=3.0.0" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.kubeletTag=3.0.0-beta1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.operatorTag=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.proxyTag=3.0.0" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.routerTag=3.0.0" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.controllerTag=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.agentTag=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.controllerVersion=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.agentVersion=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.repo=iofog" + + - id: build_linux + binary: iofogctl + main: ./cmd/iofogctl/ + goos: + - linux + goarch: + - amd64 + - arm64 + - arm + goarm: + - 6 + - 7 + ldflags: + - -extldflags -static + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.versionNumber=v{{.Version}}" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.commit={{ .ShortCommit }}" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.date={{.Date}}" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.platform={{.Os}}/{{.Arch }}" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.portManagerTag=3.0.0" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.kubeletTag=3.0.0-beta1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.operatorTag=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.proxyTag=3.0.0" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.routerTag=3.0.0" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.controllerTag=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.agentTag=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.controllerVersion=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.agentVersion=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.repo=iofog" + flags: + - -v + + - id: build_windows + binary: iofogctl + env: + main: ./cmd/iofogctl/main.go + goos: + - windows + goarch: + - amd64 + ldflags: + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.versionNumber=v{{.Version}}" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.commit={{ .ShortCommit }}" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.date={{.Date}}" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.platform={{.Os}}/{{.Arch }}" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.portManagerTag=3.0.0" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.kubeletTag=3.0.0-beta1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.operatorTag=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.proxyTag=3.0.0" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.routerTag=3.0.0" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.controllerTag=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.agentTag=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.controllerVersion=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.agentVersion=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.repo=iofog" + + +archives: + - + id: linux + builds: + - build_linux + name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}" + format: tar.gz + files: + - README.md + - LICENSE + - + id: macos + builds: + - build_macos + name_template: "{{.ProjectName}}_{{.Version}}_{{.Os}}_{{.Arch}}" + format: tar.gz + files: + - README.md + - LICENSE + replacements: + darwin: macos + +checksum: + name_template: "{{.ProjectName}}-checksums.txt" + +snapshot: + name_template: "{{ .Version }}~dev" + +changelog: + skip: true + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' + - '^dev:' + - 'README' + - Merge pull request + - Merge branch + + +release: + github: + owner: eclipse-iofog + name: iofogctl + + # If set to true, will not auto-publish the release. Default is false. + draft: false + + # If set to auto, will mark the release as not ready for production + # in case there is an indicator for this in the tag e.g. v1.0.0-rc1 + # If set to true, will mark the release as not ready for production. + # Default is false. + prerelease: auto + +brews: + - + name: iofogctl + homepage: "https://github.com/eclipse-iofog/iofogctl" + description: "CLI for iofog" + + tap: + owner: eclipse-iofog + name: homebrew-iofogctl + + url_template: "https://github.com/eclipse-iofog/iofogctl/releases/download/{{ .Tag }}/{{ .ArtifactName }}" + + commit_author: + name: neha + email: neha@edgeworx.io + + folder: Formula + + test: | + system "#{bin}/iofogctl version" + install: | + bin.install "iofogctl" + skip_upload: false + +nfpms: + - + builds: ['build_linux'] + homepage: "https://github.com/eclipse-iofog/iofogctl" + description: CLI for iofog + maintainer: Eclipse + vendor: Edgeworx + + + formats: + - deb + - rpm + + overrides: + deb: + file_name_template: "{{ .ConventionalFileName }}" + rpm: + # Note: file_name_template must have this EXACT format + file_name_template: "{{ .ProjectName }}-{{ .Version }}-1.{{ .Arch }}{{ if .Arm }}v{{ .Arm }}hl{{ end }}" + replacements: + amd64: x86_64 + arm64: aarch64 \ No newline at end of file diff --git a/.goreleaser-iofogctl.yml b/.goreleaser-iofogctl.yml new file mode 100644 index 000000000..a0373a3dc --- /dev/null +++ b/.goreleaser-iofogctl.yml @@ -0,0 +1,204 @@ +# goreleaser config for iofogctl. See: https://goreleaser.com +# +# To execute goreleaser, use the mage targets: +# +# $ mage iofogctl:snapshot +# $ mage iofogctl:release +# +# The snapshot target builds the installation packages (brew, rpm, +# deb, etc), into the dist dir. +# The release target does the same, but also publishes the packages. +# +# See README.md for more. +project_name: iofogctl +env: + - GO111MODULE=on + - CGO_ENABLED=0 +before: + hooks: + - go version + +builds: + - id: build_macos + binary: iofogctl + env: + main: ./cmd/iofogctl/main.go + goos: + - darwin + goarch: + - amd64 + - arm64 + ldflags: + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.versionNumber=v{{.Version}}" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.commit={{ .ShortCommit }}" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.date={{.Date}}" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.platform={{.Os}}/{{.Arch}}" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.portManagerTag=3.0.0" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.kubeletTag=3.0.0-beta1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.operatorTag=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.proxyTag=3.0.0" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.routerTag=3.0.0" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.controllerTag=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.agentTag=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.controllerVersion=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.agentVersion=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.repo=iofog" + + - id: build_linux + binary: iofogctl + main: ./cmd/iofogctl/ + goos: + - linux + goarch: + - amd64 + - arm64 + - arm + goarm: + - 6 + - 7 + ldflags: + - -extldflags -static + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.versionNumber=v{{.Version}}" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.commit={{ .ShortCommit }}" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.date={{.Date}}" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.platform={{.Os}}/{{.Arch}}" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.portManagerTag=3.0.0" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.kubeletTag=3.0.0-beta1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.operatorTag=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.proxyTag=3.0.0" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.routerTag=3.0.0" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.controllerTag=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.agentTag=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.controllerVersion=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.agentVersion=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.repo=iofog" + + flags: + - -v + + - id: build_windows + binary: iofogctl + env: + main: ./cmd/iofogctl/main.go + goos: + - windows + goarch: + - amd64 + ldflags: + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.versionNumber=v{{.Version}}" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.commit={{ .ShortCommit }}" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.date={{.Date}}" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.platform={{.Os}}/{{.Arch}}" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.portManagerTag=3.0.0" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.kubeletTag=3.0.0-beta1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.operatorTag=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.proxyTag=3.0.0" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.routerTag=3.0.0" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.controllerTag=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.agentTag=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.controllerVersion=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.agentVersion=3.0.1" + - -s -w -X "github.com/eclipse-iofog/iofogctl/v3/pkg/util.repo=iofog" + + +archives: + - + id: linux + builds: + - build_linux + name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}" + format: tar.gz + files: + - README.md + - LICENSE + - + id: macos + builds: + - build_macos + name_template: "{{.ProjectName}}_{{.Version}}_{{.Os}}_{{.Arch}}" + format: tar.gz + files: + - README.md + - LICENSE + replacements: + darwin: macos + +checksum: + name_template: "{{.ProjectName}}-checksums.txt" + +snapshot: + name_template: "{{ .Version }}-SNAPSHOT" + +changelog: + skip: true + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' + - '^dev:' + - 'README' + - Merge pull request + - Merge branch + + +release: + github: + owner: eclipse-iofog + name: iofogctl + + # If set to true, will not auto-publish the release. Default is false. + draft: false + + # If set to auto, will mark the release as not ready for production + # in case there is an indicator for this in the tag e.g. v1.0.0-rc1 + # If set to true, will mark the release as not ready for production. + # Default is false. + prerelease: auto + +brews: + - + name: iofogctl + homepage: "https://github.com/eclipse-iofog/iofogctl" + description: "CLI for iofog" + + tap: + owner: eclipse-iofog + name: homebrew-iofogctl + + url_template: "https://github.com/eclipse-iofog/iofogctl/releases/download/{{ .Tag }}/{{ .ArtifactName }}" + + commit_author: + name: neha + email: neha@edgeworx.io + + folder: Formula + + test: | + system "#{bin}/iofogctl version" + install: | + bin.install "iofogctl" + skip_upload: false + +nfpms: + - + builds: ['build_linux'] + homepage: "https://github.com/eclipse-iofog/iofogctl" + description: CLI for iofog + maintainer: Eclipse + vendor: Edgeworx + + + formats: + - deb + - rpm + + overrides: + deb: + file_name_template: "{{ .ConventionalFileName }}" + rpm: + # Note: file_name_template must have this EXACT format + file_name_template: "{{ .ProjectName }}-{{ .Version }}-1.{{ .Arch }}{{ if .Arm }}v{{ .Arm }}hl{{ end }}" + replacements: + amd64: x86_64 + arm64: aarch64 \ No newline at end of file diff --git a/.packagecloud-publish.sh b/.packagecloud-publish.sh new file mode 100755 index 000000000..3d517a78b --- /dev/null +++ b/.packagecloud-publish.sh @@ -0,0 +1,107 @@ +#!/usr/bin/env bash + +# This script publishes ".deb" and ".rpm" files in the ./dist +# dir to packagecloud. This script relies on the existence +# of the "packagecloud" binary: https://github.com/edgeworx/packagecloud +# The binary can be installed via: go install github.com/edgeworx/packagecloud@v0.1.0 + +set -e + +echo "" +echo "*************** Publish to packagecloud.io ***************" + +if [[ -z "$PACKAGECLOUD_TOKEN" ]]; then + echo "Must provide PACKAGECLOUD_TOKEN envar" 1>&2 + exit 1 +fi + +repo="${PACKAGECLOUD_REPO:-iofog/iofogctl-snapshots}" +echo "Using packagecloud repo: $repo" + +pushd ./dist > /dev/null +echo "Using dist dir: $PWD" + + +failed_push_file='./failed_packagecloud_push' +echo -n "" > $failed_push_file + +# add some stutter to avoid overloading packagecloud API +function sleepStutter() { + sleep "0.$((50 + RANDOM % 300))s" +} + +function deb() { + packages=$(ls | grep .deb) + + echo "" + echo "*************** Publish .deb ***************" + echo "deb packages to publish..." + echo "$packages" + echo "" + declare -a distro_versions=( + "ubuntu/focal" "ubuntu/xenial" "ubuntu/bionic" "ubuntu/trusty" + "debian/stretch" "debian/buster" "debian/bullseye" + "raspbian/stretch" "raspbian/buster" "raspbian/bullseye" + "any/any" + ) + + for package in $packages; do + for distro_version in "${distro_versions[@]}"; do + sleepStutter + repo_full_path="$repo/$distro_version" + echo $repo_full_path + { + packagecloud push --overwrite "${repo_full_path}" "${package}" 2> >(tee -a $failed_push_file >&2) + } & + done + done + + wait +} + +function rpm() { + packages=$(ls | grep .rpm) + + echo "" + echo "*************** Publish .rpm ***************" + echo "rpm packages to publish..." + echo "$packages" + echo "" + + + declare -a distro_versions=( + "fedora/23" "fedora/24" "fedora/30" "fedora/31" + "el/6" "el/7" "el/8" + "rpm_any/rpm_any" + ) + + for package in $packages; do + for distro_version in "${distro_versions[@]}"; do + sleepStutter + repo_full_path="$repo/$distro_version" + { + packagecloud push --overwrite "${repo_full_path}" "${package}" 2> >(tee -a $failed_push_file >&2) + } & + done + done + + wait +} + +deb & +sleep 0.1s # give the deb func time to do its output +rpm & + +wait + +echo "" +if [ -s $failed_push_file ]; then + # There's content in #failed_push_file... so we need to output it and exit 1. + echo "*************** Failures (from $failed_push_file) ***************" + echo "" + cat $failed_push_file + echo "" + exit 1 +else + echo "*************** SUCCESS ***************" +fi \ No newline at end of file diff --git a/Makefile b/Makefile index 872c81778..57af5eb8e 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ DEV_SUFFIX = -dev SUFFIX ?= $(shell [ -z "$(shell git tag --points-at HEAD)" ] && echo "$(DEV_SUFFIX)" || echo "$(TAG_SUFFIX)") VERSION ?= $(MAJOR).$(MINOR).$(PATCH)$(SUFFIX) COMMIT ?= $(shell git rev-parse HEAD 2>/dev/null) -BUILD_DATE ?= $(shell date +%FT%T%z) +BUILD_DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ) PREFIX = github.com/eclipse-iofog/iofogctl/v3/pkg/util LDFLAGS += -X $(PREFIX).versionNumber=$(VERSION) -X $(PREFIX).commit=$(COMMIT) -X $(PREFIX).date=$(BUILD_DATE) -X $(PREFIX).platform=$(GOOS)/$(GOARCH) LDFLAGS += -X $(PREFIX).portManagerTag=3.0.0 @@ -48,8 +48,8 @@ build: fmt ## Build the binary @go build -v $(GOARGS) $(PACKAGE_DIR)/main.go .PHONY: install -install: ## Install the iofogctl binary to /usr/local/bin - @sudo cp $(BUILD_DIR)/$(BINARY_NAME) /usr/local/bin +install: + go install -ldflags "$(LDFLAGS)" ./cmd/iofogctl/ .PHONY: lint lint: golangci-lint fmt ## Lint the source diff --git a/assets/controller/install_iofog.sh b/assets/controller/install_iofog.sh index 8045880ac..16b51c9bd 100755 --- a/assets/controller/install_iofog.sh +++ b/assets/controller/install_iofog.sh @@ -50,7 +50,7 @@ install_deps() { install_package "build-essential" fi - if [ -z "$(command -v python)" ]; then + if [ -z "$(command -v python2)" ]; then install_package "python" fi } @@ -61,13 +61,13 @@ deploy_controller() { lsof -ti tcp:51121 | xargs kill fi - # If token is provided, set up private repo +# If token is provided, set up private repo if [ ! -z $token ]; then if [ ! -z $(npmrc | grep iofog) ]; then npmrc -c iofog npmrc iofog fi - curl -s https://"$token":@packagecloud.io/install/repositories/"$repo"/script.node.sh | force_npm=1 bash + curl -s https://"$token":@packagecloud.io/install/repositories/"$repo"/script.node.sh?package_id=7368735 | force_npm=1 bash mv ~/.npmrc ~/.npmrcs/npmrc ln -s ~/.npmrcs/npmrc ~/.npmrc else @@ -75,28 +75,27 @@ deploy_controller() { fi # Save DB - if [ -f "$INSTALL_DIR/controller/lib/node_modules/iofogcontroller/package.json" ]; then + if [ -f "$INSTALL_DIR/controller/lib/node_modules/@iofog/iofogcontroller/package.json" ]; then # If iofog-controller is not running, it will fail to stop - ignore that failure. - node $INSTALL_DIR/controller/lib/node_modules/iofogcontroller/scripts/scripts-api.js preuninstall > /dev/null 2>&1 || true + node $INSTALL_DIR/controller/lib/node_modules/@iofog/iofogcontroller/scripts/scripts-api.js preuninstall > /dev/null 2>&1 || true fi # Install in temporary location mkdir -p "$TMP_DIR/controller" chmod 0777 "$TMP_DIR/controller" if [ -z $version ]; then - npm install -g -f iofogcontroller --unsafe-perm --prefix "$TMP_DIR/controller" + npm install -g -f @iofog/iofogcontroller --unsafe-perm --prefix "$TMP_DIR/controller" else - npm install -g -f "iofogcontroller@$version" --unsafe-perm --prefix "$TMP_DIR/controller" + npm install -g -f "@iofog/iofogcontroller@$version" --unsafe-perm --prefix "$TMP_DIR/controller" fi - # Move files into $INSTALL_DIR/controller mkdir -p "$INSTALL_DIR/" rm -rf "$INSTALL_DIR/controller" # Clean possible previous install mv "$TMP_DIR/controller/" "$INSTALL_DIR/" # Restore DB - if [ -f "$INSTALL_DIR/controller/lib/node_modules/iofogcontroller/package.json" ]; then - node $INSTALL_DIR/controller/lib/node_modules/iofogcontroller/scripts/scripts-api.js postinstall > /dev/null 2>&1 || true + if [ -f "$INSTALL_DIR/controller/lib/node_modules/@iofog/iofogcontroller/package.json" ]; then + node $INSTALL_DIR/controller/lib/node_modules/@iofog/iofogcontroller/scripts/scripts-api.js postinstall > /dev/null 2>&1 || true fi # Symbolic links diff --git a/assets/controller/install_node.sh b/assets/controller/install_node.sh index 5574fd775..b998f7dad 100755 --- a/assets/controller/install_node.sh +++ b/assets/controller/install_node.sh @@ -15,15 +15,14 @@ load_existing_nvm() { } install_node() { - # nvm load_existing_nvm if [ -z "$(command -v nvm)" ]; then - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash export NVM_DIR="${HOME}/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" fi - nvm install v14.19.0 - nvm use v14.19.0 + nvm install v18.15.0 + nvm use v18.15.0 ln -Ffs $(which node) /usr/local/bin/node ln -Ffs $(which npm) /usr/local/bin/npm diff --git a/azure-pipelines.yaml b/azure-pipelines.yaml index 55af11792..641f29dc1 100644 --- a/azure-pipelines.yaml +++ b/azure-pipelines.yaml @@ -40,20 +40,48 @@ variables: ssh_key_file: 'id_rsa' windows_kube_config_path: 'C:/Users/$(azure.windows.user)/.kube/config' bash_kube_config_path: '/root/.kube/config' + isTaggedCommit: $[startsWith(variables['Build.SourceBranch'], 'refs/tags/')] stages: - stage: Build jobs: - - template: pipeline/build.yaml - parameters: - os: linux - - template: pipeline/build.yaml - parameters: - os: darwin - - template: pipeline/build.yaml - parameters: - os: windows + - job: Build + pool: + vmImage: 'Ubuntu-20.04' + steps: + - template: pipeline/steps/prebuild.yaml + - template: pipeline/steps/version.yaml + - script: | + set -e + mkdir -p '$(GOBIN)' + mkdir -p '$(GOPATH)/pkg' + echo '##vso[task.prependpath]$(GOBIN)' + echo '##vso[task.prependpath]$(GOROOT)/bin' + displayName: 'Set up the Go workspace' + - task: GoTool@0 + inputs: + version: '1.19' + goPath: $(GOPATH) + goBin: $(GOBIN) + displayName: 'Install Golang' + + - script: | + set -e + go install github.com/goreleaser/goreleaser@v1.1.0 + displayName: 'iofogctl: Install Goreleaser' + - script: | + set -e + goreleaser --snapshot --rm-dist --debug --config ./.goreleaser-iofogctl.yml + displayName: 'iofogctl: Build packages' + env: + GITHUB_TOKEN: $(github_token) + - task: PublishBuildArtifacts@1 + condition: always() + inputs: + PathtoPublish: '$(System.DefaultWorkingDirectory)/dist' + ArtifactName: iofogctl + displayName: 'Publish iofogctl binaries' - stage: Test jobs: @@ -66,24 +94,95 @@ stages: parameters: job_name: Vanilla id: $(jobuuid) - distro: $(gcp.vm.distro.stretch) + distro: $(gcp.vm.distro.bullseye) repo: $(gcp.vm.repo.debian) agent_count: 2 controller_count: 1 -# - template: pipeline/vanilla.yaml -# parameters: -# job_name: Vanilla_Buster -# id: $(jobuuid) -# distro: $(gcp.vm.distro.buster) -# repo: $(gcp.vm.repo.debian) -# agent_count: 2 -# controller_count: 1 - stage: Publish - condition: or(and(succeeded(), eq(variables['build.sourceBranch'], 'refs/heads/develop')), and(succeeded(), startsWith(variables['build.sourceBranch'], 'refs/tags/'))) jobs: - - template: pipeline/publish-linux.yaml - - template: pipeline/publish-osx.yaml - - template: pipeline/publish-debian.yaml - - template: pipeline/publish-rpm.yaml - - template: pipeline/publish-win.yaml + - job: Publish_Iofogctl_Dev + condition: or(and(succeeded(), eq(variables['build.sourceBranch'], 'refs/heads/develop')), and(succeeded(), startsWith(variables['build.sourceBranch'], 'refs/tags/'))) + pool: + vmImage: 'Ubuntu-22.04' + steps: + - template: pipeline/steps/version.yaml + - script: | + set -e + mkdir -p '$(GOBIN)' + mkdir -p '$(GOPATH)/pkg' + echo '##vso[task.prependpath]$(GOBIN)' + echo '##vso[task.prependpath]$(GOROOT)/bin' + displayName: 'Set up the Go workspace' + - task: GoTool@0 + inputs: + version: '1.19' + goPath: $(GOPATH) + goBin: $(GOBIN) + displayName: 'Install Golang' + + - script: | + set -e + go install github.com/goreleaser/goreleaser@v1.1.0 + displayName: 'iofogctl: Install Goreleaser' + - script: | + go install github.com/edgeworx/packagecloud@v0.1.1 + displayName: 'iofogctl: Install packagecloud CLI' + - script: | + set -e + goreleaser --snapshot --rm-dist --debug --config ./.goreleaser-iofogctl-dev.yml + ./.packagecloud-publish.sh + displayName: 'iofogctl: Build and Release dev only packages' + env: + PACKAGECLOUD_TOKEN: $(packagecloud_token) + PACKAGECLOUD_REPO: "iofog/iofogctl-snapshots" + GITHUB_TOKEN: $(github_token) + - task: PublishBuildArtifacts@1 + condition: always() + inputs: + PathtoPublish: '$(System.DefaultWorkingDirectory)/dist' + ArtifactName: iofogctl_dev + displayName: 'Publish iofogctl binaries' + + - job: Publish_Iofogctl_Prod + condition: and(succeeded(), eq(variables['isTaggedCommit'], true)) + pool: + vmImage: 'Ubuntu-22.04' + steps: + - template: pipeline/steps/version.yaml + - script: | + set -e + mkdir -p '$(GOBIN)' + mkdir -p '$(GOPATH)/pkg' + echo '##vso[task.prependpath]$(GOBIN)' + echo '##vso[task.prependpath]$(GOROOT)/bin' + displayName: 'Set up the Go workspace' + - task: GoTool@0 + inputs: + version: '1.19' + goPath: $(GOPATH) + goBin: $(GOBIN) + displayName: 'Install Golang' + + - script: | + set -e + go install github.com/goreleaser/goreleaser@v1.1.0 + displayName: 'iofogctl: Install Goreleaser' + - script: | + go install github.com/edgeworx/packagecloud@v0.1.1 + displayName: 'iofogctl: Install packagecloud CLI' + - script: | + set -e + goreleaser --rm-dist --debug --config ./.goreleaser-iofogctl.yml + ./.packagecloud-publish.sh + displayName: 'iofogctl: Build and Release packages' + env: + PACKAGECLOUD_TOKEN: $(packagecloud_token) + PACKAGECLOUD_REPO: "iofog/iofogctl" + GITHUB_TOKEN: $(github_token) + - task: PublishBuildArtifacts@1 + condition: always() + inputs: + PathtoPublish: '$(System.DefaultWorkingDirectory)/dist' + ArtifactName: iofogctl + displayName: 'Publish iofogctl binaries' diff --git a/go.mod b/go.mod index a2d1c65fb..082d4df94 100644 --- a/go.mod +++ b/go.mod @@ -59,6 +59,7 @@ require ( github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/sirupsen/logrus v1.8.1 // indirect github.com/spf13/pflag v1.0.5 // indirect + golang.org/x/mod v0.8.0 // indirect golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect diff --git a/go.sum b/go.sum index 3ae7f73d6..93c207569 100644 --- a/go.sum +++ b/go.sum @@ -779,6 +779,8 @@ golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= +golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= diff --git a/internal/cmd/version.go b/internal/cmd/version.go index ef6343cd6..2bf4e6af2 100644 --- a/internal/cmd/version.go +++ b/internal/cmd/version.go @@ -27,7 +27,7 @@ func newVersionCommand() *cobra.Command { Run: func(cmd *cobra.Command, args []string) { ecnFlag, err := cmd.Flags().GetBool("ecn") util.Check(err) - util.PrintInfo("iofogctl - Copyright (C) 2019-2022, Edgeworx, Inc.\n") + util.PrintInfo("iofogctl - Copyright (C) 2019-2023, Edgeworx, Inc.\n") _ = util.Print(util.GetVersion()) if ecnFlag { fmt.Println("") diff --git a/pipeline/brew.tpl b/pipeline/brew.tpl deleted file mode 100644 index dca20e0bb..000000000 --- a/pipeline/brew.tpl +++ /dev/null @@ -1,16 +0,0 @@ -class IofogctlAT < Formula - desc "Command line tool for deploying and administering ioFog platforms" - homepage "https://github.com/eclipse-iofog/iofogctl" - url "///iofogctl.tar.gz" - sha256 "" - version "" - - depends_on "curl" - depends_on "bash-completion" - - bottle :unneeded - - def install - bin.install "iofogctl" - end -end \ No newline at end of file diff --git a/pipeline/build.yaml b/pipeline/build.yaml deleted file mode 100644 index 3458a3180..000000000 --- a/pipeline/build.yaml +++ /dev/null @@ -1,20 +0,0 @@ -parameters: - os: '' - -jobs: -- job: ${{ parameters.os }} - pool: - vmImage: 'Ubuntu-20.04' - steps: - - template: steps/prebuild.yaml - - template: steps/version.yaml - - script: | - . version.sh && export MAJOR && export MINOR && export PATCH && export SUFFIX - echo "version: $MAJOR.$MINOR.$PATCH$SUFFIX" - GOARCH=amd64 GOOS=${{ parameters.os }} make lint build - echo $MAJOR.$MINOR.$PATCH$SUFFIX > bin/version - displayName: 'Build Binary' - - task: PublishBuildArtifacts@1 - inputs: - pathtoPublish: './bin' - artifactName: ${{ parameters.os }} \ No newline at end of file diff --git a/pipeline/ha.yaml b/pipeline/ha.yaml index f44ccf7f2..5a43e8018 100644 --- a/pipeline/ha.yaml +++ b/pipeline/ha.yaml @@ -6,10 +6,10 @@ jobs: - task: DownloadBuildArtifacts@0 displayName: 'Download Build Artifacts' inputs: - artifactName: linux + artifactName: iofogctl downloadPath: $(System.DefaultWorkingDirectory) - script: | - sudo cp linux/iofogctl /usr/local/bin/ + sudo cp iofogctl/build_linux_linux_amd64/iofogctl /usr/local/bin/ sudo chmod 0755 /usr/local/bin/iofogctl - template: steps/postinstall.yaml - template: steps/init-ssh.yaml diff --git a/pipeline/k8s.yaml b/pipeline/k8s.yaml index 410a08d73..7498c9705 100644 --- a/pipeline/k8s.yaml +++ b/pipeline/k8s.yaml @@ -6,10 +6,10 @@ jobs: - task: DownloadBuildArtifacts@0 displayName: 'Download Build Artifacts' inputs: - artifactName: linux + artifactName: iofogctl downloadPath: $(System.DefaultWorkingDirectory) - script: | - sudo cp linux/iofogctl /usr/local/bin/ + sudo cp iofogctl/build_linux_linux_amd64/iofogctl /usr/local/bin/ sudo chmod 0755 /usr/local/bin/iofogctl - template: steps/postinstall.yaml - template: steps/init-ssh.yaml diff --git a/pipeline/local.yaml b/pipeline/local.yaml index 918231968..a2111563e 100644 --- a/pipeline/local.yaml +++ b/pipeline/local.yaml @@ -12,10 +12,10 @@ jobs: - task: DownloadBuildArtifacts@0 displayName: 'Download Build Artifacts' inputs: - artifactName: linux + artifactName: iofogctl downloadPath: $(System.DefaultWorkingDirectory) - script: | - sudo cp linux/iofogctl /usr/local/bin/ + sudo cp iofogctl/build_linux_linux_amd64/iofogctl /usr/local/bin/ sudo chmod 0755 /usr/local/bin/iofogctl - bash: | sudo apt-get install -y jq diff --git a/pipeline/publish-debian.yaml b/pipeline/publish-debian.yaml deleted file mode 100644 index f3e2e6ced..000000000 --- a/pipeline/publish-debian.yaml +++ /dev/null @@ -1,38 +0,0 @@ -jobs: -- job: Debian - pool: - vmImage: 'Ubuntu-20.04' - steps: - - task: DownloadBuildArtifacts@0 - displayName: 'Download Build Artifacts' - inputs: - artifactName: linux - downloadPath: $(System.DefaultWorkingDirectory) - - script: | - sudo cp linux/iofogctl /usr/local/bin/ - sudo chmod 0755 /usr/local/bin/iofogctl - - template: steps/version.yaml - - template: steps/publish-deps.yaml - - script: | - fpm -f -s dir -t deb -n iofogctl -v $(version) /usr/local/bin/iofogctl=/usr/local/bin/ - package=$(ls | grep *.deb) - echo $package - cp $package $(Build.ArtifactStagingDirectory) - displayName: 'Create Debian package' - - script: | - package=$(ls | grep *.deb) - echo "package..." - echo $package - declare -a UBUNTU_VERS=("xenial" "bionic" "trusty" "focal") - declare -a DEBIAN_VERS=("stretch" "buster") - for ubu in "${UBUNTU_VERS[@]}" - do - package_cloud yank iofog/iofogctl-snapshots/ubuntu/${ubu} $package --config=$(Agent.TempDirectory)/package_cloud || true - package_cloud push iofog/iofogctl-snapshots/ubuntu/${ubu} $package --config=$(Agent.TempDirectory)/package_cloud - done - for deb in "${DEBIAN_VERS[@]}" - do - package_cloud yank iofog/iofogctl-snapshots/debian/${deb} $package --config=$(Agent.TempDirectory)/package_cloud || true - package_cloud push iofog/iofogctl-snapshots/debian/${deb} $package --config=$(Agent.TempDirectory)/package_cloud - done - displayName: 'Publish deb to package-cloud' diff --git a/pipeline/publish-linux.yaml b/pipeline/publish-linux.yaml deleted file mode 100644 index 13619461f..000000000 --- a/pipeline/publish-linux.yaml +++ /dev/null @@ -1,20 +0,0 @@ -jobs: -- job: Linux - pool: - vmImage: 'Ubuntu-20.04' - steps: - - task: DownloadBuildArtifacts@0 - displayName: 'Download Build Artifacts' - inputs: - artifactName: linux - downloadPath: $(System.DefaultWorkingDirectory) - - template: steps/init-gcloud-steps.yaml - - template: steps/version.yaml - - template: steps/init-ssh.yaml - - script: | - . version.sh - DIR="$(gcp.bucket.linux)/$MAJOR.$MINOR" - gsutil cp linux/iofogctl gs://$DIR/iofogctl - gsutil acl set public-read gs://$DIR/iofogctl - displayName: 'Publish Linux binary' - \ No newline at end of file diff --git a/pipeline/publish-osx.yaml b/pipeline/publish-osx.yaml deleted file mode 100644 index c32e005dd..000000000 --- a/pipeline/publish-osx.yaml +++ /dev/null @@ -1,43 +0,0 @@ -jobs: -- job: OSX - pool: - vmImage: 'Ubuntu-20.04' - steps: - - task: DownloadBuildArtifacts@0 - displayName: 'Download Build Artifacts' - inputs: - artifactName: darwin - downloadPath: $(System.DefaultWorkingDirectory) - - template: steps/init-gcloud-steps.yaml - - template: steps/version.yaml - - template: steps/init-ssh.yaml - - script: | - . version.sh - short_version=$MAJOR.$MINOR.$PATCH - tar -zcf iofogctl.tar.gz darwin/iofogctl - checksum=$(shasum -a 256 iofogctl.tar.gz | awk '{ print $1 }') - gsutil cp iofogctl.tar.gz gs://$(gcp.bucket.osx)/$short_version/ - gsutil acl set public-read gs://$(gcp.bucket.osx)/$short_version/iofogctl.tar.gz - gsutil cp darwin/iofogctl gs://$(gcp.bucket.osx)/$short_version/ - gsutil acl set public-read gs://$(gcp.bucket.osx)/$short_version/iofogctl - git config --global user.email "serge@edgeworx.io" - git config --global user.name "Serge Radinovich" - git clone git@github.com:eclipse-iofog/homebrew-iofogctl.git - cd homebrew-iofogctl - brew_file=iofogctl@${MAJOR}.${MINOR}-devel.rb - if [ ! -f $brew_file ]; then - cat ../pipeline/brew.tpl > $brew_file - sed -i "s//${MAJOR}${MINOR}Devel/g" $brew_file - sed -i "s//$checksum/g" $brew_file - sed -i "s//$(gcp.bucket.url)/g" $brew_file - sed -i "s//$(gcp.bucket.osx)/g" $brew_file - sed -i "s//$(version)-b$(Build.BuildId)/g" $brew_file - else - sed -i "s/sha256.*/sha256 \"$checksum\"/g" $brew_file - sed -i "s/version.*/version \"$(version)-b$(Build.BuildId)\"/g" $brew_file - sed -i "s|url .*|url \"$(gcp.bucket.url)/$(gcp.bucket.osx)/$short_version/iofogctl.tar.gz\"|g" $brew_file - fi - git add $brew_file - git commit -m "Publish develop version $(version)" - git push origin master - displayName: 'Build and publish OSX binary' \ No newline at end of file diff --git a/pipeline/publish-rpm.yaml b/pipeline/publish-rpm.yaml deleted file mode 100644 index 0d00f44c2..000000000 --- a/pipeline/publish-rpm.yaml +++ /dev/null @@ -1,36 +0,0 @@ -jobs: -- job: RPM - pool: - vmImage: 'Ubuntu-20.04' - steps: - - task: DownloadBuildArtifacts@0 - displayName: 'Download Build Artifacts' - inputs: - artifactName: linux - downloadPath: $(System.DefaultWorkingDirectory) - - script: sudo cp linux/iofogctl /usr/local/bin/ - - template: steps/version.yaml - - template: steps/publish-deps.yaml - - script: | - fpm -f -s dir -t rpm -n iofogctl -v $(version) /usr/local/bin/iofogctl=/usr/local/bin/ - package=$(ls | grep *.rpm) - echo $package - cp $package $(Build.ArtifactStagingDirectory) - displayName: 'Create RPM package' - - script: | - package=$(ls | grep *.rpm) - echo "package..." - echo $package - declare -a FEDORA_VERS=("23" "24" "30" "31") - declare -a REDHAT_VERS=("6" "7" "8") - for fed in ${FEDORA_VERS[@]} - do - package_cloud yank iofog/iofogctl-snapshots/fedora/${fed} $package --config=$(Agent.TempDirectory)/package_cloud || true - package_cloud push iofog/iofogctl-snapshots/fedora/${fed} $package --config=$(Agent.TempDirectory)/package_cloud - done - for red in ${REDHAT_VERS[@]} - do - package_cloud yank iofog/iofogctl-snapshots/el/${red} $package --config=$(Agent.TempDirectory)/package_cloud || true - package_cloud push iofog/iofogctl-snapshots/el/${red} $package --config=$(Agent.TempDirectory)/package_cloud - done - displayName: 'Publish RPM to package-cloud' diff --git a/pipeline/publish-win.yaml b/pipeline/publish-win.yaml deleted file mode 100644 index 9866738e0..000000000 --- a/pipeline/publish-win.yaml +++ /dev/null @@ -1,20 +0,0 @@ -jobs: -- job: Windows - pool: - vmImage: 'Ubuntu-20.04' - steps: - - task: DownloadBuildArtifacts@0 - displayName: 'Download Build Artifacts' - inputs: - artifactName: windows - downloadPath: $(System.DefaultWorkingDirectory) - - template: steps/init-gcloud-steps.yaml - - template: steps/version.yaml - - template: steps/init-ssh.yaml - - script: | - . version.sh - DIR="$(gcp.bucket.win)/$MAJOR.$MINOR" - gsutil cp windows/iofogctl gs://$DIR/iofogctl.exe - gsutil acl set public-read gs://$DIR/iofogctl.exe - displayName: 'Publish Windows binary' - \ No newline at end of file diff --git a/pipeline/steps/vanilla.yaml b/pipeline/steps/vanilla.yaml index 14a866f9c..9c9c65f05 100644 --- a/pipeline/steps/vanilla.yaml +++ b/pipeline/steps/vanilla.yaml @@ -9,10 +9,10 @@ steps: - task: DownloadBuildArtifacts@0 displayName: 'Download Build Artifacts' inputs: - artifactName: linux + artifactName: iofogctl downloadPath: $(System.DefaultWorkingDirectory) - script: | - sudo cp $(System.DefaultWorkingDirectory)/linux/iofogctl /usr/local/bin/ + sudo cp iofogctl/build_linux_linux_amd64/iofogctl /usr/local/bin/ sudo chmod 0755 /usr/local/bin/iofogctl - template: postinstall.yaml - template: init-ssh.yaml diff --git a/pipeline/steps/version.yaml b/pipeline/steps/version.yaml index 7074a5c91..a418fa048 100644 --- a/pipeline/steps/version.yaml +++ b/pipeline/steps/version.yaml @@ -11,4 +11,5 @@ steps: fi fi echo "##vso[task.setvariable variable=version]$VERS" + echo "Version: $VERS" displayName: 'Set version variable' \ No newline at end of file diff --git a/pipeline/win-k8s.yaml b/pipeline/win-k8s.yaml index 115cf80cf..2716165ce 100644 --- a/pipeline/win-k8s.yaml +++ b/pipeline/win-k8s.yaml @@ -8,7 +8,7 @@ jobs: - task: DownloadBuildArtifacts@0 displayName: 'Download Build Artifacts' inputs: - artifactName: windows + artifactName: iofogctl downloadPath: $(System.DefaultWorkingDirectory) - bash: | dir=$(wslpath "C:\Users\$(azure.windows.user)\AppData\Local\Microsoft\WindowsApps") diff --git a/pkg/util/rice-box.go b/pkg/util/rice-box.go new file mode 100644 index 000000000..59d89549a --- /dev/null +++ b/pkg/util/rice-box.go @@ -0,0 +1,188 @@ +// Code generated by rice embed-go; DO NOT EDIT. +package util + +import ( + "time" + + "github.com/GeertJohan/go.rice/embedded" +) + +func init() { + + // define files + file3 := &embedded.EmbeddedFile{ + Filename: "agent/check_prereqs.sh", + FileModTime: time.Unix(1674701401, 0), + + Content: string("#!/bin/sh\nset -x\n\n# Check can sudo without password\nif ! $(sudo ls /tmp/ > /dev/null); then\n\tMSG=\"Unable to successfully use sudo with user $USER on this host.\\nUser $USER must be in sudoers group and using sudo without password must be enabled.\\nPlease see iofog.org documentation for more details.\"\n\techo $MSG\n\texit 1\nfi\n"), + } + file4 := &embedded.EmbeddedFile{ + Filename: "agent/init.sh", + FileModTime: time.Unix(1674701401, 0), + + Content: string("#!/bin/sh\nset -x\nset -e\n\nget_distribution() {\n\tlsb_dist=\"\"\n\t# Every system that we officially support has /etc/os-release\n\tif [ -r /etc/os-release ]; then\n\t\tlsb_dist=\"$(. /etc/os-release && echo \"$ID\")\"\n\t\tlsb_dist=\"$(echo \"$lsb_dist\" | tr '[:upper:]' '[:lower:]')\"\n\telse\n\t\techo \"Unsupported Linux distribution!\"\n\t\texit 1\n\tfi\n\techo \"# Our distro is $lsb_dist\"\n}\n\n# Check if this is a forked Linux distro\ncheck_forked() {\n\t# Check for lsb_release command existence, it usually exists in forked distros\n\tif command_exists lsb_release; then\n\t\t# Check if the `-u` option is supported\n\t\tset +e\n\t\tlsb_release -a\n\t\tlsb_release_exit_code=$?\n\t\tset -e\n\n\t\t# Check if the command has exited successfully, it means we're in a forked distro\n\t\tif [ \"$lsb_release_exit_code\" = \"0\" ]; then\n\t\t\t# Print info about current distro\n\t\t\tcat <<-EOF\n\t\t\tYou're using '$lsb_dist' version '$dist_version'.\n\t\t\tEOF\n\n\t\t\t# Get the upstream release info\n\t\t\tlsb_dist=$(lsb_release -a 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'id' | cut -d ':' -f 2 | tr -d '[:space:]')\n\t\t\tdist_version=$(lsb_release -a 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'codename' | cut -d ':' -f 2 | tr -d '[:space:]')\n\n\t\t\t# Print info about upstream distro\n\t\t\tcat <<-EOF\n\t\t\tUpstream release is '$lsb_dist' version '$dist_version'.\n\t\t\tEOF\n\t\telse\n\t\t\tif [ -r /etc/debian_version ] && [ \"$lsb_dist\" != \"ubuntu\" ] && [ \"$lsb_dist\" != \"raspbian\" ]; then\n\t\t\t\tif [ \"$lsb_dist\" = \"osmc\" ]; then\n\t\t\t\t\t# OSMC runs Raspbian\n\t\t\t\t\tlsb_dist=raspbian\n\t\t\t\telse\n\t\t\t\t\t# We're Debian and don't even know it!\n\t\t\t\t\tlsb_dist=debian\n\t\t\t\tfi\n\t\t\t\tdist_version=\"$(sed 's/\\/.*//' /etc/debian_version | sed 's/\\..*//')\"\n\t\t\t\tcase \"$dist_version\" in\n\t\t\t\t\t10)\n\t\t\t\t\t\tdist_version=\"buster\"\n\t\t\t\t\t;;\n\t\t\t\t\t9)\n\t\t\t\t\t\tdist_version=\"stretch\"\n\t\t\t\t\t;;\n\t\t\t\t\t8|'Kali Linux 2')\n\t\t\t\t\t\tdist_version=\"jessie\"\n\t\t\t\t\t;;\n\t\t\t\t\t7)\n\t\t\t\t\t\tdist_version=\"wheezy\"\n\t\t\t\t\t;;\n\t\t\t\tesac\n\t\t\telif [ -r /etc/redhat-release ] && [ \"$lsb_dist\" = \"\" ]; then\n\t\t\t\tlsb_dist=redhat\n\t\t\tfi\n\t\tfi\n\tfi\n}\n\ncommand_exists() {\n\tcommand -v \"$@\"\n}\n\ninit() {\n\tsh_c='sh -c'\n\tif [ \"$user\" != 'root' ]; then\n\t\tif command_exists sudo; then\n\t\t\tsh_c='sudo -E sh -c'\n\t\telif command_exists su; then\n\t\t\tsh_c='su -c'\n\t\telse\n\t\t\tcat >&2 <<-'EOF'\n\t\t\tError: this installer needs the ability to run commands as root.\n\t\t\tWe are unable to find either \"sudo\" or \"su\" available to make this happen.\n\t\t\tEOF\n\t\t\texit 1\n\t\tfi\n\tfi\n\n\tget_distribution\n\n\tcase \"$lsb_dist\" in\n\n\t\tubuntu)\n\t\t\tif command_exists lsb_release; then\n\t\t\t\tdist_version=\"$(lsb_release --codename | cut -f2)\"\n\t\t\tfi\n\t\t\tif [ -z \"$dist_version\" ] && [ -r /etc/lsb-release ]; then\n\t\t\t\tdist_version=\"$(. /etc/lsb-release && echo \"$DISTRIB_CODENAME\")\"\n\t\t\tfi\n\t\t;;\n\n\t\tdebian|raspbian)\n\t\t\tdist_version=\"$(sed 's/\\/.*//' /etc/debian_version | sed 's/\\..*//')\"\n\t\t\tcase \"$dist_version\" in\n\t\t\t\t10)\n\t\t\t\t\tdist_version=\"buster\"\n\t\t\t\t\t# Avoid https://stackoverflow.com/questions/68802802/repository-http-security-debian-org-debian-security-buster-updates-inrelease\n\t\t\t\t\t$sh_c \"apt-get update --allow-releaseinfo-change\"\n\t\t\t\t;;\n\t\t\t\t9)\n\t\t\t\t\tdist_version=\"stretch\"\n\t\t\t\t;;\n\t\t\t\t8)\n\t\t\t\t\tdist_version=\"jessie\"\n\t\t\t\t;;\n\t\t\t\t7)\n\t\t\t\t\tdist_version=\"wheezy\"\n\t\t\t\t;;\n\t\t\tesac\n\t\t;;\n\n\t\tcentos)\n\t\t\tif [ -z \"$dist_version\" ] && [ -r /etc/os-release ]; then\n\t\t\t\tdist_version=\"$(. /etc/os-release && echo \"$VERSION_ID\")\"\n\t\t\tfi\n\t\t;;\n\n\t\trhel|ol|sles)\n\t\t\tee_notice \"$lsb_dist\"\n\t\t\texit 1\n\t\t\t;;\n\n\t\t*)\n\t\t\tif command_exists lsb_release; then\n\t\t\t\tdist_version=\"$(lsb_release --release | cut -f2)\"\n\t\t\tfi\n\t\t\tif [ -z \"$dist_version\" ] && [ -r /etc/os-release ]; then\n\t\t\t\tdist_version=\"$(. /etc/os-release && echo \"$VERSION_ID\")\"\n\t\t\tfi\n\t\t;;\n\n\tesac\n\n\t# Check if this is a forked Linux distro\n\tcheck_forked\n\n\t# Check if we actually support this configuration\n\tif [ \"$lsb_dist\" = \"redhat\" ]; then\n\t\tcat >&2 <<-'EOF'\n\n\t\tSince Docker Community Edition is not supported for RedHat you have to procceed with installation manually.\n\t\tPlease visit the following URL for more detailed installation instructions:\n\n\t\thttps://iofog.org/install/RHEL\n\n\t\tEOF\n\t\texit 1\n\tfi\n\n}"), + } + file5 := &embedded.EmbeddedFile{ + Filename: "agent/install_deps.sh", + FileModTime: time.Unix(1674701401, 0), + + Content: string("#!/bin/sh\nset -x\nset -e\n\n/etc/iofog/agent/install_java.sh\n/etc/iofog/agent/install_docker.sh\n"), + } + file6 := &embedded.EmbeddedFile{ + Filename: "agent/install_docker.sh", + FileModTime: time.Unix(1677788259, 0), + + Content: string("#!/bin/sh\nset -x\nset -e\n\nstart_docker() {\n\tset +e\n\t# check if docker is running\n\tif ! $sh_c \"docker ps\" >/dev/null 2>&1; then\n\t\t# Try init.d\n\t\t$sh_c \"/etc/init.d/docker start\"\n\t\tlocal err_code=$?\n\t\t# Try systemd\n\t\tif [ $err_code -ne 0 ]; then\n\t\t\t$sh_c \"service docker start\"\n\t\t\terr_code=$?\n\t\tfi\n\t\t# Try snapd\n\t\tif [ $err_code -ne 0 ]; then\n\t\t\t$sh_c \"snap docker start\"\n\t\t\terr_code=$?\n\t\tfi\n\t\tif [ $err_code -ne 0 ]; then\n\t\t\techo \"Could not start Docker daemon\"\n\t\t\texit 1\n\t\tfi\n\tfi\n\tset -e\n}\n\ndo_configure_overlay() {\n\tlocal driver=\"$DOCKER_STORAGE_DRIVER\"\n\tif [ -z \"$driver\" ]; then\n\t\tdriver=\"overlay\"\n\tfi\n\techo \"# Configuring /etc/systemd/system/docker.service.d/overlay.conf...\"\n\tif [ \"$lsb_dist\" = \"raspbian\" ] || [ \"$(uname -m)\" = \"armv7l\" ] || [ \"$(uname -m)\" = \"aarch64\" ] || [ \"$(uname -m)\" = \"armv8\" ]; then\n\t\tif [ ! -d \"/etc/systemd/system/docker.service.d\" ]; then\n\t\t\t$sh_c \"mkdir -p /etc/systemd/system/docker.service.d\"\n\t\tfi\n\t\tif [ ! -f \"/etc/systemd/system/docker.service.d/overlay.conf\" ] || ! grep -Fxq \"ExecStart=/usr/bin/dockerd --storage-driver $driver -H unix:// -H tcp://127.0.0.1:2375\" \"/etc/systemd/system/docker.service.d/overlay.conf\"; then\n\t\t\t$sh_c 'echo \"[Service]\" > /etc/systemd/system/docker.service.d/overlay.conf'\n\t\t\t$sh_c 'echo \"ExecStart=\" >> /etc/systemd/system/docker.service.d/overlay.conf'\n\t\t\t$sh_c \"echo \\\"ExecStart=/usr/bin/dockerd --storage-driver $driver -H unix:// -H tcp://127.0.0.1:2375\\\" >> /etc/systemd/system/docker.service.d/overlay.conf\"\n\t\tfi\n\t\t$sh_c \"systemctl daemon-reload\"\n\t\t$sh_c \"service docker restart\"\n\tfi\n}\n\ndo_install_docker() {\n\t# Check that Docker 18.09.2 or greater is installed\n\tif command_exists docker; then\n\t\tdocker_version=$(docker -v | sed 's/.*version \\(.*\\),.*/\\1/' | tr -d '.')\n\t\tif [ \"$docker_version\" -ge 18090 ]; then\n\t\t\techo \"# Docker $docker_version already installed\"\n\t\t\tstart_docker\n\t\t\tdo_configure_overlay\n\t\t\treturn\n\t\tfi\n\tfi\n\techo \"# Installing Docker...\"\n\tcase \"$dist_version\" in\n\t\t\"stretch\")\n\t\t\t$sh_c \"apt install -y apt-transport-https ca-certificates curl gnupg2 software-properties-common\"\n\t\t\tcurl -fsSL https://download.docker.com/linux/debian/gpg | $sh_c \"apt-key add -\"\n\t\t\t$sh_c \"sudo add-apt-repository \\\"deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable\\\"\"\n\t\t\t$sh_c \"apt-get update -y\"\n\t\t\t$sh_c \"sudo apt install -y docker-ce\"\n\t\t;;\n 7|8)\n $sh_c \"sudo yum install -y yum-utils || echo 'yum-utils already installed'\"\n $sh_c \"sudo yum-config-manager \\\n --add-repo \\\n https://download.docker.com/linux/centos/docker-ce.repo\"\n $sh_c \"sudo yum install docker-ce docker-ce-cli containerd.io -y\"\n ;;\n\t\t*)\n\t\t\tcurl -fsSL https://get.docker.com/ | sh\n\t\t;;\n\tesac\n\t\n\tif ! command_exists docker; then\n\t\techo \"Failed to install Docker\"\n\t\texit 1\n\tfi\n\tstart_docker\n\tdo_configure_overlay\n}\n\n. /etc/iofog/agent/init.sh\ninit\ndo_install_docker"), + } + file7 := &embedded.EmbeddedFile{ + Filename: "agent/install_iofog.sh", + FileModTime: time.Unix(1674701401, 0), + + Content: string("#!/bin/sh\nset -x\nset -e\n\ndo_check_install() {\n\tif command_exists iofog-agent; then\n\t\tlocal VERSION=$(sudo iofog-agent version | head -n1 | sed \"s/ioFog//g\" | tr -d ' ' | tr -d \"\\n\")\n\t\tif [ \"$VERSION\" = \"$agent_version\" ]; then\n\t\t\techo \"Agent $VERSION already installed.\"\n\t\t\texit 0\n\t\tfi\n\tfi\n}\n\ndo_stop_iofog() {\n\tif command_exists iofog-agent; then\n\t\tsudo service iofog-agent stop\n\tfi\n}\n\ndo_check_iofog_on_arm() {\n if [ \"$lsb_dist\" = \"raspbian\" ] || [ \"$(uname -m)\" = \"armv7l\" ] || [ \"$(uname -m)\" = \"aarch64\" ] || [ \"$(uname -m)\" = \"armv8\" ]; then\n echo \"# We re on ARM ($(uname -m)) : Updating config.xml to use correct docker_url\"\n $sh_c 'sed -i -e \"s|.*|tcp://127.0.0.1:2375/|g\" /etc/iofog-agent/config.xml'\n\n echo \"# Restarting iofog-agent service\"\n $sh_c \"service iofog-agent stop\"\n sleep 3\n $sh_c \"service iofog-agent start\"\n fi\n}\n\ndo_install_iofog() {\n\tAGENT_CONFIG_FOLDER=/etc/iofog-agent\n\tSAVED_AGENT_CONFIG_FOLDER=/tmp/agent-config-save\n\tPACKAGE_CLOUD_SCRIPT=package_cloud.sh\n\techo \"# Installing ioFog agent...\"\n\n\t# Save iofog-agent config\n\tif [ -d ${AGENT_CONFIG_FOLDER} ]; then\n\t\tsudo rm -rf ${SAVED_AGENT_CONFIG_FOLDER}\n\t\tsudo mkdir -p ${SAVED_AGENT_CONFIG_FOLDER}\n\t\tsudo cp -r ${AGENT_CONFIG_FOLDER}/* ${SAVED_AGENT_CONFIG_FOLDER}/\n\tfi\n\n\tprefix=$([ -z \"$token\" ] && echo \"\" || echo \"$token:@\")\n\techo $lsb_dist\n\tif [ \"$lsb_dist\" = \"fedora\" ] || [ \"$lsb_dist\" = \"centos\" ]; then\n#\t\t$sh_c \"yum install yum-utils -y\"\n\t\trepo_any=\"$(echo $repo | tr \"/\" \"_\")\"\n\t\techo \"$repo_any\"\n\t\trepo_file=\"yum.repos.d/$repo_any.repo\"\necho \"[$repo_any]\nname=$repo_any\nbaseurl=https://packagecloud.io/$repo/rpm_any/rpm_any/\\$basearch\nrepo_gpgcheck=1\ngpgcheck=0\nenabled=1\ngpgkey=https://packagecloud.io/$repo/gpgkey\nsslverify=1\nsslcacert=/etc/pki/tls/certs/ca-bundle.crt\nmetadata_expire=300\" > \"/etc/$repo_file\"\n\t\t$sh_c \"yum -q makecache -y --disablerepo='*' --enablerepo=$repo_any\"\n\t\t$sh_c \"yum --disablerepo='*' --enablerepo=$repo_any install -y iofog-agent-$agent_version-1.noarch\"\n\telse\n repo_any=$(echo $repo | tr \"/\" \"_\")\n echo $repo_any\n gpg_key_url=\"https://packagecloud.io/$repo/gpgkey\"\n repo_list_file=\"sources.list.d/${repo_any}_any.list\"\n apt_trusted_keyring_path=\"/etc/apt/trusted.gpg.d/$repo_any.gpg\"\n apt install -qy debian-archive-keyring\n apt install -qy apt-transport-https\n # Import the gpg key\n echo \"${gpg_key_url}\"\n curl -fsSL \"${gpg_key_url}\" | gpg --dearmor > \"${apt_trusted_keyring_path}\"\n $sh_c \"apt update -qy\"\n # Repo definition\n echo \"deb https://packagecloud.io/$repo/any/ any main\n deb-src https://packagecloud.io/$repo/any/ any main\" > \"/etc/apt/$repo_list_file\"\n $sh_c \"apt-get update -qy \\\n -o Dir::Etc::sourcelist=\"$repo_list_file\" \\\n -o Dir::Etc::sourceparts=\"-\" \\\n -o APT::Get::List-Cleanup='0'\"\n $sh_c \"apt install --allow-downgrades iofog-agent=$agent_version -qy\"\n\tfi\n\tdo_check_iofog_on_arm\n\n\t# Restore iofog-agent config\n\tif [ -d ${SAVED_AGENT_CONFIG_FOLDER} ]; then\n\t\tsudo mv ${SAVED_AGENT_CONFIG_FOLDER}/* ${AGENT_CONFIG_FOLDER}/\n\t\tsudo rmdir ${SAVED_AGENT_CONFIG_FOLDER}\n\tfi\n\tsudo chmod 775 ${AGENT_CONFIG_FOLDER}\n}\n\ndo_start_iofog(){\n\t# shellcheck disable=SC2261\n\tsudo service iofog-agent start > /dev/null 2&>1 &\n\tlocal STATUS=\"\"\n\tlocal ITER=0\n\twhile [ \"$STATUS\" != \"RUNNING\" ] ; do\n ITER=$((ITER+1))\n if [ \"$ITER\" -gt 60 ]; then\n echo 'Timed out waiting for Agent to be RUNNING'\n exit 1;\n fi\n sleep 1\n STATUS=$(sudo iofog-agent status | cut -f2 -d: | head -n 1 | tr -d '[:space:]')\n echo \"${STATUS}\"\n\tdone\n\tsudo iofog-agent \"config -cf 10 -sf 10\"\n}\n\nagent_version=\"$1\"\nrepo=$([ -z \"$2\" ] && echo \"iofog/iofog-agent\" || echo \"$2\")\ntoken=\"$3\"\necho \"Using variables\"\necho \"version: $agent_version\"\necho \"repo: $repo\"\necho \"token: $token\"\n\n. /etc/iofog/agent/init.sh\ninit\ndo_check_install\ndo_stop_iofog\ndo_install_iofog\ndo_start_iofog"), + } + file8 := &embedded.EmbeddedFile{ + Filename: "agent/install_java.sh", + FileModTime: time.Unix(1674701401, 0), + + Content: string("#!/bin/sh\nset -x\nset -e\n\njava_major_version=0\njava_minor_version=0\ndo_check_install() {\n\tif command_exists java; then\n java_major_version=\"$(java --version | head -n1 | awk '{print $2}' | cut -d. -f1)\"\n java_minor_version=\"$(java --version | head -n1 | awk '{print $2}' | cut -d. -f2)\"\n\tfi\n\tif [ \"$java_major_version\" -ge \"11\" ] && [ \"$java_minor_version\" -ge \"0\" ]; then\n\t\techo \"Java $java_major_version.$java_minor_version already installed.\"\n\t\texit 0\n\tfi\n}\n\ndo_install_java() {\n\techo \"# Installing java 11...\"\n\techo \"\"\n\tos_arch=$(getconf LONG_BIT)\n\tis_arm=\"\"\n\tif [ \"$lsb_dist\" = \"raspbian\" ] || [ \"$(uname -m)\" = \"armv7l\" ] || [ \"$(uname -m)\" = \"aarch64\" ] || [ \"$(uname -m)\" = \"armv8\" ]; then\n\t\tis_arm=\"-arm\"\n\tfi\n\tcase \"$lsb_dist\" in\n\t\tubuntu)\n\t\t\t$sh_c \"apt-get update -y\"\n\t\t\t$sh_c \"apt install -y openjdk-11-jdk\"\n\t\t;;\n\t\tdebian|mendel)\n\t\t\t$sh_c \"apt-get update\"\n\t\t\t$sh_c \"apt install -y openjdk-11-jdk\"\n\t\t;;\n\t\traspbian)\n\t\t if [ \"$os_arch\" = \"32\" ]; then\n\t\t $sh_c \"apt-get update\"\n\t\t $sh_c \"apt-get install openjdk-8-jdk -y\"\n\t\t else\n\t\t $sh_c \"apt-get update\"\n\t\t $sh_c \"apt install -y openjdk-11-jdk\"\n\t\t fi\n\t\t;;\n\t\tfedora|centos)\n\t\t\t$sh_c \"yum install -y java-11-openjdk\"\n\t\t;;\n\tesac\n}\n\ndo_install_deps() {\n\tlocal installer=\"\"\n\tcase \"$lsb_dist\" in\n\t\tubuntu|debian|raspbian)\n\t\t\tinstaller=\"apt\"\n\t\t;;\n\t\tfedora|centos)\n\t\t\tinstaller=\"yum\"\n\t\t;;\n\tesac\n\n\tlocal iter=0\n\twhile ! $sh_c \"$installer update\" && [ \"$iter\" -lt 6 ]; do\n\t\tsleep 5\n\t\titer=$((iter+1))\n\tdone\n}\n\n. /etc/iofog/agent/init.sh\ninit\ndo_check_install\ndo_install_deps\ndo_install_java"), + } + file9 := &embedded.EmbeddedFile{ + Filename: "agent/uninstall_iofog.sh", + FileModTime: time.Unix(1674701401, 0), + + Content: string("#!/bin/sh\nset -x\nset -e\n\nAGENT_CONFIG_FOLDER=/etc/iofog-agent/\nAGENT_LOG_FOLDER=/var/log/iofog-agent/\n\ndo_uninstall_iofog() {\n\techo \"# Removing ioFog agent...\"\n\n\tcase \"$lsb_dist\" in\n\t\tubuntu)\n\t\t\t$sh_c \"apt-get -y --purge autoremove iofog-agent\"\n\t\t\t;;\n\t\tfedora|centos)\n\t\t\t$sh_c \"yum remove -y iofog-agent\"\n\t\t\t;;\n\t\tdebian|raspbian)\n\t\t\t$sh_c \"apt-get -y --purge autoremove iofog-agent\"\n\t\t\t;;\n\tesac\n\n\t# Remove config files\n\t$sh_c \"rm -rf ${AGENT_CONFIG_FOLDER}\"\n\n\t# Remove log files\n\t$sh_c \"rm -rf ${AGENT_LOG_FOLDER}\"\n}\n\n. /etc/iofog/agent/init.sh\ninit\n\ndo_uninstall_iofog"), + } + fileb := &embedded.EmbeddedFile{ + Filename: "controller/check_prereqs.sh", + FileModTime: time.Unix(1674701401, 0), + + Content: string("#!/bin/sh\nset -x\n\n# Check can sudo without password\nif ! $(sudo ls /tmp/ > /dev/null); then\n\tMSG=\"Unable to successfully use sudo with user $USER on this host.\\nUser $USER must be in sudoers group and using sudo without password must be enabled.\\nPlease see iofog.org documentation for more details.\"\n\techo $MSG\n\texit 1\nfi\n"), + } + filec := &embedded.EmbeddedFile{ + Filename: "controller/install_iofog.sh", + FileModTime: time.Unix(1679424914, 0), + + Content: string("#!/bin/sh\nset -x\nset -e\n\nINSTALL_DIR=\"/opt/iofog\"\nTMP_DIR=\"/tmp/iofog\"\nETC_DIR=\"/etc/iofog/controller\"\n\ncontroller_service() {\n USE_SYSTEMD=`grep -m1 -c systemd /proc/1/comm`\n USE_INITCTL=`which initctl | wc -l`\n USE_SERVICE=`which service | wc -l`\n\n if [ $USE_SYSTEMD -eq 1 ]; then\n cp \"$ETC_DIR/service/iofog-controller.systemd\" /etc/systemd/system/iofog-controller.service\n chmod 644 /etc/systemd/system/iofog-controller.service\n systemctl daemon-reload\n systemctl enable iofog-controller.service\n elif [ $USE_INITCTL -eq 1 ]; then\n cp \"$ETC_DIR/service/iofog-controller.initctl\" /etc/init/iofog-controller.conf\n initctl reload-configuration\n elif [ $USE_SERVICE -eq 1 ]; then\n cp \"$ETC_DIR/service/iofog-controller.update-rc\" /etc/init.d/iofog-controller\n chmod +x /etc/init.d/iofog-controller\n update-rc.d iofog-controller defaults\n else\n echo \"Unable to setup Controller startup script.\"\n fi\n}\n\ninstall_package() {\n\t\tif [ -z \"$(command -v apt)\" ]; then\n\t\t\techo \"Unsupported distro\"\n\t\t\texit 1\n\t\tfi\n\t\tapt update -qq\n\t\tapt install -y $1\n}\n\ninstall_deps() {\n\tif [ -z \"$(command -v curl)\" ]; then\n install_package \"curl\"\n\tfi\n\n\tif [ -z \"$(command -v lsof)\" ]; then\n install_package \"lsof\"\n\tfi\n\n\tif [ -z \"$(command -v make)\" ]; then\n install_package \"build-essential\"\n\tfi\n\n\tif [ -z \"$(command -v python2)\" ]; then\n install_package \"python\"\n\tfi\n}\n\ndeploy_controller() {\n\t# Nuke any existing instances\n\tif [ ! -z \"$(lsof -ti tcp:51121)\" ]; then\n\t\tlsof -ti tcp:51121 | xargs kill\n\tfi\n\n#\t If token is provided, set up private repo\n\tif [ ! -z $token ]; then\n\t\tif [ ! -z $(npmrc | grep iofog) ]; then\n\t\t\tnpmrc -c iofog\n\t\t\tnpmrc iofog\n\t\tfi\n\t\tcurl -s https://\"$token\":@packagecloud.io/install/repositories/\"$repo\"/script.node.sh?package_id=7368735 | force_npm=1 bash\n\t\tmv ~/.npmrc ~/.npmrcs/npmrc\n\t\tln -s ~/.npmrcs/npmrc ~/.npmrc\n\telse\n\t\tnpmrc default\n\tfi\n\n\t# Save DB\n\tif [ -f \"$INSTALL_DIR/controller/lib/node_modules/@iofog/iofogcontroller/package.json\" ]; then\n\t\t# If iofog-controller is not running, it will fail to stop - ignore that failure.\n\t\tnode $INSTALL_DIR/controller/lib/node_modules/@iofog/iofogcontroller/scripts/scripts-api.js preuninstall > /dev/null 2>&1 || true\n\tfi\n\n\t# Install in temporary location\n\tmkdir -p \"$TMP_DIR/controller\"\n\tchmod 0777 \"$TMP_DIR/controller\"\n\tif [ -z $version ]; then\n\t\tnpm install -g -f @iofog/iofogcontroller --unsafe-perm --prefix \"$TMP_DIR/controller\"\n\telse\n\t\tnpm install -g -f \"@iofog/iofogcontroller@$version\" --unsafe-perm --prefix \"$TMP_DIR/controller\"\n\tfi\n\t# Move files into $INSTALL_DIR/controller\n\tmkdir -p \"$INSTALL_DIR/\"\n\trm -rf \"$INSTALL_DIR/controller\" # Clean possible previous install\n\tmv \"$TMP_DIR/controller/\" \"$INSTALL_DIR/\"\n\n\t# Restore DB\n\tif [ -f \"$INSTALL_DIR/controller/lib/node_modules/@iofog/iofogcontroller/package.json\" ]; then\n\t\tnode $INSTALL_DIR/controller/lib/node_modules/@iofog/iofogcontroller/scripts/scripts-api.js postinstall > /dev/null 2>&1 || true\n\tfi\n\n\t# Symbolic links\n\tif [ ! -f \"/usr/local/bin/iofog-controller\" ]; then\n\t\tln -fFs \"$INSTALL_DIR/controller/bin/iofog-controller\" /usr/local/bin/iofog-controller\n\tfi\n\n\t# Set controller permissions\n\tchmod 744 -R \"$INSTALL_DIR/controller\"\n\n\t# Startup script\n\tcontroller_service\n\n\t# Run controller\n\t. /opt/iofog/config/controller/env.sh\n\tiofog-controller start\n}\n\n# main\nversion=\"$1\"\nrepo=$([ -z \"$2\" ] && echo \"iofog/iofog-controller-snapshots\" || echo \"$2\")\ntoken=\"$3\"\n\ninstall_deps\ndeploy_controller"), + } + filed := &embedded.EmbeddedFile{ + Filename: "controller/install_node.sh", + FileModTime: time.Unix(1679425068, 0), + + Content: string("#!/bin/sh\nset -x\nset -e\n\nload_existing_nvm() {\n\tset +e\n\tif [ -z \"$(command -v nvm)\" ]; then\n\t\texport NVM_DIR=\"${HOME}/.nvm\"\n\t\tmkdir -p $NVM_DIR\n\t\tif [ -f \"$NVM_DIR/nvm.sh\" ]; then\n\t\t\t[ -s \"$NVM_DIR/nvm.sh\" ] && \\. \"$NVM_DIR/nvm.sh\" # This loads nvm\n\t\tfi\n\tfi\n\tset -e\n}\n\ninstall_node() {\n\tload_existing_nvm\n\tif [ -z \"$(command -v nvm)\" ]; then\n\t\tcurl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash\n\t\texport NVM_DIR=\"${HOME}/.nvm\"\n\t\t[ -s \"$NVM_DIR/nvm.sh\" ] && \\. \"$NVM_DIR/nvm.sh\"\n\tfi\n\tnvm install v18.15.0\n\tnvm use v18.15.0\n\tln -Ffs $(which node) /usr/local/bin/node\n\tln -Ffs $(which npm) /usr/local/bin/npm\n\n\t# npmrc\n\tif [ -z \"$(command -v npmrc)\" ]; then\n\t\tnpm i npmrc -g\n\tfi\n\tln -Ffs $(which npmrc) /usr/local/bin/npmrc\n}\n\ninstall_node"), + } + filef := &embedded.EmbeddedFile{ + Filename: "controller/service/iofog-controller.initctl", + FileModTime: time.Unix(1674701401, 0), + + Content: string("description \"ioFog Controller\"\n\nstart on (runlevel [2345])\nstop on (runlevel [!2345])\n\nrespawn\n\nscript\n . /opt/iofog/config/controller/env.sh\n exec /usr/local/bin/iofog-controller start\nend script"), + } + fileg := &embedded.EmbeddedFile{ + Filename: "controller/service/iofog-controller.systemd", + FileModTime: time.Unix(1674701401, 0), + + Content: string("[Unit]\nDescription=ioFog Controller\n\n[Service]\nType=forking\nExecStart=/usr/local/bin/iofog-controller start\nExecStop=/usr/local/bin/iofog-controller stop\nEnvironmentFile=/opt/iofog/config/controller/env.env\n\n[Install]\nWantedBy=multi-user.target\n"), + } + fileh := &embedded.EmbeddedFile{ + Filename: "controller/service/iofog-controller.update-rc", + FileModTime: time.Unix(1674701401, 0), + + Content: string("#!/bin/sh\n\ncase \"$1\" in\n start)\n . /opt/iofog/controller/env.env\n /usr/local/bin/iofog-controller start\n ;;\n stop)\n /usr/local/bin/iofog-controller stop\n ;;\n restart)\n /usr/local/bin/iofog-controller stop\n . /opt/iofog/config/controller/env.sh\n /usr/local/bin/iofog-controller start\n ;;\n *)\n echo \"Usage: $0 {start|stop|restart}\"\nesac\n"), + } + filei := &embedded.EmbeddedFile{ + Filename: "controller/set_env.sh", + FileModTime: time.Unix(1674701401, 0), + + Content: string("#!/bin/sh\nset -x\nset -e\n\nCONF_FOLDER=/opt/iofog/config/controller\nSOURCE_FILE_NAME=env.sh # Used to source env variables\nENV_FILE_NAME=env.env # Used as an env file in systemd\n\nSOURCE_FILE=\"$CONF_FOLDER/$SOURCE_FILE_NAME\"\nENV_FILE=\"$CONF_FOLDER/$ENV_FILE_NAME\"\n\n# Create folder\nmkdir -p \"$CONF_FOLDER\"\n\n# Source file\necho \"#!/bin/sh\" > \"$SOURCE_FILE\"\n\n# Env file (for systemd)\nrm -f \"$ENV_FILE\"\ntouch \"$ENV_FILE\"\n\nfor var in \"$@\"\ndo\n echo \"export $var\" >> \"$SOURCE_FILE\"\n echo \"$var\" >> \"$ENV_FILE\"\ndone"), + } + filej := &embedded.EmbeddedFile{ + Filename: "controller/uninstall_iofog.sh", + FileModTime: time.Unix(1674701401, 0), + + Content: string("#!/bin/sh\nset -x\nset -e\n\nCONTROLLER_DIR=\"/opt/iofog/controller/\"\nCONTROLLER_LOG_DIR=\"/var/log/iofog/\"\n\ndo_uninstall_controller() {\n # Remove folders\n sudo rm -rf $CONTROLLER_DIR\n sudo rm -rf $CONTROLLER_LOG_DIR\n\n # Remove symbolic links\n rm -f /usr/local/bin/iofog-controller\n\n # Remove service files\n USE_SYSTEMD=`grep -m1 -c systemd /proc/1/comm`\n USE_INITCTL=`which initctl | wc -l`\n USE_SERVICE=`which service | wc -l`\n\n if [ $USE_SYSTEMD -eq 1 ]; then\n systemctl stop iofog-controller.service\n rm -f /etc/systemd/system/iofog-controller.service\n elif [ $USE_INITCTL -eq 1 ]; then\n rm -f /etc/init/iofog-controller.conf\n elif [ $USE_SERVICE -eq 1 ]; then\n rm -f /etc/init.d/iofog-controller\n else\n echo \"Unable to setup Controller startup script.\"\n fi\n}\n\ndo_uninstall_controller"), + } + + // define dirs + dir1 := &embedded.EmbeddedDir{ + Filename: "", + DirModTime: time.Unix(1674701401, 0), + ChildFiles: []*embedded.EmbeddedFile{}, + } + dir2 := &embedded.EmbeddedDir{ + Filename: "agent", + DirModTime: time.Unix(1677788259, 0), + ChildFiles: []*embedded.EmbeddedFile{ + file3, // "agent/check_prereqs.sh" + file4, // "agent/init.sh" + file5, // "agent/install_deps.sh" + file6, // "agent/install_docker.sh" + file7, // "agent/install_iofog.sh" + file8, // "agent/install_java.sh" + file9, // "agent/uninstall_iofog.sh" + + }, + } + dira := &embedded.EmbeddedDir{ + Filename: "controller", + DirModTime: time.Unix(1679425068, 0), + ChildFiles: []*embedded.EmbeddedFile{ + fileb, // "controller/check_prereqs.sh" + filec, // "controller/install_iofog.sh" + filed, // "controller/install_node.sh" + filei, // "controller/set_env.sh" + filej, // "controller/uninstall_iofog.sh" + + }, + } + dire := &embedded.EmbeddedDir{ + Filename: "controller/service", + DirModTime: time.Unix(1679424931, 0), + ChildFiles: []*embedded.EmbeddedFile{ + filef, // "controller/service/iofog-controller.initctl" + fileg, // "controller/service/iofog-controller.systemd" + fileh, // "controller/service/iofog-controller.update-rc" + + }, + } + + // link ChildDirs + dir1.ChildDirs = []*embedded.EmbeddedDir{ + dir2, // "agent" + dira, // "controller" + + } + dir2.ChildDirs = []*embedded.EmbeddedDir{} + dira.ChildDirs = []*embedded.EmbeddedDir{ + dire, // "controller/service" + + } + dire.ChildDirs = []*embedded.EmbeddedDir{} + + // register embeddedBox + embedded.RegisterEmbeddedBox(`../../assets`, &embedded.EmbeddedBox{ + Name: `../../assets`, + Time: time.Unix(1674701401, 0), + Dirs: map[string]*embedded.EmbeddedDir{ + "": dir1, + "agent": dir2, + "controller": dira, + "controller/service": dire, + }, + Files: map[string]*embedded.EmbeddedFile{ + "agent/check_prereqs.sh": file3, + "agent/init.sh": file4, + "agent/install_deps.sh": file5, + "agent/install_docker.sh": file6, + "agent/install_iofog.sh": file7, + "agent/install_java.sh": file8, + "agent/uninstall_iofog.sh": file9, + "controller/check_prereqs.sh": fileb, + "controller/install_iofog.sh": filec, + "controller/install_node.sh": filed, + "controller/service/iofog-controller.initctl": filef, + "controller/service/iofog-controller.systemd": fileg, + "controller/service/iofog-controller.update-rc": fileh, + "controller/set_env.sh": filei, + "controller/uninstall_iofog.sh": filej, + }, + }) +} diff --git a/test/conf/.gitignore b/test/conf/.gitignore index 5e7d2734c..17d9918f2 100644 --- a/test/conf/.gitignore +++ b/test/conf/.gitignore @@ -2,3 +2,4 @@ * # Except this file !.gitignore +env.sh